index.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import props from './props';
  13. import { getInstance } from '../common/utils';
  14. const defaultOptions = {
  15. actions: false,
  16. buttonLayout: props.buttonLayout.value,
  17. cancelBtn: props.cancelBtn.value,
  18. closeOnOverlayClick: props.closeOnOverlayClick.value,
  19. confirmBtn: props.confirmBtn.value,
  20. content: '',
  21. preventScrollThrough: props.preventScrollThrough.value,
  22. showOverlay: props.showOverlay.value,
  23. title: '',
  24. visible: props.visible.value,
  25. };
  26. export default {
  27. alert(options) {
  28. const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog' } = _a, otherOptions = __rest(_a, ["context", "selector"]);
  29. const instance = getInstance(context, selector);
  30. if (!instance)
  31. return Promise.reject();
  32. return new Promise((resolve) => {
  33. instance.setData(Object.assign(Object.assign({ cancelBtn: '' }, otherOptions), { visible: true }));
  34. instance._onComfirm = resolve;
  35. });
  36. },
  37. confirm(options) {
  38. const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog' } = _a, otherOptions = __rest(_a, ["context", "selector"]);
  39. const instance = getInstance(context, selector);
  40. if (!instance)
  41. return Promise.reject();
  42. return new Promise((resolve, reject) => {
  43. instance.setData(Object.assign(Object.assign({}, otherOptions), { visible: true }));
  44. instance._onComfirm = resolve;
  45. instance._onCancel = reject;
  46. });
  47. },
  48. close(options) {
  49. const { context, selector = '#t-dialog' } = Object.assign({}, options);
  50. const instance = getInstance(context, selector);
  51. if (instance) {
  52. instance.close();
  53. return Promise.resolve();
  54. }
  55. return Promise.reject();
  56. },
  57. action(options) {
  58. const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog', actions } = _a, otherOptions = __rest(_a, ["context", "selector", "actions"]);
  59. const instance = getInstance(context, selector);
  60. if (!instance)
  61. return Promise.reject();
  62. if (!actions || (typeof actions === 'object' && (actions.length === 0 || actions.length > 7))) {
  63. console.warn('action 数量建议控制在1至7个');
  64. }
  65. return new Promise((resolve) => {
  66. instance.setData(Object.assign(Object.assign({ actions, buttonLayout: 'vertical' }, otherOptions), { visible: true }));
  67. instance._onAction = resolve;
  68. });
  69. },
  70. };