diff --git a/src/layout/components/setting/index.vue b/src/layout/components/setting/index.vue index 37ee7a8ec..dffdc64ce 100644 --- a/src/layout/components/setting/index.vue +++ b/src/layout/components/setting/index.vue @@ -17,6 +17,7 @@ import { debounce } from "/@/utils/debounce"; import { themeColorsType } from "../../types"; import { useAppStoreHook } from "/@/store/modules/app"; import { storageLocal, storageSession } from "/@/utils/storage"; +import { useMultiTagsStoreHook } from "/@/store/modules/multiTags"; import { toggleTheme } from "@zougt/vite-plugin-theme-preprocessor/dist/browser-utils"; const router = useRouter(); @@ -135,6 +136,18 @@ function onReset() { storageSession.clear(); toggleClass(false, "html-grey", document.querySelector("html")); toggleClass(false, "html-weakness", document.querySelector("html")); + useMultiTagsStoreHook().handleTags("equal", [ + { + path: "/welcome", + parentPath: "/", + meta: { + title: "message.hshome", + icon: "el-icon-s-home", + i18n: true, + showLink: true + } + } + ]); router.push("/login"); } diff --git a/src/layout/components/tag/index.vue b/src/layout/components/tag/index.vue index 9c852a5a0..9daf2743d 100644 --- a/src/layout/components/tag/index.vue +++ b/src/layout/components/tag/index.vue @@ -255,18 +255,6 @@ function deleteDynamicTag(obj: any, current: any, tag?: string) { startIndex, length }); - useMultiTagsStoreHook().handleTags("equal", [ - { - path: "/welcome", - parentPath: "/", - meta: { - title: "message.hshome", - icon: "el-icon-s-home", - i18n: true, - showLink: true - } - } - ]); } }; diff --git a/src/router/index.ts b/src/router/index.ts index 5e37b678b..dbc0fd870 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,6 +12,7 @@ import NProgress from "/@/utils/progress"; import { useTimeoutFn } from "@vueuse/core"; import { storageSession, storageLocal } from "/@/utils/storage"; import { usePermissionStoreHook } from "/@/store/modules/permission"; +import { useMultiTagsStoreHook } from "/@/store/modules/multiTags"; // 静态路由 import homeRouter from "./modules/home"; @@ -230,7 +231,9 @@ router.beforeEach((to, _from, next) => { // 刷新 if (usePermissionStoreHook().wholeRoutes.length === 0) initRouter(name.username).then((router: Router) => { - router.push(to.path); + useMultiTagsStoreHook().getMultiTagsCache + ? router.push(to.path) + : router.push("/"); // 刷新页面更新标签栏与页面路由匹配 const localRoutes = storageLocal.getItem("responsive-tags"); const optionsRoutes = router.options?.routes; diff --git a/src/store/modules/multiTags.ts b/src/store/modules/multiTags.ts index ed31e7272..c6ee7d5e6 100644 --- a/src/store/modules/multiTags.ts +++ b/src/store/modules/multiTags.ts @@ -2,23 +2,26 @@ import { defineStore } from "pinia"; import { store } from "/@/store"; import { getConfig } from "/@/config"; import { positionType } from "./types"; +import { storageLocal } from "/@/utils/storage"; export const useMultiTagsStore = defineStore({ id: "pure-multiTags", state: () => ({ // 存储标签页信息(路由信息) - multiTags: [ - { - path: "/welcome", - parentPath: "/", - meta: { - title: "message.hshome", - icon: "el-icon-s-home", - i18n: true, - showLink: true - } - } - ], + multiTags: getConfig().MultiTagsCache + ? storageLocal.getItem("responsive-tags") + : [ + { + path: "/welcome", + parentPath: "/", + meta: { + title: "message.hshome", + icon: "el-icon-s-home", + i18n: true, + showLink: true + } + } + ], multiTagsCache: getConfig().MultiTagsCache }), getters: { @@ -27,6 +30,10 @@ export const useMultiTagsStore = defineStore({ } }, actions: { + tagsCache(multiTags) { + this.getMultiTagsCache && + storageLocal.setItem("responsive-tags", multiTags); + }, handleTags(mode: string, value?: T, position?: positionType): any { switch (mode) { case "equal": @@ -34,12 +41,15 @@ export const useMultiTagsStore = defineStore({ break; case "push": this.multiTags.push(value); + this.tagsCache(this.multiTags); break; case "splice": this.multiTags.splice(position?.startIndex, position?.length); + this.tagsCache(this.multiTags); + return this.multiTags; break; case "slice": - this.multiTags.slice(-1); + return this.multiTags.slice(-1); break; } }