瀏覽代碼

elmessagebox

xiaochan 2 年之前
父節點
當前提交
ca40e13cbb

+ 19 - 1
src/components/cy/message-box/cy-message-box.ts

@@ -9,6 +9,7 @@ import {
     DeleteFilled
 } from '@element-plus/icons-vue'
 import {IElMessageBox, MessageBoxType} from "./message-box.type";
+import {uuid} from '../../../utils/getUuid'
 
 const iconData = {
     success: {
@@ -38,6 +39,7 @@ const iconData = {
     }
 }
 
+const messageInstance = new Map <string, { close: () => void }>
 
 const MESSAGE_BOX_VARIANTS = ['alert', 'confirm', 'prompt'] as const
 const MESSAGE_BOX_DEFAULT_OPTS: {
@@ -75,10 +77,12 @@ function MessageBox(options: MessageBoxType) {
     const div = document.createElement('div');
     document.body.appendChild(div);
     const icon = getIcon(options)
+    const id = options.boxId || 'cy' + uuid(5);
 
     function clearDiv() {
         render(null, div);
         div.remove();
+        messageInstance.delete(id);
     }
 
     return new Promise((resolve, reject) => {
@@ -92,17 +96,31 @@ function MessageBox(options: MessageBoxType) {
             },
             onVanish: () => {
                 clearDiv();
+            },
+            setClose: (close: () => void) => {
+                if (messageInstance.has(id)) {
+                    messageInstance.get(id)?.close()
+                }
+                messageInstance.set(id, {close})
             }
         }
 
         Object.assign(data, options, {...icon});
-
         const vNode = createVNode(MessageBoxConstructor,
             data,
             null);
         render(vNode, div);
     });
+}
 
+MessageBox.close = (id: string) => {
+    if (id) {
+        messageInstance.get(id)?.close()
+    } else {
+        messageInstance.forEach((value, key) => {
+            messageInstance.get(key)?.close()
+        })
+    }
 }
 
 export default MessageBox as IElMessageBox;

+ 9 - 0
src/components/cy/message-box/index.vue

@@ -84,6 +84,12 @@ const props = defineProps({
   showCancelButton: {
     type: Boolean,
     default: true
+  },
+  setClose: {
+    type: Function,
+    default: () => {
+
+    }
   }
 })
 
@@ -186,6 +192,9 @@ watch(() => visible.value, (val) => {
 useDraggable(rootRef, headerRef, draggable)
 
 onMounted(async () => {
+  props.setClose(() => {
+    handelClose('close')
+  })
   zIndex.value = useZIndex().nextZIndex()
   await nextTick()
   await sleep(100);

+ 4 - 1
src/components/cy/message-box/message-box.type.ts

@@ -13,7 +13,8 @@ export interface MessageBoxType {
     selectOption?: { code: string, name: string }[],
     inputRows?: number;
     showCancelButton?: boolean,
-    inputDefaultValue?: string
+    inputDefaultValue?: string,
+    boxId? :string
 }
 
 export type CyMessageBoxShortcutMethod = ((
@@ -32,4 +33,6 @@ export interface IElMessageBox {
 
     /** Show a prompt message box */
     prompt: CyMessageBoxShortcutMethod
+
+    close: (id?: string) => void;
 }

+ 1 - 1
src/utils/getUuid.js → src/utils/getUuid.ts

@@ -1,4 +1,4 @@
-export function uuid(len, radix) {
+export function uuid(len = 5, radix = 62) {
     const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
     let uuid = [], i;
     radix = radix || chars.length;

+ 2 - 2
src/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/EmrMain.vue

@@ -54,13 +54,13 @@
       <el-button type="primary"
                  icon="Printer"
                  @click="frontEndPrinting"
-                 title="页面打印支持病历续打,但是可能会出现打印错误,如果页面打印无法使用请用服务打印,服务打印也不行请换win10电脑打印。">
+                 v-title="'页面打印支持病历续打,但是可能会出现打印错误,如果页面打印无法使用请用服务打印,服务打印也不行请换win10电脑打印。'">
         页面
       </el-button>
       <el-button type="primary"
                  icon="Printer"
                  @click="servicePrint"
-                 title="服务打印慢,但是不会出现页面打印错误,不支持病历续打。">
+                 v-title="'服务打印慢,但是不会出现页面打印错误,不支持病历续打。'">
         服务
       </el-button>
     </el-button-group>