| | |
| | | var __rest = (this && this.__rest) || function (s, e) { |
| | | var t = {}; |
| | | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) |
| | | t[p] = s[p]; |
| | | if (s != null && typeof Object.getOwnPropertySymbols === "function") |
| | | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { |
| | | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) |
| | | t[p[i]] = s[p[i]]; |
| | | } |
| | | return t; |
| | | }; |
| | | import props from './props'; |
| | | import { getInstance } from '../common/utils'; |
| | | const defaultOptions = { |
| | | actions: [], |
| | | buttonLayout: props.buttonLayout.value, |
| | | cancelBtn: props.cancelBtn.value, |
| | | closeOnOverlayClick: props.closeOnOverlayClick.value, |
| | | confirmBtn: props.confirmBtn.value, |
| | | content: '', |
| | | preventScrollThrough: props.preventScrollThrough.value, |
| | | showOverlay: props.showOverlay.value, |
| | | title: '', |
| | | visible: props.visible.value, |
| | | }; |
| | | export default { |
| | | alert(options) { |
| | | const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog' } = _a, otherOptions = __rest(_a, ["context", "selector"]); |
| | | const instance = getInstance(context, selector); |
| | | if (!instance) |
| | | return Promise.reject(); |
| | | return new Promise((resolve) => { |
| | | instance.setData(Object.assign(Object.assign({ cancelBtn: '' }, otherOptions), { visible: true })); |
| | | instance._onConfirm = resolve; |
| | | }); |
| | | }, |
| | | confirm(options) { |
| | | const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog' } = _a, otherOptions = __rest(_a, ["context", "selector"]); |
| | | const instance = getInstance(context, selector); |
| | | if (!instance) |
| | | return Promise.reject(); |
| | | return new Promise((resolve, reject) => { |
| | | instance.setData(Object.assign(Object.assign({}, otherOptions), { visible: true })); |
| | | instance._onConfirm = resolve; |
| | | instance._onCancel = reject; |
| | | }); |
| | | }, |
| | | close(options) { |
| | | const { context, selector = '#t-dialog' } = Object.assign({}, options); |
| | | const instance = getInstance(context, selector); |
| | | if (instance) { |
| | | instance.close(); |
| | | return Promise.resolve(); |
| | | } |
| | | return Promise.reject(); |
| | | }, |
| | | action(options) { |
| | | const _a = Object.assign(Object.assign({}, defaultOptions), options), { context, selector = '#t-dialog', actions } = _a, otherOptions = __rest(_a, ["context", "selector", "actions"]); |
| | | const instance = getInstance(context, selector); |
| | | if (!instance) |
| | | return Promise.reject(); |
| | | const { buttonLayout = 'vertical' } = options; |
| | | const maxLengthSuggestion = buttonLayout === 'vertical' ? 7 : 3; |
| | | if (!actions || (typeof actions === 'object' && (actions.length === 0 || actions.length > maxLengthSuggestion))) { |
| | | console.warn(`action 数量建议控制在1至${maxLengthSuggestion}个`); |
| | | } |
| | | return new Promise((resolve) => { |
| | | instance.setData(Object.assign(Object.assign({ actions }, otherOptions), { buttonLayout, visible: true })); |
| | | instance._onAction = resolve; |
| | | }); |
| | | }, |
| | | }; |
| | | import{__rest}from"tslib";import props from"./props";import{getInstance}from"../common/utils";const defaultOptions={actions:[],buttonLayout:props.buttonLayout.value,cancelBtn:props.cancelBtn.value,closeOnOverlayClick:props.closeOnOverlayClick.value,confirmBtn:props.confirmBtn.value,content:"",preventScrollThrough:props.preventScrollThrough.value,showOverlay:props.showOverlay.value,title:"",visible:props.visible.value};export default{alert(t){const e=Object.assign({},t),{context:s,selector:o="#t-dialog"}=e,n=__rest(e,["context","selector"]),c=getInstance(s,o);return c?new Promise(t=>{const e=Object.assign(Object.assign(Object.assign({},defaultOptions),c.properties),n);c.setData(Object.assign(Object.assign({cancelBtn:""},e),{visible:!0})),c._onConfirm=t}):Promise.reject()},confirm(t){const e=Object.assign({},t),{context:s,selector:o="#t-dialog"}=e,n=__rest(e,["context","selector"]),c=getInstance(s,o);return c?new Promise((t,e)=>{const s=Object.assign(Object.assign(Object.assign({},defaultOptions),c.properties),n);c.setData(Object.assign(Object.assign({},s),{visible:!0})),c._onConfirm=t,c._onCancel=e}):Promise.reject()},close(t){const{context:e,selector:s="#t-dialog"}=Object.assign({},t),o=getInstance(e,s);return o?(o.close(),Promise.resolve()):Promise.reject()},action(t){const e=Object.assign({},t),{context:s,selector:o="#t-dialog"}=e,n=__rest(e,["context","selector"]),c=getInstance(s,o);if(!c)return Promise.reject();const{buttonLayout:r="vertical",actions:i=c.properties.actions}=t,a="vertical"===r?7:3;return(!i||"object"==typeof i&&(0===i.length||i.length>a))&&console.warn(`action 数量建议控制在1至${a}个`),new Promise(t=>{const e=Object.assign(Object.assign(Object.assign({},defaultOptions),c.properties),n);c.setData(Object.assign(Object.assign({},e),{buttonLayout:r,visible:!0})),c._onAction=t})}}; |