mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-07 16:56:23 +08:00
feat(projects): 添加生产的主题配置缓存
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import type { RouteRecordNormalized, RouteLocationNormalizedLoaded } from 'vue-router';
|
||||
import { EnumStorageKey } from '@/enum';
|
||||
import { setLocal, getLocal } from '@/utils';
|
||||
|
||||
/**
|
||||
* 根据vue路由获取tab路由
|
||||
@@ -55,3 +57,30 @@ function hasFullPath(
|
||||
): route is RouteLocationNormalizedLoaded {
|
||||
return Boolean((route as RouteLocationNormalizedLoaded).fullPath);
|
||||
}
|
||||
|
||||
/** 缓存多页签数据 */
|
||||
export function setTabRoutes(data: GlobalTabRoute[]) {
|
||||
setLocal(EnumStorageKey['multi-tab-routes'], data);
|
||||
}
|
||||
|
||||
/** 获取缓存的多页签数据 */
|
||||
export function getTabRoutes() {
|
||||
const routes: GlobalTabRoute[] = [];
|
||||
const data = getLocal<GlobalTabRoute[]>(EnumStorageKey['multi-tab-routes']);
|
||||
if (data) {
|
||||
const defaultTabRoutes = data.map(item => ({
|
||||
...item,
|
||||
scrollPosition: {
|
||||
left: 0,
|
||||
top: 0
|
||||
}
|
||||
}));
|
||||
routes.push(...defaultTabRoutes);
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
|
||||
/** 清空多页签数据 */
|
||||
export function clearTabRoutes() {
|
||||
setTabRoutes([]);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import type { Router, RouteLocationNormalizedLoaded } from 'vue-router';
|
||||
import { defineStore } from 'pinia';
|
||||
import { useRouterPush } from '@/composables';
|
||||
import { getTabRoutes, clearTabRoutes } from '@/utils';
|
||||
import { useThemeStore } from '../theme';
|
||||
import { getTabRouteByVueRoute, isInTabRoutes, getIndexInTabRoutes, getIndexInTabRoutesByRouteName } from './helpers';
|
||||
import {
|
||||
getTabRouteByVueRoute,
|
||||
isInTabRoutes,
|
||||
getIndexInTabRoutes,
|
||||
getIndexInTabRoutesByRouteName,
|
||||
setTabRoutes,
|
||||
getTabRoutes,
|
||||
clearTabRoutes
|
||||
} from './helpers';
|
||||
|
||||
interface TabState {
|
||||
/** 多页签数据 */
|
||||
@@ -43,6 +50,10 @@ export const useTabStore = defineStore('tab-store', {
|
||||
clearTabRoutes();
|
||||
this.$reset();
|
||||
},
|
||||
/** 缓存页签路由数据 */
|
||||
cacheTabRoutes() {
|
||||
setTabRoutes(this.tabs);
|
||||
},
|
||||
/**
|
||||
* 设置当前路由对应的页签为激活状态
|
||||
* @param fullPath - 路由fullPath
|
||||
|
||||
Reference in New Issue
Block a user