Kaynağa Gözat

优化登录状态处理,修复 pushRecordId 逻辑

yuanmingze 1 hafta önce
ebeveyn
işleme
712c55df53

+ 2 - 1
src/services/request/index.ts

@@ -103,12 +103,13 @@ const handleNetworkError = (response: AxiosResponse, silent?: boolean) => {
     showToast('您的登录状态已失效,请重新登录')
     abortAllRequests()
 
+    const pushRecordId = userStore.pushRecordId
     // 🔁 跳转到登录页
     setTimeout(() => {
       router.replace({
         path: '/login',
         query: {
-          pushRecordId: userStore.pushRecordId,
+          pushRecordId: pushRecordId,
         },
       })
       useUserStoreWithOut().LogOut()

+ 0 - 1
src/stores/modules/user.ts

@@ -28,7 +28,6 @@ export const useUserStore = defineStore('user', {
     },
     LogOut() {
       this.access_token = ''
-      this.pushRecordId = ''
       this.needFaceId = false
     },
   },

+ 11 - 13
src/views/login/index.vue

@@ -365,11 +365,9 @@ const resetLoginState = () => {
   formData.mobile = ''
   formData.code = ''
   agree.value = false
-
   isCounting.value = false
   countDown.value = 60
   sending.value = false
-
   showDialog.value = false
   loginDialog.value = false
   changePasswordDialog.value = false
@@ -393,19 +391,19 @@ onActivated(() => {
 })
 
 onBeforeMount(() => {
-  userStore.LogOut()
   registerUrlParams.value.returnUrl = `${location.origin}/h5${route.fullPath}`
-  const pushRecordId = route?.query.pushRecordId || ''
-  console.log('pushRecordId', pushRecordId)
-
-  if (pushRecordId) {
-    sendEtsSms.pushRecordId = pushRecordId as string
-    userStore.setPushRecordId(pushRecordId as string)
-    formData.pushRecordId = pushRecordId as string
-    getPubName()
-  } else {
-    showToast('登录链接存在不完整或者输入错误,请重新复制链接登录')
+  const pushRecordId = route.query.pushRecordId
+  if (!pushRecordId) {
+    userStore.setPushRecordId('')
+    formData.pushRecordId = ''
+    sendEtsSms.pushRecordId = ''
+    showToast('登录链接存在不完整或者输入错误')
+    return
   }
+  userStore.setPushRecordId(pushRecordId as string)
+  sendEtsSms.pushRecordId = pushRecordId as string
+  formData.pushRecordId = pushRecordId as string
+  getPubName()
 })
 </script>