Forráskód Böngészése

fix: 修复未登录状态下API返回10001导致首页死循环的问题

- HTTP拦截器仅在曾持有token(过期/失效)时才reLaunch回首页,未登录时不跳转
- refresh()未登录时API失败静默处理,不弹错误modal

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 1 napja
szülő
commit
d64e469b20
2 módosított fájl, 12 hozzáadás és 5 törlés
  1. 4 0
      charge-front/src/pages/map/map.vue
  2. 8 5
      charge-front/src/utils/http.ts

+ 4 - 0
charge-front/src/pages/map/map.vue

@@ -516,6 +516,10 @@ const refresh = () => {
       console.log(err);
       uni.hideLoading();
       loading.value = false;
+      if (!token.value) {
+        ready.value = true;
+        return;
+      }
       uni.showModal({
         content: `${err.errMsg},请重试`,
       });

+ 8 - 5
charge-front/src/utils/http.ts

@@ -75,12 +75,15 @@ class Http {
           //   });
           // }
           if ([21005, 21000, 10001].includes(Number(res.code))) {
+            const hasToken = getApp<any>().globalData.token;
             clearToken();
-            setTimeout(() => {
-              uni.reLaunch({
-                url: "/pages/map/map",
-              });
-            }, 1500);
+            if (hasToken) {
+              setTimeout(() => {
+                uni.reLaunch({
+                  url: "/pages/map/map",
+                });
+              }, 1500);
+            }
             throw {
               errMsg: "请重新登录",
             };