li.shaoyi hace 2 años
padre
commit
42561fa377
Se han modificado 2 ficheros con 21 adiciones y 9 borrados
  1. 12 6
      src/hooks/navigation/index.ts
  2. 9 3
      src/packages/mobile/App.vue

+ 12 - 6
src/hooks/navigation/index.ts

@@ -1,3 +1,4 @@
+import { watch } from 'vue'
 import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
 import animateRouter from '@mobile/router/animateRouter'
 
@@ -6,8 +7,8 @@ export function useNavigation() {
     const router = useRouter()
 
     // 缓存全局Url参数
-    const setGlobalUrlParams = <T extends object>(params: T) => {
-        sessionStorage.setItem('globalUrlParams', JSON.stringify(params))
+    const setGlobalUrlParams = <T extends object>(params?: T) => {
+        sessionStorage.setItem('globalUrlParams', JSON.stringify(params ?? {}))
     }
 
     // 是否有历史页面
@@ -50,7 +51,7 @@ export function useNavigation() {
 
     //     if (total > -1) {
     //         if (index > -1) {
-    //             setGlobalUrlParams(params ?? {})
+    //             setGlobalUrlParams(params)
     //             const delta = total - index
     //             if (delta > 0) {
     //                 router.go(-delta)
@@ -64,18 +65,23 @@ export function useNavigation() {
     // }
 
     // 返回主页
-    const backHomePage = <T extends object>(params?: T) => {
+    const backHomePage = <T extends object>(params?: T, callback?: () => void) => {
         const { state } = animateRouter
         const delta = state.history.length - 1
-        setGlobalUrlParams(params ?? {})
+        setGlobalUrlParams(params)
         if (delta) {
             router.go(-delta)
+            watch(() => route.path, () => {
+                callback && callback()
+            })
+        } else {
+            callback && callback()
         }
     }
 
     // 返回上个页面
     const routerBack = <T extends object>(params?: T) => {
-        setGlobalUrlParams(params ?? {})
+        setGlobalUrlParams(params)
         router.back()
     }
 

+ 9 - 3
src/packages/mobile/App.vue

@@ -15,9 +15,10 @@ const isRouterAlive = shallowRef(true) // 用于页面重新渲染
 
 const quit = (showLogin = false) => {
   isRouterAlive.value = false
-  backHomePage({ tabName: 'home', showLogin })
-  nextTick(() => {
-    isRouterAlive.value = true
+  backHomePage({ tabName: 'home', showLogin }, () => {
+    nextTick(() => {
+      isRouterAlive.value = true
+    })
   })
 }
 
@@ -27,8 +28,13 @@ eventBus.$on('LogoutNotify', (msg) => {
     if (msg) {
       dialog({
         message: msg as string,
+        showCancelButton: true,
+        cancelButtonText: '退出',
+        confirmButtonText: '重新登录'
       }).then(() => {
         quit(true)
+      }).catch(() => {
+        quit()
       })
     } else {
       quit()