button.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 { setIcon } 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'() {
  30. this.setClass();
  31. },
  32. icon(icon) {
  33. const obj = setIcon('icon', icon, '');
  34. this.setData(Object.assign({}, obj));
  35. },
  36. };
  37. this.lifetimes = {
  38. attached() {
  39. this.setClass();
  40. },
  41. };
  42. this.methods = {
  43. setClass() {
  44. const classList = [
  45. name,
  46. `${prefix}-class`,
  47. `${name}--${this.data.variant || 'base'}`,
  48. `${name}--${this.data.theme || 'default'}`,
  49. `${name}--${this.data.shape || 'rectangle'}`,
  50. `${name}--size-${this.data.size || 'medium'}`,
  51. ];
  52. if (this.data.block) {
  53. classList.push(`${name}--block`);
  54. }
  55. if (this.data.disabled) {
  56. classList.push(`${name}--disabled`);
  57. }
  58. if (this.data.ghost) {
  59. classList.push(`${name}--ghost`);
  60. }
  61. this.setData({
  62. className: classList.join(' '),
  63. });
  64. },
  65. getuserinfo(e) {
  66. this.triggerEvent('getuserinfo', e.detail);
  67. },
  68. contact(e) {
  69. this.triggerEvent('contact', e.detail);
  70. },
  71. getphonenumber(e) {
  72. this.triggerEvent('getphonenumber', e.detail);
  73. },
  74. error(e) {
  75. this.triggerEvent('error', e.detail);
  76. },
  77. opensetting(e) {
  78. this.triggerEvent('opensetting', e.detail);
  79. },
  80. launchapp(e) {
  81. this.triggerEvent('launchapp', e.detail);
  82. },
  83. chooseavatar(e) {
  84. this.triggerEvent('chooseavatar', e.detail);
  85. },
  86. handleTap(e) {
  87. if (this.data.disabled || this.data.loading)
  88. return;
  89. this.triggerEvent('tap', e);
  90. },
  91. };
  92. }
  93. };
  94. Button = __decorate([
  95. wxComponent()
  96. ], Button);
  97. export default Button;