Quellcode durchsuchen

增加测试代码

liudan vor 3 Monaten
Ursprung
Commit
38cf32932d
1 geänderte Dateien mit 27 neuen und 98 gelöschten Zeilen
  1. 27 98
      src/api/index.js

+ 27 - 98
src/api/index.js

@@ -2,7 +2,7 @@
  * 公用的请求方法
  */
 import io from 'socket.io-client'; //io進行通訊
-import { Toast } from 'antd-mobile';
+import { Toast, Modal } from 'antd-mobile';
 
 // 获取请求的地址
 const getBaseUrl = () => {
@@ -358,6 +358,7 @@ const testSocket = (getMessage) => {
   }
 };
 // scoket创建
+let handler = null;
 export const initSocket = (obj, getMessage) => {
   // 测试模拟发送消息start!!!!
   // if (testSocket(getMessage)) {
@@ -391,10 +392,16 @@ export const initSocket = (obj, getMessage) => {
   //服务器连接异常
   window.socket.on('connect_error', (e) => {
     console.log('connect_error', e);
-    Toast.show({
-      duration: 10000,
-      content: 'scoket连接出错了' + e,
-    });
+    // Toast.show({
+    //   duration: 10000,
+    //   content: 'scoket连接出错了' + e,
+    // });
+    if (!handler) {
+      handler = Modal.show({
+        content: '连接断开' + e,
+        closeOnMaskClick: true,
+      });
+    }
     window.socket.close();
     window.socket = null;
     initSocket(obj, getMessage);
@@ -409,6 +416,11 @@ export const initSocket = (obj, getMessage) => {
   });
   window.socket.on('connect', function () {
     console.log('scoket连接成功');
+    console.log(handler);
+    if (handler) {
+      handler?.close();
+      handler = null;
+    }
     Toast.show({
       duration: 10000,
       content: '连接成功',
@@ -416,100 +428,17 @@ export const initSocket = (obj, getMessage) => {
   });
 
   window.socket.on('disconnect', function (e) {
-    Toast.show({
-      duration: 10000,
-      content: '连接断开' + e,
-    });
+    // Toast.show({
+    //   duration: 10000,
+    //   content: '连接断开' + e,
+    // });
+    if (!handler) {
+      handler = Modal.show({
+        content: '连接断开' + e,
+        closeOnMaskClick: true,
+      });
+    }
     // window.socket = null;
     // initSocket(obj, getMessage);
   });
-  // todo 测试
-  // getMessage({
-  //   'locID': '1328',
-  //   'locDesc': '住院手术室',
-  //   'locENDesc': '',
-  //   'purposeCode': 'OperLoc',
-  //   'roomID': '',
-  //   'roomDesc': '手术室',
-  //   'roomENDesc': '',
-  //    userData: {
-  //     userImage:'',
-  //     userDesc: '用户名',
-  //     userTitleDesc: '职称',
-  //     userIntroduce: '简介',
-  //     userQrCode: 'http://localhost:5173/callapp/',
-  //   },
-  //   'callMsg': {
-  //   'callPat': [{
-  //       'patName': '北2号',
-  //       'patSex': '男',
-  //       'patAge': '24岁',
-  //       'patOpeName': '可植入式隐形眼镜置入术[ICL置入术]',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     },
-  //     {
-  //       'patName': '北3号',
-  //       'patSex': '男',
-  //       'patAge': '23岁',
-  //       'patOpeName': '白内障超声乳化抽吸术',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     },
-  //     {
-  //       'patName': '北1号',
-  //       'patSex': '男',
-  //       'patAge': '24岁',
-  //       'patOpeName': '白内障超声乳化抽吸术',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     },
-  //     {
-  //       'patName': '北1号',
-  //       'patSex': '男',
-  //       'patAge': '24岁',
-  //       'patOpeName': '白内障针吸术',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //   }],
-  //   'waitPat': [{
-  //       'patName': '北2号',
-  //       'patSex': '男',
-  //       'patAge': '24岁',
-  //       'patOpeName': '可植入式隐形眼镜置入术[ICL置入术]',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     },
-  //     {
-  //       'patName': '北3号',
-  //       'patSex': '男',
-  //       'patAge': '23岁',
-  //       'patOpeName': '白内障超声乳化抽吸术',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     },
-  //     {
-  //       'patName': '北1号',
-  //       'patSex': '男',
-  //       'patAge': '24岁',
-  //       'patOpeName': '白内障超声乳化抽吸术',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     },
-  //     {
-  //       'patName': '北1号',
-  //       'patSex': '男',
-  //       'patAge': '24岁',
-  //       'patOpeName': '白内障针吸术',
-  //       'patOpeState': '术中',
-  //       'patOpeRom': '1室'
-  //     }
-  //   ]},
-  //     'readMsg': {},
-  //     'areaID': '',
-  //     'docName': '住院手术室',
-  //     'deviceList': [{
-  //       'deviceID': '4abda00d976b1fe2A1680F7A6D9B12655546D514A226FA476F90DA5'
-  //     }]
-  // });
 };