+
我的
@@ -45,8 +45,6 @@ let state = $ref({
\ No newline at end of file
diff --git a/src/router.ts b/src/router.ts
index b200c621..e1fbc6c6 100644
--- a/src/router.ts
+++ b/src/router.ts
@@ -5,15 +5,18 @@ import Dict from '@/pages/pc/dict/index.vue'
import Mobile from '@/pages/mobile/index.vue'
import MobilePractice from '@/pages/mobile/practice/index.vue'
import Test from "@/pages/test/test.vue";
+import {useRuntimeStore} from "@/stores/runtime.ts";
+import DictDetail from "@/pages/mobile/DictDetail.vue";
+import SetDictPlan from "@/pages/mobile/SetDictPlan.vue";
-const routes: RouteRecordRaw[] = [
+export const routes: RouteRecordRaw[] = [
{path: '/pc/practice', component: Practice},
{path: '/pc/dict', component: Dict},
- {
- path: '/mobile', component: Mobile,
- // redirect:'/mobile/home',
- },
- {path: '/mobile-practice', component: MobilePractice,},
+
+ {path: '/mobile', component: Mobile,},
+ {path: '/mobile/practice', component: MobilePractice},
+ {path: '/mobile/dict-detail', component: DictDetail},
+ {path: '/mobile/set-dict-plan', component: SetDictPlan},
{path: '/test', component: Test},
{path: '/', redirect: '/pc/practice'},
]
@@ -21,6 +24,57 @@ const routes: RouteRecordRaw[] = [
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes,
+ scrollBehavior(to, from, savedPosition) {
+ // console.log('savedPosition', savedPosition)
+ if (savedPosition) {
+ return savedPosition
+ } else {
+ return {top: 0}
+ }
+ },
})
+router.beforeEach((to, from) => {
+ // console.log('beforeEach-to',to.path)
+ // console.log('beforeEach-from',from.path)
+ const runtimeStore = useRuntimeStore()
+
+ //footer下面的5个按钮,对跳不要用动画
+ let noAnimation = [
+ '/pc/practice',
+ '/pc/dict',
+ '/mobile',
+ '/'
+ ]
+ if (noAnimation.indexOf(from.path) !== -1 && noAnimation.indexOf(to.path) !== -1) {
+ return true
+ }
+
+ const toDepth = routes.findIndex(v => v.path === to.path)
+ const fromDepth = routes.findIndex(v => v.path === from.path)
+ // const fromDepth = routeDeep.indexOf(from.path)
+
+ if (toDepth > fromDepth) {
+ if (to.matched && to.matched.length) {
+ let toComponentName = to.matched[0].components.default.name
+ runtimeStore.updateExcludeRoutes({type: 'remove', value: toComponentName})
+ // console.log('to', toComponentName)
+ // console.log('前进')
+ // console.log('删除', toComponentName)
+ }
+
+ } else {
+ if (from.matched && from.matched.length) {
+ let fromComponentName = from.matched[0].components.default.name
+ runtimeStore.updateExcludeRoutes({type: 'add', value: fromComponentName})
+ // console.log('后退')
+ // console.log('添加', fromComponentName)
+ }
+ }
+ // ...
+ // 返回 false 以取消导航
+ return true
+})
+
+
export default router
\ No newline at end of file
diff --git a/src/stores/base.ts b/src/stores/base.ts
index 23911b4e..233b444e 100644
--- a/src/stores/base.ts
+++ b/src/stores/base.ts
@@ -135,7 +135,7 @@ export const useBaseStore = defineStore('base', {
].includes(this.currentDict.type)
},
currentDict(): Dict {
- return this.myDictList[this.current.index]
+ return this.myDictList[this.current.index]??{}
},
chapter(state: BaseState): Word[] {
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
diff --git a/src/stores/runtime.ts b/src/stores/runtime.ts
index c961a1f1..422d94cf 100644
--- a/src/stores/runtime.ts
+++ b/src/stores/runtime.ts
@@ -8,6 +8,7 @@ export interface RuntimeState {
editDict: Dict
showDictModal: boolean
showSettingModal: boolean
+ excludeRoutes: any[]
}
export const useRuntimeStore = defineStore('runtime', {
@@ -18,6 +19,22 @@ export const useRuntimeStore = defineStore('runtime', {
editDict: cloneDeep(DefaultDict),
showDictModal: false,
showSettingModal: false,
+ excludeRoutes: [],
}
},
+ actions: {
+ updateExcludeRoutes(val: any) {
+ if (val.type === 'add') {
+ if (!this.excludeRoutes.find(v => v === val.value)) {
+ this.excludeRoutes.push(val.value)
+ }
+ } else {
+ let resIndex = this.excludeRoutes.findIndex(v => v === val.value)
+ if (resIndex !== -1) {
+ this.excludeRoutes.splice(resIndex, 1)
+ }
+ }
+ // console.log('store.excludeRoutes', this.excludeRoutes)
+ },
+ }
})
\ No newline at end of file