合伙人运营小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 { isObject, toCamel } from '../common/utils';
  11. import useCustomNavbar from '../mixins/using-custom-navbar';
  12. const { prefix } = config;
  13. const name = `${prefix}-dialog`;
  14. let Dialog = class Dialog extends SuperComponent {
  15. constructor() {
  16. super(...arguments);
  17. this.behaviors = [useCustomNavbar];
  18. this.options = {
  19. multipleSlots: true,
  20. };
  21. this.externalClasses = [
  22. `${prefix}-class`,
  23. `${prefix}-class-content`,
  24. `${prefix}-class-confirm`,
  25. `${prefix}-class-cancel`,
  26. `${prefix}-class-action`,
  27. ];
  28. this.properties = props;
  29. this.data = {
  30. prefix,
  31. classPrefix: name,
  32. buttonVariant: 'text',
  33. };
  34. this.observers = {
  35. 'confirmBtn, cancelBtn'(confirm, cancel) {
  36. const { prefix, classPrefix, buttonLayout } = this.data;
  37. const rect = { buttonVariant: 'text' };
  38. const useBaseVariant = [confirm, cancel].some((item) => isObject(item) && item.variant && item.variant !== 'text');
  39. const buttonMap = { confirm, cancel };
  40. const cls = [`${classPrefix}__button`];
  41. const externalCls = [];
  42. if (useBaseVariant) {
  43. rect.buttonVariant = 'base';
  44. cls.push(`${classPrefix}__button--${buttonLayout}`);
  45. }
  46. else {
  47. cls.push(`${classPrefix}__button--text`);
  48. externalCls.push(`${classPrefix}-button`);
  49. }
  50. Object.keys(buttonMap).forEach((key) => {
  51. const btn = buttonMap[key];
  52. const base = {
  53. block: true,
  54. class: [...cls, `${classPrefix}__button--${key}`],
  55. externalClass: [...externalCls, `${prefix}-class-${key}`],
  56. variant: rect.buttonVariant,
  57. };
  58. if (key === 'cancel' && rect.buttonVariant === 'base') {
  59. base.theme = 'light';
  60. }
  61. if (typeof btn === 'string') {
  62. rect[`_${key}`] = Object.assign(Object.assign({}, base), { content: btn });
  63. }
  64. else if (btn && typeof btn === 'object') {
  65. rect[`_${key}`] = Object.assign(Object.assign({}, base), btn);
  66. }
  67. else {
  68. rect[`_${key}`] = null;
  69. }
  70. });
  71. this.setData(Object.assign({}, rect));
  72. },
  73. };
  74. this.methods = {
  75. onTplButtonTap(e) {
  76. var _a, _b, _c;
  77. const evtType = e.type;
  78. const { type, extra } = e.target.dataset;
  79. const button = this.data[`_${type}`];
  80. const cbName = `bind${evtType}`;
  81. if (type === 'action') {
  82. this.onActionTap(extra);
  83. return;
  84. }
  85. if (typeof button[cbName] === 'function') {
  86. const closeFlag = button[cbName](e);
  87. if (closeFlag) {
  88. this.close();
  89. }
  90. }
  91. const hasOpenType = 'openType' in button;
  92. if (!hasOpenType && ['confirm', 'cancel'].includes(type)) {
  93. (_a = this[toCamel(`on-${type}`)]) === null || _a === void 0 ? void 0 : _a.call(this, type);
  94. }
  95. if (evtType !== 'tap') {
  96. const success = ((_c = (_b = e.detail) === null || _b === void 0 ? void 0 : _b.errMsg) === null || _c === void 0 ? void 0 : _c.indexOf('ok')) > -1;
  97. this.triggerEvent(success ? 'open-type-event' : 'open-type-error-event', e.detail);
  98. }
  99. },
  100. onConfirm() {
  101. this.triggerEvent('confirm');
  102. if (this._onConfirm) {
  103. this._onConfirm();
  104. this.close();
  105. }
  106. },
  107. onCancel() {
  108. this.triggerEvent('close', { trigger: 'cancel' });
  109. this.triggerEvent('cancel');
  110. if (this._onCancel) {
  111. this._onCancel();
  112. this.close();
  113. }
  114. },
  115. onClose() {
  116. this.triggerEvent('close', { trigger: 'close-btn' });
  117. this.close();
  118. },
  119. close() {
  120. this.setData({ visible: false });
  121. },
  122. overlayClick() {
  123. if (this.properties.closeOnOverlayClick) {
  124. this.triggerEvent('close', { trigger: 'overlay' });
  125. }
  126. this.triggerEvent('overlay-click');
  127. },
  128. onActionTap(index) {
  129. this.triggerEvent('action', { index });
  130. if (this._onAction) {
  131. this._onAction({ index });
  132. this.close();
  133. }
  134. },
  135. openValueCBHandle(e) {
  136. this.triggerEvent('open-type-event', e.detail);
  137. },
  138. openValueErrCBHandle(e) {
  139. this.triggerEvent('open-type-error-event', e.detail);
  140. },
  141. };
  142. }
  143. };
  144. Dialog = __decorate([
  145. wxComponent()
  146. ], Dialog);
  147. export default Dialog;