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

View File

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

View File

@ -3,23 +3,8 @@ import { App } from "vue";
import Storage from "responsive-storage"; import Storage from "responsive-storage";
export const injectResponsiveStorage = (app: App, config: ServerConfigs) => { export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
app.use(Storage, { const configObj = Object.assign(
// 默认显示首页tag
tags: {
type: Array,
default: Storage.getData(undefined, "tags") ?? [
{ {
path: "/welcome",
parentPath: "/",
meta: {
title: "message.hshome",
i18n: true,
icon: "HomeFilled",
showLink: true
}
}
]
},
// 国际化 默认中文zh // 国际化 默认中文zh
locale: { locale: {
type: Object, type: Object,
@ -43,5 +28,28 @@ export const injectResponsiveStorage = (app: App, config: ServerConfigs) => {
hideTabs: config.HideTabs ?? 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
}
}
]
}
}
: {}
);
app.use(Storage, configObj);
}; };