浏览代码

日常开发

林旭祥 7 月之前
父节点
当前提交
08f67f7b33
共有 5 个文件被更改,包括 56 次插入19 次删除
  1. 18 6
      src/api/request.ts
  2. 23 8
      src/views/gesture/index.vue
  3. 9 1
      src/views/login/qrcode.vue
  4. 4 3
      src/views/train/multiple.vue
  5. 2 1
      src/views/train/test.vue

+ 18 - 6
src/api/request.ts

@@ -21,8 +21,12 @@ service.interceptors.request.use(
     if (!token && Boolean(config.headers['auth']) == true) {
       delete config.headers['auth'];
       const message = '缺少凭证,请重新登录!';
-      if (router.currentRoute.value.path != '/login') {
-        localStorage.clear();
+      localStorage.clear();
+      let deviceid = localStorage.getItem('deviceid');
+      if (deviceid && router.currentRoute.value.path != '/login/qrcode') {
+        router.push('/login/qrcode');
+      }
+      if (deviceid == undefined && router.currentRoute.value.path != '/login') {
         router.push('/login');
       }
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 });
@@ -58,8 +62,12 @@ service.interceptors.response.use(
     const code = res.data.code;
     const message = res.data.message;
     if (code === 401) {
-      if (router.currentRoute.value.path != '/login') {
-        localStorage.clear();
+      localStorage.clear();
+      let deviceid = localStorage.getItem('deviceid');
+      if (deviceid && router.currentRoute.value.path != '/login/qrcode') {
+        router.push('/login/qrcode');
+      }
+      if (deviceid == undefined && router.currentRoute.value.path != '/login') {
         router.push('/login');
       }
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 });
@@ -75,8 +83,12 @@ service.interceptors.response.use(
     } else if (message.includes('timeout')) {
       message = '请求超时';
     } else if (response.status == 401) {
-      if (router.currentRoute.value.path != '/login') {
-        localStorage.clear();
+      localStorage.clear();
+      let deviceid = localStorage.getItem('deviceid');
+      if (deviceid && router.currentRoute.value.path != '/login/qrcode') {
+        router.push('/login/qrcode');
+      }
+      if (deviceid == undefined && router.currentRoute.value.path != '/login') {
         router.push('/login');
       }
       ElMessage({ message: message, type: 'error', duration: 5 * 1000 });

+ 23 - 8
src/views/gesture/index.vue

@@ -40,11 +40,17 @@ const { mySwiper, projectList, timerManager, device_info, listenWs } = toRefs(da
 /**
  * 清空定时任务
 */
-const getClearTimer = () => {
-  for (let key in timerManager.value) {
-    if (timerManager.value.hasOwnProperty(key)) {
-      clearInterval(timerManager.value[key])
-      timerManager.value[key] = null;
+const getClearTimer = (data?: any) => {
+  if (data) {
+    //清除指定
+    clearInterval(timerManager.value[data])
+    timerManager.value[data] = null;
+  } else {
+    for (let key in timerManager.value) {
+      if (timerManager.value.hasOwnProperty(key)) {
+        clearInterval(timerManager.value[key])
+        timerManager.value[key] = null;
+      }
     }
   }
 };
@@ -204,6 +210,14 @@ onBeforeMount(() => {
       listenWs.value = true;
       let deviceid = localStorage.getItem("deviceid");
       startDevice({ deviceid: deviceid })
+      timerManager.value.deviceid = setInterval(() => {
+        if (device_info.value.handcontroller_id == undefined) {
+          proxy?.$modal.msgWarning(`获取项目信息失败,正尝试重新获取,请稍等!`)
+          startDevice({ deviceid: deviceid })
+        } else {
+          getClearTimer("deviceid");
+        }
+      }, 10000)
     }
     if (listenWs.value == false) {
       return false;
@@ -211,9 +225,11 @@ onBeforeMount(() => {
     //接收参数
     if (e?.device_info) {
       console.log("222", e)
-      device_info.value = e.device_info
+      getClearTimer("deviceid");
+      device_info.value = e.device_info;
       let handcontroller_id = device_info.value.handcontroller_id;
-      startHand(handcontroller_id)
+      startHand(handcontroller_id);
+      getTips();
     }
     //左滑动
     if (e?.data?.result == "next_item") {
@@ -238,7 +254,6 @@ onBeforeMount(() => {
 })
 onMounted(() => {
   getInitExam();
-  getTips();
 })
 onBeforeUnmount(() => {
   listenWs.value = false;

+ 9 - 1
src/views/login/qrcode.vue

@@ -107,7 +107,15 @@ const getMobile = () => {
 }
 
 onMounted(() => {
-  getHandWs();
+  let token = localStorage.getItem("token");
+  let deviceid = localStorage.getItem("deviceid");
+  if (token && deviceid) {
+    //跳转
+    router.push({ path: '/gesture' });
+    getUserInfo();
+  } else {
+    getHandWs();
+  }
 })
 
 onBeforeUnmount(() => {

+ 4 - 3
src/views/train/multiple.vue

@@ -11,7 +11,7 @@
       <div class="testBox"
         :class="{ 'testBox1': styleType == 1, 'testBox2': styleType == 2, 'testBox3': styleType == 3 }">
         <div class="ul"
-          :class="{ 'overlap': (examState == 43 && time.ready) || [42].includes(examState) || (showTestAgain && ![41].includes(examState)), 'ready': [41].includes(examState), 'hands': parameter.handcontroller }"
+          :class="{ 'overlap': (examState == 43 && time.ready) || [42].includes(examState) || (showTestAgain && ![41].includes(examState)), 'ready': [41].includes(examState), 'hands': parameter.gesture }"
           v-for="(items, indexs) in testListArr " :key="indexs">
           <MultipleItem :ref="(el: any) => { multipleItemRef(el, item.itemNumber, item.area) }"
             v-for="(item, index) in items" :query="parameter" :area="item.area" :key="index" @returnData="returnData"
@@ -616,6 +616,7 @@ const initHand = () => {
         timerManager.value.exitTimer = setInterval(() => {
           time.value.exit--;
           console.log("取消倒计时", time.value.exit)
+          proxy?.$modal.msgWarning(`取消倒计时:${time.value.exit}`)
           if (time.value.exit == 0) {
             exit.value = 0;
             getClearTimer("exitTimer");
@@ -1073,7 +1074,7 @@ $waiPadding: 6.51rem;
           top: -1.5vw;
           left: 50%;
           margin-left: -1vw;
-          background-image: url("@/assets/images/home/test_icon.png");
+          background-image: url("@/assets/images/test/yuan.png");
           background-position: center;
           background-repeat: no-repeat;
           background-size: 100% 100%;
@@ -1328,7 +1329,7 @@ $waiPadding: 6.51rem;
           top: -1.3vw;
           left: 50%;
           margin-left: -1vw;
-          background-image: url("@/assets/images/home/test_icon.png");
+          background-image: url("@/assets/images/test/yuan.png");
           background-position: center;
           background-repeat: no-repeat;
           background-size: 100% 100%;

+ 2 - 1
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" />
@@ -753,6 +753,7 @@ const initHand = () => {
         timerManager.value.exitTimer = setInterval(() => {
           time.value.exit--;
           console.log("取消倒计时", time.value.exit)
+          proxy?.$modal.msgWarning(`取消倒计时:${time.value.exit}`)
           if (time.value.exit == 0) {
             exit.value = 0;
             getClearTimer("exitTimer");