li.shaoyi il y a 2 ans
Parent
commit
1e0aac1e4d

+ 8 - 0
src/business/login/index.ts

@@ -129,6 +129,14 @@ export function useLogin(persist = false) {
             localStorage.setItem('app_loginId', formData.userName) // 记住登录ID
             await loadUserData()
             eventBus.$emit('LoginNotify') // 登录成功通知
+        } catch (err) {
+            // 登录失败断开所有链路
+            stopCheckToken()
+            tradeSocket.close()
+            tradeV2Socket.close()
+            quoteSocket.close()
+            timerTask.clearAll()
+            return Promise.reject(err)
         } finally {
             logining.value = false
         }

+ 3 - 1
src/filters/index.ts

@@ -161,7 +161,9 @@ export function parsePercent(value = 0, decimal = 2) {
  * @returns 
  */
 export function round(value: number, precision = 2) {
-    return Math.round(+(value + 'e' + precision)) / Math.pow(10, precision)
+    const power = Math.pow(10, precision)
+    const roundedValue = ~~(value * power)
+    return roundedValue / power
 }
 
 /**

+ 6 - 7
src/packages/gcszt/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/gcszt/router/index.ts

@@ -308,10 +308,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 6 - 7
src/packages/gstj/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/gstj/router/index.ts

@@ -343,10 +343,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 6 - 7
src/packages/mobile/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 6 - 20
src/packages/mobile/components/layouts/home/index.vue

@@ -34,7 +34,7 @@ const props = defineProps({
   iosUpdateUrl: String
 })
 
-const { route, routerTo, getGlobalUrlParams, setGlobalUrlParams } = useNavigation()
+const { route, routerTo } = useNavigation()
 const { userLogin } = useLogin()
 const loginStore = useLoginStore()
 const cssTransition = shallowRef(true) // 是否使用css动画
@@ -44,18 +44,13 @@ const tabIndex = computed(() => props.tabs.findIndex((e) => e.name === route.nam
 
 const onTabClick = (index: number) => {
   const { name } = props.tabs[index]
-  cssTransition.value = false
-
-  if (name === 'home-index' || loginStore.token) {
-    currentTab.value = index
+  if (index === 0 || loginStore.token) {
     routerTo(name, true)
   } else {
     fullloading((hideLoading) => {
       userLogin(true).then(() => {
-        currentTab.value = index
         routerTo(name, true)
       }).catch(() => {
-        cssTransition.value = true
         routerTo('user-login')
       }).finally(() => {
         hideLoading()
@@ -75,12 +70,9 @@ const tradeServerReconnectSuccessNotify = eventBus.$on('TradeServerReconnectSucc
 })
 
 watch(() => route.name, () => {
-  const params = getGlobalUrlParams()
-  if (params.tabIndex > -1) {
-    onTabClick(params.tabIndex)
-  } else {
-    // 如果参数不是 tabIndex ,需要保留到下一个路由
-    setGlobalUrlParams(params)
+  if (tabIndex.value > -1) {
+    cssTransition.value = false
+    currentTab.value = tabIndex.value
   }
   nextTick(() => {
     cssTransition.value = true
@@ -88,13 +80,7 @@ watch(() => route.name, () => {
 })
 
 onMounted(() => {
-  // 页面初始化时判断底部导航位置
-  const params = getGlobalUrlParams()
-  if (params.tabIndex > -1) {
-    onTabClick(params.tabIndex)
-  } else {
-    currentTab.value = tabIndex.value
-  }
+  currentTab.value = tabIndex.value
 })
 
 onUnmounted(() => {

+ 14 - 5
src/packages/mobile/router/animateRouter.ts

@@ -152,14 +152,23 @@ export default new (class {
                 }
             } else {
                 if (goStep.value < 0) {
-                    const start = historyRoutes.value.length + goStep.value
-                    if (start) {
-                        historyRoutes.value.splice(start)
+                    const i = historyRoutes.value.length + goStep.value
+                    if (i > 0) {
+                        const n = historyRoutes.value.length - i
+                        excludeViews.value = historyRoutes.value.map((e) => e.name).slice(-n) // 返回数组最后位置开始的n个元素
+                        historyRoutes.value.splice(i)
                     }
                 }
-                // 忽略重定向的页面
+                // 如有存在重定向的页面,判断路由前进还是后退
                 if (route.redirectedFrom) {
-                    transitionName.value = 'route-in' // 前进动画
+                    if (goStep.value < 0) {
+                        const index = historyRoutes.value.length - 1
+                        const lastIndex = index > -1 ? index : 0
+                        historyRoutes.value[lastIndex] = newRoute // 更新最后一条记录
+                        transitionName.value = 'route-out' //后退动画
+                    } else {
+                        transitionName.value = 'route-in' // 前进动画
+                    }
                 } else {
                     historyRoutes.value.push(newRoute)
                     if (historyRoutes.value.length > 1) {

+ 12 - 4
src/packages/mobile/router/index.ts

@@ -508,10 +508,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 1 - 5
src/packages/mobile/router/navigation.ts

@@ -70,18 +70,14 @@ export function useNavigation() {
     // }
 
     // 返回主页
-    const backHome = (isLogout = false) => {
+    const backHome = () => {
         const state = animateRouter.getState()
         const delta = state.historyRoutes.length - 1
-        const params = { tabIndex: 0, isLogout }
-
         if (delta > 0) {
-            setGlobalUrlParams(params)
             router.go(-delta)
         } else {
             const page = state.historyRoutes[0]
             if (page?.name !== 'home-index') {
-                setGlobalUrlParams(params)
                 router.replace({ name: 'home-index' })
             }
         }

+ 6 - 7
src/packages/qdhs/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/qdhs/router/index.ts

@@ -313,10 +313,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 6 - 7
src/packages/qxst/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/qxst/router/index.ts

@@ -301,10 +301,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 6 - 7
src/packages/sbyj/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/sbyj/router/index.ts

@@ -315,10 +315,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-market',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 8 - 16
src/packages/sbyj/views/home/index.vue

@@ -24,7 +24,7 @@ import AppTabbar from '@mobile/components/base/tabbar/index.vue'
 import AppUpdater from '@mobile/components/base/updater/index.vue'
 import RouterTransition from '@mobile/components/base/router-transition/index.vue'
 
-const { route, routerTo, getGlobalUrlParams, setGlobalUrlParams } = useNavigation()
+const { route, routerTo } = useNavigation()
 const { userLogin } = useLogin()
 const loginStore = useLoginStore()
 const cssTransition = shallowRef(true) // 是否使用css动画
@@ -61,18 +61,13 @@ const tabList: Tabbar[] = [
 
 const onTabClick = (index: number) => {
   const { name } = tabList[index]
-  cssTransition.value = false
-
   if (name !== 'home-mine' || loginStore.token) {
-    currentTab.value = index
     routerTo(name, true)
   } else {
     fullloading((hideLoading) => {
       userLogin(true).then(() => {
-        currentTab.value = index
         routerTo(name, true)
       }).catch(() => {
-        cssTransition.value = true
         routerTo('user-login')
       }).finally(() => {
         hideLoading()
@@ -81,22 +76,19 @@ const onTabClick = (index: number) => {
   }
 }
 
-onMounted(() => {
-  currentTab.value = tabIndex.value
-})
-
 watch(() => route.name, () => {
-  const params = getGlobalUrlParams()
-  if (params.tabIndex > -1) {
-    onTabClick(params.tabIndex)
-  } else {
-    // 如果参数不是 tabIndex ,需要保留到下一个路由
-    setGlobalUrlParams(params)
+  if (tabIndex.value > -1) {
+    cssTransition.value = false
+    currentTab.value = tabIndex.value
   }
   nextTick(() => {
     cssTransition.value = true
   })
 })
+
+onMounted(() => {
+  currentTab.value = tabIndex.value
+})
 </script>
 
 <style lang="less">

+ 1 - 0
src/packages/sbyj/views/user/login/index.less

@@ -2,6 +2,7 @@
     display: flex;
     flex-direction: column;
     background: #fff;
+    overflow: hidden;
 
     &::before {
         content: '';

+ 6 - 7
src/packages/tc/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/tc/router/index.ts

@@ -343,10 +343,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 6 - 7
src/packages/tjmd/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/tjmd/router/index.ts

@@ -345,10 +345,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {

+ 6 - 7
src/packages/zrwyt/App.vue

@@ -13,19 +13,18 @@ const { backHome } = useNavigation()
 
 // 接收用户登出通知
 eventBus.$on('LogoutNotify', (msg) => {
-  // ---待优化---
-  // 登出后应该回退到首页,如果回退后非首页,会导致路由拦截而跳转到登录页面,此时因为 tabIndex = 0 的问题,登录页被 replace 成首页,导致路由还能继续后退
-  // 临时解决方案是先退回首页后再进行登出操作
-  backHome()
-  setTimeout(() => {
-    userLogout()
+  userLogout(() => {
     if (msg) {
       dialog({
         message: msg as string,
         confirmButtonText: '确定'
+      }).then(() => {
+        backHome()
       })
+    } else {
+      backHome()
     }
-  }, 0)
+  })
 })
 
 // 接收风控通知

+ 12 - 4
src/packages/zrwyt/router/index.ts

@@ -365,10 +365,18 @@ router.beforeEach((to, from, next) => {
     if (to.meta.ignoreAuth || loginStore.token) {
       next()
     } else {
-      next({
-        name: 'user-login',
-        query: { redirect: to.fullPath },
-      })
+      if (to.matched.some((e) => e.name === 'home')) {
+        // 如果是主页导航页面,强制跳转到首页
+        next({
+          name: 'home-index',
+          replace: true,
+        })
+      } else {
+        next({
+          name: 'user-login',
+          query: { redirect: to.fullPath },
+        })
+      }
     }
   } else {
     if (to.name === 'boot' || to.name === 'user-login') {