button.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // 组件的对外属性
  19. this.properties = props;
  20. // 组件的内部数据
  21. this.data = {
  22. // 按钮样式列表
  23. prefix,
  24. className: '',
  25. classPrefix: name,
  26. };
  27. this.observers = {
  28. 'theme, size, plain, block, shape, disabled, loading'() {
  29. this.setClass();
  30. },
  31. };
  32. /* 组件生命周期 */
  33. this.lifetimes = {
  34. // 组件实例被创建
  35. // created() {},
  36. // 组件实例进入页面节点树
  37. attached() {
  38. this.setClass();
  39. },
  40. // 页面组件初始化完成
  41. // ready() { },
  42. // 组件实例被移动到节点树另一个位置
  43. // moved() {},
  44. // 组件实例被从页面节点树移除
  45. // detached() { },
  46. };
  47. /* Methods */
  48. this.methods = {
  49. setClass() {
  50. const classList = [
  51. name,
  52. `${prefix}-class`,
  53. `${name}--${this.data.theme || 'default'}`,
  54. `${name}--size-${this.data.size.slice(0, 1)}`,
  55. ];
  56. classList.push(`${name}--${this.data.shape}`);
  57. if (this.data.block) {
  58. classList.push(`${prefix}-is-block`);
  59. }
  60. if (this.data.disabled) {
  61. classList.push(`${prefix}-is-disabled`);
  62. }
  63. // if (this.data.loading) {
  64. // classList.push(`${prefix}-is-loading`);
  65. // }
  66. classList.push(`${name}--${this.data.variant}`);
  67. if (this.data.ghost) {
  68. classList.push(`${name}--ghost`);
  69. }
  70. this.setData({
  71. className: classList.join(' '),
  72. });
  73. },
  74. getuserinfo(e) {
  75. this.triggerEvent('getuserinfo', e.detail);
  76. },
  77. contact(e) {
  78. this.triggerEvent('contact', e.detail);
  79. },
  80. getphonenumber(e) {
  81. this.triggerEvent('getphonenumber', e.detail);
  82. },
  83. error(e) {
  84. this.triggerEvent('error', e.detail);
  85. },
  86. opensetting(e) {
  87. this.triggerEvent('opensetting', e.detail);
  88. },
  89. launchapp(e) {
  90. this.triggerEvent('launchapp', e.detail);
  91. },
  92. handleTap(e) {
  93. if (this.data.disabled)
  94. return;
  95. this.triggerEvent('tap', e.detail);
  96. },
  97. };
  98. }
  99. };
  100. Button = __decorate([
  101. wxComponent()
  102. ], Button);
  103. export default Button;
  104. //# sourceMappingURL=button.js.map