Bladeren bron

日常开发

linxuxiang 6 maanden geleden
bovenliggende
commit
618fb33980
5 gewijzigde bestanden met toevoegingen van 123 en 27 verwijderingen
  1. 22 14
      src/utils/handWs.ts
  2. 11 3
      src/utils/ws.ts
  3. 1 1
      src/views/gesture/index.vue
  4. 44 2
      src/views/train/multiple.vue
  5. 45 7
      src/views/train/test.vue

+ 22 - 14
src/utils/handWs.ts

@@ -1,6 +1,7 @@
 import io from 'socket.io-client';
 import { ref, onMounted, onUnmounted } from 'vue';
 import useAppStore from '@/store/modules/app';
+import router from '@/router';
 
 export function useWebSocket() {
   const address: any = import.meta.env.VITE_APP_BASE_API;
@@ -8,27 +9,27 @@ export function useWebSocket() {
   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 = null; //ws实例对象
+  // 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 = null; //ws实例对象
+    socketHand = io(address + '/', {
+      transports: ['websocket', 'polling'],
+      query: {
+        Authorization: token ? myToken : '',
+      }
+    });
 
   function handWs(callback: any) {
-    if(socketHand==null){
+    if(socketHand == null){
       return false;
     }
     callback({
@@ -139,8 +140,15 @@ export function useWebSocket() {
   };
 
   onUnmounted(() => {
+    // if (socketHand) {
+    //   // if(['/gesture'].includes(router.currentRoute.value.path)){
+    //   //   socketHand.close();
+    //   //   socketHand = null;
+    //   // }
+    //   socketHand = null;
+    // }
     if (socketHand) {
-      // socketHand.close();
+      socketHand.close();
       socketHand = null;
     }
   });

+ 11 - 3
src/utils/ws.ts

@@ -1,4 +1,5 @@
 import io from 'socket.io-client';
+import { ref, onMounted, onUnmounted } from 'vue';
 const address: any = import.meta.env.VITE_APP_BASE_API;
 const token: any = localStorage.getItem('token');
 const myInfo: any = localStorage.getItem('userInfo');
@@ -196,7 +197,7 @@ export const initWs = (data: any, callback: any) => {
  */
 export const sendMessage = (type: string, data: any, callback?: () => void) => {
   if (socket.connected) {
-    callback = callback || function () {};
+    callback = callback || function () { };
     //版本2就拼接进去
     if (version == 'v2') {
       type = type + '_' + version;
@@ -221,7 +222,7 @@ const getTaskStarts = (data?: any) => {
       demo: parameter.demo,
       test_time: testTime
     },
-    () => {}
+    () => { }
   );
 };
 
@@ -240,7 +241,7 @@ const getExamStarts = (data?: any) => {
       demo: parameter.demo,
       test_time: testTime
     },
-    () => {}
+    () => { }
   );
 };
 
@@ -584,3 +585,10 @@ const getClearTimer = () => {
     }
   }
 };
+
+onUnmounted(() => {
+  if (socket) {
+    socket.close();
+    socket = null;
+  }
+});

+ 1 - 1
src/views/gesture/index.vue

@@ -290,7 +290,7 @@ onBeforeMount(() => {
     if(router.currentRoute.value.path != '/gesture'){
       return false;
     }
-    console.log("eeeee", e)
+    // console.log("eeeee", e)
     if (e?.wksid) {
       //获取设备项目
       getDevice()

+ 44 - 2
src/views/train/multiple.vue

@@ -71,7 +71,7 @@
 import { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
 import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech'
 import { useWebSocket } from '@/utils/handWs';  
-const { handWs } = useWebSocket();
+const { handWs,startDevice, startHand, stateHand } = useWebSocket();
 // const { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } = useWs();
 const { proxy } = getCurrentInstance() as any;
 const router = useRouter();
@@ -98,8 +98,9 @@ const data = reactive<any>({
   exit: 0,//退出响应次数
   sid: null,//WS的id
   chooseStudentArea:'',//弹出手动选择对应的区号
+  device_info:{},//设备信息
 });
-const { timerManager, parameter, time, userInfo, examState, needStart, showTestAgain, testList, multipleItemRefList, styleType, showReportList, exit, sid, chooseStudentArea } = toRefs(data);
+const { timerManager, parameter, time, userInfo, examState, needStart, showTestAgain, testList, multipleItemRefList, styleType, showReportList, exit, sid, chooseStudentArea,device_info } = toRefs(data);
 
 /**
  * 创建组件实例
@@ -582,6 +583,25 @@ const getAddTestList = (num: number) => {
   }
 };
 
+/**
+ * 获取设备项目
+*/
+const getDevice = async () => {
+  let deviceid = localStorage.getItem("deviceid") || '';
+  if (deviceid) {
+    startDevice({ deviceid: deviceid })
+  } else {
+    proxy?.$modal.msgError(`缺少设备信息请重新登录!`);
+    await proxy?.$http.common.logout({}).then((res: any) => {
+    });
+    proxy?.$modal?.closeLoading()
+    //清空缓存
+    localStorage.clear();
+    //跳转
+    router.push({ path: '/login/qrcode' });
+  }
+};
+
 /**
  * 加载手势WS
 */
@@ -590,18 +610,39 @@ const initHand = () => {
     if (router.currentRoute.value.path != '/train/multiple'){
       return false;
     }
+    console.log("eeeee", e)
+    if (e?.wksid) {
+      //获取设备项目
+      getDevice()
+    }
+    //接收设备信息
+    if (e?.device_info) {
+      device_info.value = e.device_info;
+      let handcontroller_id = device_info.value.handcontroller_id;
+      stateHand(handcontroller_id);
+    }
+    //获取手势状态
+    if (e?.cmd == 'get_handcontroller_state' && e?.state == 0) {
+      let handcontroller_id = device_info.value.handcontroller_id;
+      startHand(handcontroller_id);
+    }
     //左滑动
     if (e?.data?.result == "next_item") {
     }
     //举左手
     if (e?.data?.result == "left_hand") {
+      console.log("qqqqqqqqqqqqqqqqqqqq")
       //开始识别
       if (needStart.value && examState.value < 41) {
+        console.log("111111111111111111111")
         getOpenOneTestAndStartFace();
+        return false;
       }
       //停止人脸识别
       if (needStart.value && examState.value == 41) {
+        console.log("222222222222222222222")
         getStopFace();
+        return false;
       }
       //开始测试
       if (examState.value == 43) {
@@ -610,6 +651,7 @@ const initHand = () => {
         } else {
           getStartOneTest();
         }
+        return false;
       }
       //确认退出
       if (exit.value) {

+ 45 - 7
src/views/train/test.vue

@@ -21,7 +21,7 @@
               :leave-active-class="proxy?.animate.dialog.leave">
               <div class="time" v-show="needStart && [42].includes(examState)">{{
                 time.countdownNum
-                }}</div>
+              }}</div>
             </Transition>
             <div class="tips" v-if="examState == 41">
               <img v-if="parameter.gesture" src="@/assets/images/test/ready1.png" />
@@ -48,8 +48,7 @@
               </div>
             </div>
             <div class="foulBox" v-if="examState == 42 && backReason.length">
-              <Transition :enter-active-class="proxy?.animate.mask.enter"
-                :leave-active-class="proxy?.animate.mask.leave">
+              <Transition :enter-active-class="proxy?.animate.mask.enter" :leave-active-class="proxy?.animate.mask.leave">
                 <div class="foul" v-show="backReasonStr ? true : false">
                   <div class="lable">!</div>
                   <div class="value">{{ backReasonStr }}</div>
@@ -116,10 +115,10 @@
 // import { useWs } from '@/utils/trainWs';
 import { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } from '@/utils/ws'
 import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech'
-import { useWebSocket } from '@/utils/handWs';  
+import { useWebSocket } from '@/utils/handWs';
 import dayjs from 'dayjs'
 import dataDictionary from "@/utils/dataDictionary"
-const { handWs } = useWebSocket();
+const { handWs, startDevice, startHand, stateHand } = useWebSocket();
 // const { initWs, examEnds, openOneTest, startFace, stopFace, faceConfirmOnly, startOneTest, finishOneTest, closeOneTest, suspendFaceRecognitionChannels, resumeFaceRecognitionChannels } = useWs();
 const { proxy } = getCurrentInstance() as any;
 const router = useRouter();
@@ -151,8 +150,9 @@ const data = reactive<any>({
   readyState: true,//倒计时按钮状态
   exit: 0,//退出响应次数
   sid: null,//WS的id
+  device_info: {},//设备信息
 });
-const { timerManager, parameter, time, userInfo, examState, resultId, faceCheckStu, currentResultObj, unit, backReason, backReasonStr, needStart, showTestAgain, readyState, exit, sid } = toRefs(data);
+const { timerManager, parameter, time, userInfo, examState, resultId, faceCheckStu, currentResultObj, unit, backReason, backReasonStr, needStart, showTestAgain, readyState, exit, sid, device_info } = toRefs(data);
 
 /**
  * 接收消息
@@ -695,14 +695,50 @@ const getReady = () => {
   }
 };
 
+/**
+ * 获取设备项目
+*/
+const getDevice = async () => {
+  let deviceid = localStorage.getItem("deviceid") || '';
+  if (deviceid) {
+    startDevice({ deviceid: deviceid })
+  } else {
+    proxy?.$modal.msgError(`缺少设备信息请重新登录!`);
+    await proxy?.$http.common.logout({}).then((res: any) => {
+    });
+    proxy?.$modal?.closeLoading()
+    //清空缓存
+    localStorage.clear();
+    //跳转
+    router.push({ path: '/login/qrcode' });
+  }
+};
+
+
 /**
  * 加载手势WS
 */
 const initHand = () => {
   handWs((e: any) => {
-    if (router.currentRoute.value.path != '/train/test'){
+    if (router.currentRoute.value.path != '/train/test') {
       return false;
     }
+    console.log("eeeee", e)
+    if (e?.wksid) {
+      //获取设备项目
+      getDevice()
+    }
+    //接收设备信息
+    if (e?.device_info) {
+      device_info.value = e.device_info;
+      let handcontroller_id = device_info.value.handcontroller_id;
+      stateHand(handcontroller_id);
+    }
+    //获取手势状态
+    if (e?.cmd == 'get_handcontroller_state' && e?.state == 0) {
+      let handcontroller_id = device_info.value.handcontroller_id;
+      startHand(handcontroller_id);
+    }
     //左滑动
     if (e?.data?.result == "next_item") {
     }
@@ -711,6 +747,7 @@ const initHand = () => {
       //开始识别
       if (needStart.value && examState.value < 41) {
         getOpenOneTestAndStartFace();
+        return false;
       }
       //停止人脸识别
       // if (needStart.value && examState.value == 41) {
@@ -723,6 +760,7 @@ const initHand = () => {
         } else {
           getStartOneTest();
         }
+        return false;
       }
       if (exit.value) {
         exit.value = 0;