button.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import { canIUseFormFieldButton } from '../common/version';
  11. const { prefix } = config;
  12. const name = `${prefix}-button`;
  13. let Button = class Button extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [`${prefix}-class`, `${prefix}-class-icon`, `${prefix}-class-loading`];
  17. this.behaviors = canIUseFormFieldButton() ? ['wx://form-field-button'] : [];
  18. this.properties = props;
  19. this.data = {
  20. prefix,
  21. className: '',
  22. classPrefix: name,
  23. };
  24. this.observers = {
  25. 'theme, size, plain, block, shape, disabled, loading'() {
  26. this.setClass();
  27. },
  28. };
  29. this.lifetimes = {
  30. attached() {
  31. this.setClass();
  32. },
  33. };
  34. this.methods = {
  35. setClass() {
  36. const classList = [
  37. name,
  38. `${prefix}-class`,
  39. `${name}--${this.data.theme}`,
  40. `${name}--size-${this.data.size.slice(0, 1)}`,
  41. ];
  42. classList.push(`${name}--${this.data.shape}`);
  43. if (this.data.block) {
  44. classList.push(`${prefix}-is-block`);
  45. }
  46. if (this.data.disabled) {
  47. classList.push(`${prefix}-is-disabled`);
  48. }
  49. classList.push(`${name}--${this.data.variant}`);
  50. if (this.data.ghost) {
  51. classList.push(`${name}--ghost`);
  52. }
  53. this.setData({
  54. className: classList.join(' '),
  55. });
  56. },
  57. getuserinfo(e) {
  58. this.triggerEvent('getuserinfo', e.detail);
  59. },
  60. contact(e) {
  61. this.triggerEvent('contact', e.detail);
  62. },
  63. getphonenumber(e) {
  64. this.triggerEvent('getphonenumber', e.detail);
  65. },
  66. error(e) {
  67. this.triggerEvent('error', e.detail);
  68. },
  69. opensetting(e) {
  70. this.triggerEvent('opensetting', e.detail);
  71. },
  72. launchapp(e) {
  73. this.triggerEvent('launchapp', e.detail);
  74. },
  75. chooseavatar(e) {
  76. this.triggerEvent('chooseavatar', e.detail);
  77. },
  78. handleTap(e) {
  79. if (this.data.disabled)
  80. return;
  81. this.triggerEvent('tap', e);
  82. },
  83. };
  84. }
  85. };
  86. Button = __decorate([
  87. wxComponent()
  88. ], Button);
  89. export default Button;