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ts","sourcesContent":["import props from './props';\n\ntype Context = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;\n\ninterface DialogAlertOptionsType {\n context?: Context;\n selector?: string;\n title?: string;\n content: string;\n zIndex?: number;\n asyncClose?: boolean;\n confirmButtonText?: string;\n textAlign?: string;\n cancelBtn?: string | object;\n confirmBtn?: string | object;\n}\n\ninterface DialogComfirmOptionsType extends DialogAlertOptionsType {\n cancelButtonText?: string;\n}\n\ninterface Action {\n name: string;\n primary?: boolean;\n style?: string;\n}\n\ninterface DialogActionOptionsType {\n context?: Context;\n selector?: string;\n title?: string;\n content: string;\n zIndex?: number;\n asyncClose?: boolean;\n actions?: Action[]; // 自定义多选项,优先级高于默认的确定、取消按钮,触发后返回按钮的index\n buttonLayout?: 'vertical' | 'horizontal'; // 多按钮排列方式,可选值:horizontal/vertical。\n}\n\nconst defaultOptions = {\n actions: false,\n buttonLayout: props.buttonLayout.value,\n cancelBtn: props.cancelBtn.value,\n closeOnOverlayClick: props.closeOnOverlayClick.value,\n confirmBtn: props.confirmBtn.value,\n content: '',\n preventScrollThrough: props.preventScrollThrough.value,\n showOverlay: props.showOverlay.value,\n title: '',\n visible: props.visible.value,\n};\n\nconst getDialogInstance = function (context?: Context, selector = '#t-dialog') {\n if (!context) {\n const pages = getCurrentPages();\n const page = pages[pages.length - 1];\n context = page.$$basePage || page;\n }\n const instance = context ? context.selectComponent(selector) : null;\n if (!instance) {\n console.warn('未找到dialog组件,请检查selector是否正确');\n return null;\n }\n return instance;\n};\n\nexport default {\n alert(options: DialogAlertOptionsType) {\n const { context, selector, ...otherOptions } = { ...defaultOptions, ...options };\n const instance = getDialogInstance(context, selector);\n if (!instance) return Promise.reject();\n\n return new Promise((resolve) => {\n instance.setData({\n cancelBtn: '',\n ...otherOptions,\n visible: true,\n });\n instance._onComfirm = resolve;\n });\n },\n confirm(options: DialogComfirmOptionsType) {\n const { context, selector, ...otherOptions } = { ...defaultOptions, ...options };\n const instance = getDialogInstance(context, selector);\n if (!instance) return Promise.reject();\n\n return new Promise((resolve, reject) => {\n instance.setData({\n ...otherOptions,\n visible: true,\n });\n instance._onComfirm = resolve;\n instance._onCancel = reject;\n });\n },\n close() {\n const instance = getDialogInstance();\n if (instance) {\n instance.close();\n return Promise.resolve();\n }\n return Promise.reject();\n },\n action(options: DialogActionOptionsType): Promise<{ index: number }> {\n const { context, selector, actions, ...otherOptions } = { ...defaultOptions, ...options };\n const instance = getDialogInstance(context, selector);\n if (!instance) return Promise.reject();\n if (!actions || (typeof actions === 'object' && (actions.length === 0 || actions.length > 7))) {\n console.warn('action 数量建议控制在1至7个');\n }\n\n return new Promise((resolve) => {\n instance.setData({\n actions,\n buttonLayout: 'vertical',\n ...otherOptions,\n visible: true,\n });\n instance._onAction = resolve;\n });\n },\n};\n"]}
|