perf: storage tags

This commit is contained in:
lrl 2021-11-27 19:04:14 +08:00
parent 6d3a8c5a88
commit be3a8a6949
3 changed files with 56 additions and 43 deletions

View File

@ -17,6 +17,7 @@ import fullScreen from "/@/assets/svg/full_screen.svg";
import exitScreen from "/@/assets/svg/exit_screen.svg";
import { deviceDetection } from "/@/utils/deviceDetection";
import { useSettingStoreHook } from "/@/store/modules/settings";
import { useMultiTagsStore } from "/@/store/modules/multiTags";
import navbar from "./components/navbar.vue";
import tag from "./components/tag/index.vue";
@ -32,7 +33,10 @@ const instance = getCurrentInstance().appContext.app.config.globalProperties;
// serverConfig.jsonstorage
const layout = computed(() => {
//
if (!instance.$storage.tags || instance.$storage.tags.length === 0) {
if (
useMultiTagsStore().multiTagsCache &&
(!instance.$storage.tags || instance.$storage.tags.length === 0)
) {
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
instance.$storage.tags = routerArrays;
}

View File

@ -231,9 +231,10 @@ router.beforeEach((to, _from, next) => {
// 刷新
if (usePermissionStoreHook().wholeRoutes.length === 0)
initRouter(name.username).then((router: Router) => {
useMultiTagsStoreHook().getMultiTagsCache
? router.push(to.path)
: router.push("/");
if (!useMultiTagsStoreHook().getMultiTagsCache) {
return router.push("/");
}
router.push(to.path);
// 刷新页面更新标签栏与页面路由匹配
const localRoutes = storageLocal.getItem("responsive-tags");
const optionsRoutes = router.options?.routes;

View File

@ -3,45 +3,53 @@ import { App } from "vue";
import Storage from "responsive-storage";
export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
app.use(Storage, {
// 默认显示首页tag
tags: {
type: Array,
default: Storage.getData(undefined, "tags") ?? [
{
path: "/welcome",
parentPath: "/",
meta: {
title: "message.hshome",
i18n: true,
icon: "HomeFilled",
showLink: true
const configObj = Object.assign(
{
// 国际化 默认中文zh
locale: {
type: Object,
default: Storage.getData(undefined, "locale") ?? {
locale: config.Locale ?? "zh"
}
},
// layout模式以及主题
layout: {
type: Object,
default: Storage.getData(undefined, "layout") ?? {
layout: config.Layout ?? "vertical",
theme: config.Theme ?? "default"
}
},
sets: {
type: Object,
default: Storage.getData(undefined, "sets") ?? {
grey: config.Grey ?? false,
weak: config.Weak ?? false,
hideTabs: config.HideTabs ?? false
}
}
},
config.MultiTagsCache
? {
// 默认显示首页tag
tags: {
type: Array,
default: Storage.getData(undefined, "tags") ?? [
{
path: "/welcome",
parentPath: "/",
meta: {
title: "message.hshome",
i18n: true,
icon: "HomeFilled",
showLink: true
}
}
]
}
}
]
},
// 国际化 默认中文zh
locale: {
type: Object,
default: Storage.getData(undefined, "locale") ?? {
locale: config.Locale ?? "zh"
}
},
// layout模式以及主题
layout: {
type: Object,
default: Storage.getData(undefined, "layout") ?? {
layout: config.Layout ?? "vertical",
theme: config.Theme ?? "default"
}
},
sets: {
type: Object,
default: Storage.getData(undefined, "sets") ?? {
grey: config.Grey ?? false,
weak: config.Weak ?? false,
hideTabs: config.HideTabs ?? false
}
}
});
: {}
);
app.use(Storage, configObj);
};