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AnF,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,OAAuD,EAAlD,YAAY,cAA7C,kCAA+C,CAAoC,CAAC;QAC1F,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ;YAAE,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE;YAC7F,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;SACpC;QAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,QAAQ,CAAC,OAAO,+BACd,OAAO,EACP,YAAY,EAAE,UAAU,IACrB,YAAY,KACf,OAAO,EAAE,IAAI,IACb,CAAC;YACH,QAAQ,CAAC,SAAS,GAAG,OAAO,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC","file":"index.js","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"]}
|