dialog.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. const { prefix } = config;
  11. const name = `${prefix}-dialog`;
  12. let Dialog = class Dialog extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.options = {
  16. multipleSlots: true,
  17. addGlobalClass: true,
  18. };
  19. this.externalClasses = [
  20. `${prefix}-class`,
  21. `${prefix}-class-content`,
  22. `${prefix}-class-confirm`,
  23. `${prefix}-class-cancel`,
  24. `${prefix}-class-action`,
  25. ];
  26. this.properties = props;
  27. this.data = {
  28. prefix,
  29. classPrefix: name,
  30. };
  31. this.methods = {
  32. onTplButtonTap(e) {
  33. var _a;
  34. const evtType = e.type;
  35. const { type } = e.target.dataset;
  36. const button = this.data[`${type}Btn`];
  37. const cbName = `bind${evtType}`;
  38. if (typeof button[cbName] === 'function') {
  39. button[cbName](e);
  40. }
  41. if (evtType !== 'tap') {
  42. const success = ((_a = e.detail) === null || _a === void 0 ? void 0 : _a.errMsg.indexOf('ok')) > -1;
  43. this.triggerEvent(success ? 'open-type-event' : 'open-type-error-event', e.detail);
  44. }
  45. },
  46. onConfirm() {
  47. this.triggerEvent('confirm');
  48. if (this._onComfirm) {
  49. this._onComfirm();
  50. this.close();
  51. }
  52. },
  53. onCancel() {
  54. this.triggerEvent('close', { trigger: 'cancel' });
  55. this.triggerEvent('cancel');
  56. if (this._onCancel) {
  57. this._onCancel();
  58. this.close();
  59. }
  60. },
  61. close() {
  62. this.setData({ visible: false });
  63. },
  64. overlayClick() {
  65. if (this.properties.closeOnOverlayClick) {
  66. this.triggerEvent('close', { trigger: 'overlay' });
  67. }
  68. this.triggerEvent('overlayClick');
  69. },
  70. onActionTap(e) {
  71. const { index } = e.currentTarget.dataset;
  72. this.triggerEvent('action', { index });
  73. if (this._onAction) {
  74. this._onAction({ index });
  75. this.close();
  76. }
  77. },
  78. openValueCBHandle(e) {
  79. this.triggerEvent('open-type-event', e.detail);
  80. },
  81. openValueErrCBHandle(e) {
  82. this.triggerEvent('open-type-error-event', e.detail);
  83. },
  84. };
  85. }
  86. };
  87. Dialog = __decorate([
  88. wxComponent()
  89. ], Dialog);
  90. export default Dialog;