|
@@ -3,8 +3,6 @@ import { useWebSocket, UseWebSocketReturn } from "@vueuse/core";
|
|
|
import { ElMessageBox, ElNotification } from "element-plus";
|
|
|
import { EmrStore } from "@/views/hospitalization/zhu-yuan-yi-sheng/electronic-medical-record/emr-func/useEmrStore";
|
|
|
import { EditType } from "@/utils/emr/edit";
|
|
|
-import { stringIsBlank } from "@/utils/blank-utils";
|
|
|
-import { xcMessage } from "@/utils/xiaochan-element-plus";
|
|
|
import XEUtils from "xe-utils";
|
|
|
|
|
|
const us = useUserStore().userInfo;
|
|
@@ -57,6 +55,17 @@ const socketMsg = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+const setInfo = () => {
|
|
|
+ return JSON.stringify({
|
|
|
+ code: MessageType.USER_INFO,
|
|
|
+ data: {
|
|
|
+ deptName: us.deptName,
|
|
|
+ name: us.name,
|
|
|
+ code: us.code,
|
|
|
+ },
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
export function useEmrSocket(
|
|
|
patInfo: string,
|
|
|
store: EmrStore["store"],
|
|
@@ -75,16 +84,6 @@ export function useEmrSocket(
|
|
|
},
|
|
|
});
|
|
|
|
|
|
- const setInfo = () => {
|
|
|
- return JSON.stringify({
|
|
|
- code: MessageType.USER_INFO,
|
|
|
- data: {
|
|
|
- deptName: us.deptName,
|
|
|
- name: us.name,
|
|
|
- },
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
const { status, send } = useWebSocket(URL + "/emrEditor/" + sid, {
|
|
|
autoReconnect: true,
|
|
|
onError: (ws, event) => {
|
|
@@ -119,13 +118,10 @@ export function useEmrSocket(
|
|
|
* 发送用户当前在看什么病历
|
|
|
*/
|
|
|
function sendCurrentDocument() {
|
|
|
- if (stringIsBlank(editor()?.documentData?._id)) {
|
|
|
- return;
|
|
|
- }
|
|
|
sendMsg({
|
|
|
code: MessageType.VIEW_DOCUMENT,
|
|
|
data: {
|
|
|
- id: editor().documentData._id,
|
|
|
+ id: editor()?.documentData?._id,
|
|
|
name: us.name,
|
|
|
},
|
|
|
});
|
|
@@ -161,30 +157,74 @@ export function documentSocket(
|
|
|
status: ref(),
|
|
|
};
|
|
|
|
|
|
+ let documentId: string;
|
|
|
+
|
|
|
+ function open(id: string) {
|
|
|
+ documentId = id;
|
|
|
+ newSocket(URL + "/emrDocument/" + id);
|
|
|
+ }
|
|
|
+
|
|
|
+ function showKickingDialog(value) {
|
|
|
+ ElMessageBox.confirm(
|
|
|
+ `编辑者:【${value.name}】,
|
|
|
+ 科室:【${value.deptName}】<br />
|
|
|
+ 正在编辑病历,请医生退出后,重新打开病历。
|
|
|
+ <br />
|
|
|
+ <span style="color: red">强制提出人员,会导致当前正在编辑的医生,退出当前病历在点击之前请确保没有医生正在编辑了。</span>
|
|
|
+ `,
|
|
|
+ "有人在编辑病历",
|
|
|
+ {
|
|
|
+ type: "warning",
|
|
|
+ confirmButtonText: "只读查看",
|
|
|
+ cancelButtonText: "强制踢出人员",
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
+ distinguishCancelAndClose: true,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ editor()?.setEditorMode?.("readonly");
|
|
|
+ })
|
|
|
+ .catch(async action => {
|
|
|
+ if (action === "cancel") {
|
|
|
+ try {
|
|
|
+ await kicked.a.open(documentId);
|
|
|
+ open(documentId);
|
|
|
+ } catch (e) {
|
|
|
+ editor()?.setEditorMode?.("readonly");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ editor()?.setEditorMode?.("readonly");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
function newSocket(url: string) {
|
|
|
socketFun.close();
|
|
|
- socketFun = useWebSocket(url, {
|
|
|
+ const newSocketFun = useWebSocket(url, {
|
|
|
autoReconnect: true,
|
|
|
immediate: true,
|
|
|
+ heartbeat: {
|
|
|
+ pongTimeout: 1000,
|
|
|
+ message: setInfo(),
|
|
|
+ interval: 1000 * 60 * 3,
|
|
|
+ },
|
|
|
onDisconnected(ws, event) {
|
|
|
if (event.code > 3000) {
|
|
|
- socketFun.close();
|
|
|
+ newSocketFun.close();
|
|
|
editor().setEditorMode("readonly");
|
|
|
+
|
|
|
+ if (event.code === 3001) {
|
|
|
+ showKickingDialog(JSON.parse(event.reason));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
ElMessageBox.alert(event.reason, "出错了", {
|
|
|
type: "error",
|
|
|
}).catch(XEUtils.noop);
|
|
|
}
|
|
|
},
|
|
|
onConnected(ws) {
|
|
|
- ws.send(
|
|
|
- JSON.stringify({
|
|
|
- code: MessageType.USER_INFO,
|
|
|
- data: {
|
|
|
- name: us.name,
|
|
|
- code: us.code,
|
|
|
- },
|
|
|
- })
|
|
|
- );
|
|
|
+ ws.send(setInfo());
|
|
|
kicked.b.wsSend = value => {
|
|
|
value["kicked"] = true;
|
|
|
socketFun.send(JSON.stringify(value));
|
|
@@ -195,12 +235,11 @@ export function documentSocket(
|
|
|
kicked.b.onMsg[value?.code]?.(value.data);
|
|
|
},
|
|
|
});
|
|
|
+ socketFun = newSocketFun;
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
- open: id => {
|
|
|
- newSocket(URL + "/emrDocument/" + id);
|
|
|
- },
|
|
|
+ open,
|
|
|
status: () => socketFun.status.value,
|
|
|
sendMsg(message: any) {
|
|
|
socketFun.send(JSON.stringify(message));
|