button.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. import { calcIcon } from '../common/utils';
  12. const { prefix } = config;
  13. const name = `${prefix}-button`;
  14. let Button = class Button extends SuperComponent {
  15. constructor() {
  16. super(...arguments);
  17. this.externalClasses = [`${prefix}-class`, `${prefix}-class-icon`, `${prefix}-class-loading`];
  18. this.behaviors = canIUseFormFieldButton() ? ['wx://form-field-button'] : [];
  19. this.properties = props;
  20. this.options = {
  21. multipleSlots: true,
  22. };
  23. this.data = {
  24. prefix,
  25. className: '',
  26. classPrefix: name,
  27. };
  28. this.observers = {
  29. 'theme, size, plain, block, shape, disabled, loading, variant'() {
  30. this.setClass();
  31. },
  32. icon(icon) {
  33. this.setData({
  34. _icon: calcIcon(icon, ''),
  35. });
  36. },
  37. };
  38. this.lifetimes = {
  39. attached() {
  40. this.setClass();
  41. },
  42. };
  43. this.methods = {
  44. setClass() {
  45. const classList = [
  46. name,
  47. `${prefix}-class`,
  48. `${name}--${this.data.variant || 'base'}`,
  49. `${name}--${this.data.theme || 'default'}`,
  50. `${name}--${this.data.shape || 'rectangle'}`,
  51. `${name}--size-${this.data.size || 'medium'}`,
  52. ];
  53. if (this.data.block) {
  54. classList.push(`${name}--block`);
  55. }
  56. if (this.data.disabled) {
  57. classList.push(`${name}--disabled`);
  58. }
  59. if (this.data.ghost) {
  60. classList.push(`${name}--ghost`);
  61. }
  62. this.setData({
  63. className: classList.join(' '),
  64. });
  65. },
  66. getuserinfo(e) {
  67. this.triggerEvent('getuserinfo', e.detail);
  68. },
  69. contact(e) {
  70. this.triggerEvent('contact', e.detail);
  71. },
  72. getphonenumber(e) {
  73. this.triggerEvent('getphonenumber', e.detail);
  74. },
  75. error(e) {
  76. this.triggerEvent('error', e.detail);
  77. },
  78. opensetting(e) {
  79. this.triggerEvent('opensetting', e.detail);
  80. },
  81. launchapp(e) {
  82. this.triggerEvent('launchapp', e.detail);
  83. },
  84. chooseavatar(e) {
  85. this.triggerEvent('chooseavatar', e.detail);
  86. },
  87. agreeprivacyauthorization(e) {
  88. this.triggerEvent('agreeprivacyauthorization', e.detail);
  89. },
  90. handleTap(e) {
  91. if (this.data.disabled || this.data.loading)
  92. return;
  93. this.triggerEvent('tap', e);
  94. },
  95. };
  96. }
  97. };
  98. Button = __decorate([
  99. wxComponent()
  100. ], Button);
  101. export default Button;