| import { NewPromptOneLine } from '@12333/components'; | 
| import { Portal, Model } from 'senin-mini/components'; | 
| import { Toast, Input } from '@nutui/nutui-taro'; | 
| import { ExtractPropTypes } from 'vue'; | 
| import { VNode } from 'vue'; | 
| import _ from 'lodash'; | 
|   | 
| type ToastInstance = InstanceType<typeof Toast>; | 
|   | 
| type ToastProps = ExtractPropTypes<ToastInstance['$props']>; | 
|   | 
| type InputInstance = InstanceType<typeof Input>; | 
|   | 
| type InputProps = ExtractPropTypes<InputInstance['$props']>; | 
|   | 
| type PromptOptions = { | 
|   title?: string; | 
|   inputProps?: Partial<InputProps>; | 
|   onConfirm?: (value: string, done: () => any) => any; | 
|   showCount?: boolean; | 
|   confirmText?: string; | 
| }; | 
|   | 
| type ConfirmOptions = { | 
|   title?: string; | 
|   message?: string | VNode; | 
|   confirmText?: string; | 
|   cancelText?: string; | 
|   showCancelBtn?: boolean; | 
| }; | 
|   | 
| export class Message { | 
|   static confirm(options: ConfirmOptions = {}) { | 
|     const { | 
|       title = '提示', | 
|       message = '确定要删除该数据吗?', | 
|       confirmText = '确认', | 
|       cancelText = '取消', | 
|       showCancelBtn = true, | 
|     } = options; | 
|     return new Promise((resolve, reject) => { | 
|       Portal.add((key) => { | 
|         return ( | 
|           //@ts-ignore | 
|           <Portal.Container keyNumber={key} delayOpen> | 
|             {{ | 
|               default: ({ open, onClose }) => ( | 
|                 //@ts-ignore | 
|                 <Model | 
|                   title={title} | 
|                   visible={open.value} | 
|                   content={message} | 
|                   showCancelBtn={showCancelBtn} | 
|                   cancelText={cancelText} | 
|                   onCancel={() => { | 
|                     onClose(); | 
|                     reject(); | 
|                   }} | 
|                   onConfirm={() => { | 
|                     onClose(); | 
|                     resolve(1); | 
|                   }} | 
|                   confirmText={confirmText} | 
|                   //@ts-ignore | 
|                   onClickOverlay={() => { | 
|                     onClose(); | 
|                     reject(); | 
|                   }} | 
|                 ></Model> | 
|               ), | 
|             }} | 
|           </Portal.Container> | 
|         ); | 
|       }); | 
|     }); | 
|   } | 
|   static success(msg: string, options: Partial<ToastProps> = {}) { | 
|     Portal.add((key) => { | 
|       const _options = _.omit(options, ['onClosed']); | 
|       return ( | 
|         //@ts-ignore | 
|         <Portal.Container keyNumber={key}> | 
|           {{ | 
|             default: ({ open, onClose }) => ( | 
|               <Toast | 
|                 msg={msg} | 
|                 visible={open.value} | 
|                 type="success" | 
|                 cover | 
|                 onClosed={() => { | 
|                   onClose(); | 
|                   options?.onClosed?.(); | 
|                 }} | 
|                 {..._options} | 
|               ></Toast> | 
|             ), | 
|           }} | 
|         </Portal.Container> | 
|       ); | 
|     }); | 
|   } | 
|   static error(msg: string, options: Partial<ToastProps> = {}) { | 
|     Portal.add((key) => { | 
|       return ( | 
|         //@ts-ignore | 
|         <Portal.Container keyNumber={key}> | 
|           {{ | 
|             default: ({ open, onClose }) => ( | 
|               <Toast | 
|                 msg={msg} | 
|                 visible={open.value} | 
|                 type="fail" | 
|                 cover | 
|                 onClosed={onClose} | 
|                 {...options} | 
|               ></Toast> | 
|             ), | 
|           }} | 
|         </Portal.Container> | 
|       ); | 
|     }); | 
|   } | 
|   static warning(msg: string, options: Partial<ToastProps> = {}) { | 
|     Portal.add((key) => { | 
|       return ( | 
|         //@ts-ignore | 
|         <Portal.Container keyNumber={key}> | 
|           {{ | 
|             default: ({ open, onClose }) => ( | 
|               <Toast | 
|                 msg={msg} | 
|                 visible={open.value} | 
|                 type="warn" | 
|                 cover | 
|                 onClosed={onClose} | 
|                 {...options} | 
|               ></Toast> | 
|             ), | 
|           }} | 
|         </Portal.Container> | 
|       ); | 
|     }); | 
|   } | 
|   | 
|   static newPromptOneLine(options: PromptOptions) { | 
|     function handleConfirm(v, onClose) { | 
|       options.onConfirm?.(v, onClose); | 
|     } | 
|     Portal.add((key) => { | 
|       return ( | 
|         //@ts-ignore | 
|         <Portal.Container keyNumber={key} delayOpen> | 
|           {{ | 
|             default: ({ open, onClose }) => ( | 
|               //@ts-ignore | 
|               <NewPromptOneLine | 
|                 visible={open.value} | 
|                 onUpdate:visible={(value) => !value && onClose()} | 
|                 title={options.title} | 
|                 inputProps={options.inputProps} | 
|                 showCount={options.showCount} | 
|                 confirmText={options.confirmText} | 
|                 onOnClose={onClose} | 
|                 onConfirm={(v) => handleConfirm(v, onClose)} | 
|               ></NewPromptOneLine> | 
|             ), | 
|           }} | 
|         </Portal.Container> | 
|       ); | 
|     }); | 
|   } | 
| } |