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QACvC,OAAO,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,CAAC,OAAiC;QACvC,OAAO,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IACD,KAAK,CAAC,OAAiC;QACrC,OAAO,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IACD,IAAI;QACF,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;QAC/B,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO;SACR;QACD,QAAQ,CAAC,IAAI,EAAE,CAAC;IAClB,CAAC;CACF,CAAC","file":"index.js","sourcesContent":["import { MessageType, MessageProps } from './message.interface';\n\ntype Context = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;\n\ninterface MessageActionOptionsType extends Optional<MessageProps> {\n context?: Context;\n selector?: string;\n}\n\nconst getInstance = function (context?: Context, selector = '#t-message') {\n if (!context) {\n const pages = getCurrentPages();\n const page = pages[pages.length - 1];\n context = page.$$basePage || page;\n }\n const instance = context?.selectComponent(selector);\n if (!instance) {\n return null;\n }\n return instance;\n};\n\nconst showMessage = function (\n options: MessageActionOptionsType,\n theme: MessageType = MessageType.info,\n) {\n const { context, selector } = options;\n const instance = getInstance(context, selector);\n\n if (!instance) {\n return Promise.reject(new Error('未找到Message组件, 请检查selector是否正确'));\n }\n\n // instance.hide();\n\n instance.resetData(() => {\n instance.setData({ theme, ...options }, instance.show);\n });\n\n return instance;\n};\n\nexport default {\n info(options: MessageActionOptionsType) {\n return showMessage(options, MessageType.info);\n },\n success(options: MessageActionOptionsType) {\n return showMessage(options, MessageType.success);\n },\n warning(options: MessageActionOptionsType) {\n return showMessage(options, MessageType.warning);\n },\n error(options: MessageActionOptionsType) {\n return showMessage(options, MessageType.error);\n },\n hide() {\n const instance = getInstance();\n if (!instance) {\n return;\n }\n instance.hide();\n },\n};\n"]}
|