xiaochan 8 mesiacov pred
rodič
commit
8daa866bf5

+ 5 - 6
src/components/zhu-yuan-yi-sheng/emr/web-socket/EmrWebSocket.vue

@@ -27,19 +27,19 @@
 <script setup lang="ts">
 import { stringIsBlank } from "@/utils/blank-utils";
 import {
-  ref,
+  computed,
   defineProps,
-  onMounted,
   nextTick,
-  computed,
   onBeforeUnmount,
+  onMounted,
+  ref,
 } from "vue";
 import { xcMessage } from "@/utils/xiaochan-element-plus";
 import {
   getRoomPeople,
   sendAMessage,
 } from "@/api/zhu-yuan-yi-sheng/emr-socket";
-import { ElMessageBox, ElNotification } from "element-plus";
+import { ElNotification } from "element-plus";
 import EmrChatBox from "@/components/zhu-yuan-yi-sheng/emr/web-socket/EmrChatBox.vue";
 import { emrMitt } from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/emr-init";
 import { forceRefreshDialog } from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/force-refresh-func";
@@ -57,7 +57,6 @@ const props = defineProps<{
   currentEditorUser: any;
 }>();
 const userData = useUserStore().userInfo;
-const roomRef = ref<HTMLElement | null>(null);
 
 const dialog = ref<boolean>(false);
 const errDialog = ref<boolean>(false);
