|
|
@@ -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()
|
|
|
}
|
|
|
|