linxuxiang 5 months ago
parent
commit
f53114b5be
3 changed files with 35 additions and 29 deletions
  1. 31 29
      src/utils/handWs.ts
  2. 1 0
      src/utils/trainWs.ts
  3. 3 0
      src/views/gesture/index.vue

+ 31 - 29
src/utils/handWs.ts

@@ -1,35 +1,37 @@
 import io from 'socket.io-client';
 import { ref, onMounted, onUnmounted } from 'vue';
 import useAppStore from '@/store/modules/app';
-import router from '@/router';
+// import router from '@/router';
 
-const address: any = import.meta.env.VITE_APP_BASE_API;
-const token: any = localStorage.getItem('token');
-const deviceid: any = localStorage.getItem('deviceid');
-const myToken: any = 'JWT ' + token;
 
-let socketHand: any = null; //ws实例对象
-socketHand = io(address + '/', {
-  transports: ['websocket', 'polling'],
-  query: {
-    Authorization: token ? myToken : ''
-  }
-});
 
+// let socketHand: any = null; //ws实例对象
+// socketHand = io(address + '/', {
+//   transports: ['websocket', 'polling'],
+//   query: {
+//     type: 'hand',
+//     Authorization: token ? myToken : ''
+//   }
+// });
 
-export function useWebSocket() {
 
+export function useWebSocket() {
+  const address: any = import.meta.env.VITE_APP_BASE_API;
+  const token: any = localStorage.getItem('token');
+  const deviceid: any = localStorage.getItem('deviceid');
+  const myToken: any = 'JWT ' + token;
 
-  // let socketHand: any = useAppStore().getSocketHand() || null; //ws实例对象
-  // if (socketHand == null) {
-  //   socketHand = io(address + '/', {
-  //     transports: ['websocket', 'polling'],
-  //     query: {
-  //       Authorization: token ? myToken : '',
-  //     }
-  //   });
-  //   useAppStore().setSocketHand(socketHand);
-  // }
+  let socketHand: any = useAppStore().getSocketHand() || null; //ws实例对象
+  if (socketHand == null) {
+    socketHand = io(address + '/', {
+      transports: ['websocket', 'polling'],
+      query: {
+        type: 'hand',
+        Authorization: token ? myToken : '',
+      }
+    });
+    useAppStore().setSocketHand(socketHand);
+  }
 
   function handWs(callback: any) {
     if (socketHand == null) {
@@ -69,7 +71,7 @@ export function useWebSocket() {
       return false;
     }
     if (socketHand.connected) {
-      callback = callback || function () {};
+      callback = callback || function () { };
       socketHand.emit(type, data, callback);
     }
   }
@@ -83,7 +85,7 @@ export function useWebSocket() {
       {
         deviceid: deviceid ? deviceid : ''
       },
-      () => {}
+      () => { }
     );
   }
 
@@ -96,7 +98,7 @@ export function useWebSocket() {
       {
         data: data
       },
-      () => {}
+      () => { }
     );
   }
 
@@ -110,7 +112,7 @@ export function useWebSocket() {
         hctrl_name: `handcontroller_${data}`,
         cmd: 'open_handcontroller'
       },
-      () => {}
+      () => { }
     );
   }
 
@@ -124,7 +126,7 @@ export function useWebSocket() {
         hctrl_name: `handcontroller_${data}`,
         cmd: 'get_handcontroller_state'
       },
-      () => {}
+      () => { }
     );
   }
 
@@ -138,7 +140,7 @@ export function useWebSocket() {
         hctrl_name: `handcontroller_${data}`,
         cmd: 'terminate_handcontroller'
       },
-      () => {}
+      () => { }
     );
   }
 

+ 1 - 0
src/utils/trainWs.ts

@@ -21,6 +21,7 @@ export function useWs() {
   socket = io(address + '/midexam', {
     transports: ['websocket', 'polling'],
     query: {
+      type: 'train',
       Authorization: 'JWT ' + token,
       sysuuid: 'JWT ' + token
     }

+ 3 - 0
src/views/gesture/index.vue

@@ -308,6 +308,7 @@ onBeforeMount(() => {
     }
     //左滑动
     if (e?.data?.result == "next_item") {
+      proxy?.$modal.msgSuccess('手势指令:左滑动');
       if (projectList.value.length == 0) {
         return false;
       }
@@ -315,10 +316,12 @@ onBeforeMount(() => {
     }
     //举左手
     if (e?.data?.result == "left_hand") {
+      proxy?.$modal.msgSuccess('手势指令:举左手');
       confirm();
     }
     //退出
     if (e?.data?.result == "exit") {
+      proxy?.$modal.msgSuccess('手势指令:交叉手');
     }
     //刷新
     if (e?.data?.result == "refresh") {