@@ -256,7 +255,7 @@ const clearSocket = () => {
 
 onMounted(async () => {
   await nextTick();
-  initWebSocket(props.patInfo.inpatientNo, props.patInfo.admissTimes);
+  // initWebSocket(props.patInfo.inpatientNo, props.patInfo.admissTimes);
   emrMitt.on("getDocumentSocket", () => {
     return documentSocket;
   });

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

@@ -189,6 +189,7 @@ import useCompRef from "@/utils/useCompRef";
 import { useHistoricalData } from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/components/emr-function/useEmrFunction";
 import PatientInfoView from "@/components/zhu-yuan-yi-sheng/public/PatientInfoView.vue";
 import { useSystemStore } from "@/pinia/system-store";
+import * as socket from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/socket/useEmrSocket";
 
 const EmrWebSocket = defineAsyncComponent(
   () => import("@/components/zhu-yuan-yi-sheng/emr/web-socket/EmrWebSocket.vue")
@@ -501,6 +502,9 @@ const editJudgment = async () => {
   if (stringIsBlank(getId())) {
     return;
   }
+  emrStore.emrSocket.sendMsg({
+    code: socket.notice,
+  });
   // 发送正在看的病历
   emrSocketRef.value
     ?.medicalRecordSwitching(
@@ -1699,25 +1703,24 @@ const hisSaveEmrInit = () => {
 let hisSaveEmr: UseEmrInitReturn | null = null;
 
 function beforeRevisionAccept(evt, data) {
-  if (isCourse()) {
-    const el = editMain?.iframe.contentWindow!.document.getElementById(data.id);
-    const area = editor!.getViewByElType(el, "area");
-    const values = parsingFragmentDataElements(editor, area.model);
-    const { code } = getBcjlUserInfo(values);
-    if (code === userInfo.code) {
-      return false;
-    } else {
-      xcMessage.error("片段不是你创建的无法使用此功能。");
-      return false;
-    }
-  } else {
-    if (createId.value === userInfo.code) {
-      return false;
-    } else {
-      xcMessage.error("病历不是你创建的无法使用此功能。");
-      return false;
-    }
-  }
+  return false;
+  // if (isCourse()) {
+  //   const el = editMain?.iframe.contentWindow!.document.getElementById(data.id);
+  //   const area = editor!.getViewByElType(el, "area");
+  //   const values = parsingFragmentDataElements(editor, area.model);
+  //   const { code } = getBcjlUserInfo(values);
+  //   if (code === userInfo.code) {
+  //     return false;
+  //   } else {
+  //     return false;
+  //   }
+  // } else {
+  //   if (createId.value === userInfo.code) {
+  //     return false;
+  //   } else {
+  //     return false;
+  //   }
+  // }
 }
 
 onMounted(async () => {

+ 95 - 0
src/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/socket/useEmrSocket.ts

@@ -0,0 +1,95 @@
+import { useUserStore } from "@/pinia/user-store";
+import { useWebSocket } from "@vueuse/core";
+import { ElNotification } from "element-plus";
+
+const us = useUserStore().userInfo;
+const URL = import.meta.env.VITE_EMR_SOCKET;
+
+enum MessageType {
+  USER_INFO = "USER_INFO",
+  OPEN = "open",
+  exitEmrEditor = "exitEmrEditor",
+  notice = "notice",
+}
+
+function showRoom(data, type: string) {
+  ElNotification({
+    type,
+    // @ts-ignore
+    title: type === "success" ? "有新的连接加入" : "有连接退出",
+    dangerouslyUseHTMLString: true,
+    message: `<span>姓名:${data.name}</span>
+                <br>
+                <span>科室:${data.deptName}</span>`,
+  });
+}
+
+const socketMsg = {
+  [MessageType.OPEN]: data => {
+    showRoom(data, "success");
+  },
+  [MessageType.exitEmrEditor]: data => {
+    showRoom(data, "error");
+  },
+};
+
+export function useEmrSocket(
+  patInfo: string,
+  cb?: {
+    [key: string]: (value: any) => void;
+  }
+) {
+  Object.assign(socketMsg, cb);
+
+  const sid = patInfo + "_" + us.code;
+
+  const { data, status, send } = useWebSocket(URL + "/emrEditor/" + sid, {
+    autoReconnect: true,
+    onError: (ws, event) => {
+      console.error(ws, event);
+    },
+    onConnected: () => {
+      send(
+        JSON.stringify({
+          code: MessageType.USER_INFO,
+          data: {
+            deptName: us.deptName,
+            name: us.name,
+          },
+        })
+      );
+    },
+  });
+
+  watch(
+    () => data.value,
+    () => {
+      try {
+        const val = JSON.parse(data.value);
+        const key = val.code;
+        socketMsg?.[key]?.(val.data);
+      } catch (e) {
+        console.error("socket接受消息错误", e);
+      }
+    }
+  );
+
+  send(
+    JSON.stringify({
+      code: MessageType.OPEN,
+      data: {
+        deptName: us.deptName,
+        name: us.name,
+      },
+    })
+  );
+
+  return {
+    sendMsg(message: string) {
+      send(message);
+    },
+    status,
+  };
+}
+
+export function documentSocket() {}

+ 4 - 0
src/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-func/useEmrStore.ts

@@ -12,6 +12,7 @@ import { EmrRightTabs } from "@/views/hospitalization/zhu-yuan-yi-sheng/electron
 import sleep from "@/utils/sleep";
 import emrFunUtils from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-func/emr-fun-utils";
 import { EmrPatientData } from "@/api/zhu-yuan-yi-sheng/emr-patient";
+import * as socket from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-editor/socket/useEmrSocket";
 
 type Pl<D> = {
   [K in keyof D]: D[K] extends (...args: any[]) => infer R ? R : any;
@@ -204,11 +205,14 @@ export const useEmrStore = (patId: string) => {
     },
   };
 
+  const emrSocket = socket.useEmrSocket(patId);
+
   return {
     patInfo,
     getEditor() {
       return editor;
     },
+    emrSocket,
     emrPatientData,
     mutation,
     outline,

+ 10 - 10
src/vite-env.d.ts

@@ -1,14 +1,14 @@
 /// <reference types="vite/client" />
 interface ImportMetaEnv {
-    readonly VITE_BASE_URL: string
-    readonly VITE_SOCKET_URL: string
-    readonly VITE_EMR_CONTROL_URL: string
+  readonly VITE_BASE_URL: string;
+  readonly VITE_SOCKET_URL: string;
+  readonly VITE_EMR_CONTROL_URL: string;
 
-
-    readonly VITE_DATA_BASE: string
-    readonly VITE_MAGIC_API_IFRAME: string
-    readonly VITE_HOSPITAL_NAME: string
-    readonly VITE_SYSTEM_NAME: string
-    readonly VITE_HOSPITAL_CODE: string
-    readonly VITE_UPLOAD_TEMPLATE_THUMB: string
+  readonly VITE_DATA_BASE: string;
+  readonly VITE_MAGIC_API_IFRAME: string;
+  readonly VITE_HOSPITAL_NAME: string;
+  readonly VITE_SYSTEM_NAME: string;
+  readonly VITE_HOSPITAL_CODE: string;
+  readonly VITE_UPLOAD_TEMPLATE_THUMB: string;
+  readonly VITE_EMR_SOCKET: string;
 }