button.js 3.5 KB

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