diff --git a/src/GlobalModal.tsx b/src/GlobalModal.tsx index f39aeb2..303062b 100644 --- a/src/GlobalModal.tsx +++ b/src/GlobalModal.tsx @@ -30,7 +30,7 @@ export default defineComponent(() => {
{ - router.path = '' + router.back() }} >
)} @@ -53,7 +53,7 @@ export default defineComponent(() => { (router.path === 'global-adder' ? 'top-6 right-4' : 'top-2 right-2') } onClick={() => { - router.path = '' + router.back() }} > diff --git a/src/layout/grid/WidgetBlock.tsx b/src/layout/grid/WidgetBlock.tsx index dddfc6c..f21bef6 100644 --- a/src/layout/grid/WidgetBlock.tsx +++ b/src/layout/grid/WidgetBlock.tsx @@ -32,7 +32,7 @@ export default defineComponent({ menu.open(props.block) }} onClick={() => { - router.path = `widget-${props.block.name}` + router.go(`widget-${props.block.name}`) }} > diff --git a/src/layout/grid/index.tsx b/src/layout/grid/index.tsx index 9972367..82599b3 100644 --- a/src/layout/grid/index.tsx +++ b/src/layout/grid/index.tsx @@ -67,7 +67,7 @@ export default defineComponent(() => { class="w-full h-full overflow-hidden rounded-[calc(var(--block-radius)_*_var(--block-size))] bg-white/60 backdrop-blur flex justify-center items-center cursor-pointer hover:scale-105 transition-all" onClick={() => { if (layout.state.content[layout.state.current].pages[layout.state.currentPage]) { - router.path = 'global-adder' + router.go('global-adder') } else { globalToast.warning('请先添加页面') } diff --git a/src/layout/header/search/SearchConfig.tsx b/src/layout/header/search/SearchConfig.tsx index d8cc7d1..736fa07 100644 --- a/src/layout/header/search/SearchConfig.tsx +++ b/src/layout/header/search/SearchConfig.tsx @@ -53,7 +53,7 @@ export default defineComponent({ class="w-full h-10 rounded-lg overflow-hidden flex justify-center items-center p-2 transition-all cursor-pointer bg-white/40 hover:bg-white/60" onClick={() => { search.showSearchConfig = false - router.path = 'global-search' + router.go('global-search') }} > diff --git a/src/layout/sider/index.tsx b/src/layout/sider/index.tsx index aec843e..d79f873 100644 --- a/src/layout/sider/index.tsx +++ b/src/layout/sider/index.tsx @@ -114,16 +114,16 @@ export default defineComponent(() => { name="px-headset" label="反馈" onClick={() => { - router.path = 'settings-fallback' + router.go('settings-fallback') }} />
{ if (user.isLogin) { - router.path = 'settings-user' + router.go('settings-user') } else { - router.path = 'global-login' + router.go('global-login') } }} > diff --git a/src/settings/SettingsButton.tsx b/src/settings/SettingsButton.tsx index 7756199..3d7dbe4 100644 --- a/src/settings/SettingsButton.tsx +++ b/src/settings/SettingsButton.tsx @@ -10,7 +10,7 @@ export default defineComponent(() => { class="absolute left-10 bottom-8 p-1 z-10 flex justify-center items-center cursor-pointer rounded-lg hover:bg-black/20 transition-all" style="filter: drop-shadow(0 0 4px rgba(0,0,0,0.2))" onClick={() => { - router.path = 'settings-background' + router.go('settings-background') }} > diff --git a/src/settings/SettingsOverlay.tsx b/src/settings/SettingsOverlay.tsx index bb6efca..c601cea 100644 --- a/src/settings/SettingsOverlay.tsx +++ b/src/settings/SettingsOverlay.tsx @@ -25,7 +25,7 @@ const SettingsTab = defineComponent({ (router.path === props.path ? 'bg-white/70 font-bold shadow-lg' : '') } onClick={() => { - router.path = props.path as any + router.go(props.path as any) }} > {props.label} @@ -44,7 +44,7 @@ export default defineComponent(() => {
{ - router.path = '' + router.back() }} >
)} @@ -52,45 +52,41 @@ export default defineComponent(() => { {show.value && (
- { - router.path.startsWith('settings-') ? - <> -
-
{ - router.path = 'settings-user' - }} - > -
- -
+ {router.path.startsWith('settings-') ? ( + <> +
+
{ + router.go('settings-user') + }} + > +
+
- - - - - - - - -
- - - : - router.path.startsWith('s2') ? - <> -
-
- - : '' - - } - + + + + + + + + + +
+ + + ) : router.path.startsWith('s2') ? ( + <> +
+ + ) : ( + '' + )}
)} diff --git a/src/useRouterStore.ts b/src/useRouterStore.ts index eb3124d..c9b5501 100644 --- a/src/useRouterStore.ts +++ b/src/useRouterStore.ts @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import { ref } from 'vue' +import { computed, ref, watch } from 'vue' export type GlobalStr = 'search' | 'block' | 'adder' | 'login' export type SettingStr = @@ -16,8 +16,24 @@ export type SettingStr = export type RouteStr = '' | `widget-${string}` | `global-${GlobalStr}` | `settings-${SettingStr}` export default defineStore('router', () => { - const path = ref('') + const his = ref([]) + const go = (p: RouteStr) => { + his.value.unshift(p) + if (his.value.length > 10) { + his.value.pop() + } + } + const back = () => { + if (his.value.length > 0) { + his.value.shift() + } + } + const path = computed(() => { + return his.value[0] || '' + }) return { - path + path, + go, + back } }) diff --git a/src/user/LoginModal.tsx b/src/user/LoginModal.tsx index 8abe717..5702e47 100644 --- a/src/user/LoginModal.tsx +++ b/src/user/LoginModal.tsx @@ -17,7 +17,7 @@ export default defineComponent(() => {
{ - router.path = '' + router.back() }} >
)} @@ -45,7 +45,7 @@ export default defineComponent(() => { returnType: 'text' }).then((res) => { user.token = res - router.path = '' + router.go('') }) }} > diff --git a/src/user/UserPage.tsx b/src/user/UserPage.tsx index 335d157..6766d4a 100644 --- a/src/user/UserPage.tsx +++ b/src/user/UserPage.tsx @@ -43,7 +43,7 @@ export default defineComponent(() => { <>