Procházet zdrojové kódy

feat:过期跳转锁,ib的loading

ljc před 1 měsícem
rodič
revize
d28cca3bb7
2 změnil soubory, kde provedl 33 přidání a 16 odebrání
  1. 8 4
      pages/ib/index.vue
  2. 25 12
      utils/request.js

+ 8 - 4
pages/ib/index.vue

@@ -390,7 +390,7 @@
         </uni-forms>
       </view>
     </cwg-popup>
-
+    <uni-loading v-if="loading" />
   </cwg-page-wrapper>
 </template>
 
@@ -407,6 +407,7 @@
   import { isAfterJuly28 } from '@/utils/dateUtils'
 
   const { t } = useI18n()
+  const loading = ref(false)
   const router = useRouter()
   const { Code } = config
   const { userInfo } = useUserStore()
@@ -949,10 +950,12 @@
     })
   }
 
-  onMounted(() => {
+  onMounted(async () => {
+    loading.value = true
     // 初始化数据
-    getIbData()
-    getPammManagerValid()
+    await getIbData()
+    await getPammManagerValid()
+    loading.value = false
   })
 
 </script>
@@ -1173,6 +1176,7 @@
   .mam-card {
     .add-mam-btn {
       display: flex;
+      background-color: var(--color-error);
       align-items: center;
       gap: 8rpx;
       height: px2rpx(32);

+ 25 - 12
utils/request.js

@@ -55,6 +55,9 @@ const requestInterceptor = (config) => {
   return config;
 };
 
+// 记录是否正在跳转登录页
+let isRedirectingToLogin = false;
+
 // 响应拦截器
 const responseInterceptor = (response, options = {}) => {
   const { data, statusCode } = response;
@@ -84,18 +87,28 @@ const responseInterceptor = (response, options = {}) => {
           code: 401,
         });
       }
-      // // 4. 提示并跳转登录页(默认逻辑)
-      uni.showToast({
-        title: "登录已过期,请重新登录",
-        icon: "none",
-        success: () => {
-          setTimeout(() => {
-            uni.reLaunch({
-              url: LOGIN_PAGE_PATH,
-            });
-          }, 1500);
-        },
-      });
+      
+      // 4. 提示并跳转登录页(防抖/防重复跳转处理)
+      if (!isRedirectingToLogin) {
+        isRedirectingToLogin = true;
+        uni.showToast({
+          title: "登录已过期,请重新登录",
+          icon: "none",
+        });
+        
+        setTimeout(() => {
+          uni.reLaunch({
+            url: LOGIN_PAGE_PATH,
+            success: () => {
+              isRedirectingToLogin = false;
+            },
+            fail: () => {
+              isRedirectingToLogin = false;
+            }
+          });
+        }, 1500);
+      }
+      
       return Promise.reject({
         ...data,
         code: 401,