mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 添加页面缓存、记录在tab中的缓存页面的滚动条位置
This commit is contained in:
@ -34,6 +34,9 @@ export const useAppStore = defineStore('app-store', {
|
||||
} else {
|
||||
this.reloadFlag = true;
|
||||
}
|
||||
setTimeout(() => {
|
||||
document.documentElement.scrollTo({ left: 0, top: 0 });
|
||||
}, 100);
|
||||
},
|
||||
/** 打开设置抽屉 */
|
||||
openSettingDrawer() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { Router } from 'vue-router';
|
||||
import { defineStore } from 'pinia';
|
||||
import { fetchUserRoutes } from '@/service';
|
||||
import { transformAuthRouteToMenu, transformAuthRoutesToVueRoutes } from '@/utils';
|
||||
import { transformAuthRouteToMenu, transformAuthRoutesToVueRoutes, getCacheRoutes } from '@/utils';
|
||||
import type { GlobalMenuOption } from '@/interface';
|
||||
import { useTabStore } from '../tab';
|
||||
|
||||
@ -12,13 +12,16 @@ interface RouteState {
|
||||
routeHomeName: AuthRoute.RouteKey;
|
||||
/** 菜单 */
|
||||
menus: GlobalMenuOption[];
|
||||
/** 缓存的路由名称 */
|
||||
cacheRoutes: string[];
|
||||
}
|
||||
|
||||
export const useRouteStore = defineStore('route-store', {
|
||||
state: (): RouteState => ({
|
||||
isAddedDynamicRoute: false,
|
||||
routeHomeName: 'dashboard_analysis',
|
||||
menus: []
|
||||
menus: [],
|
||||
cacheRoutes: []
|
||||
}),
|
||||
actions: {
|
||||
/**
|
||||
@ -38,6 +41,8 @@ export const useRouteStore = defineStore('route-store', {
|
||||
router.addRoute(route);
|
||||
});
|
||||
|
||||
this.cacheRoutes = getCacheRoutes(vueRoutes);
|
||||
|
||||
initHomeTab(data.home, router);
|
||||
this.isAddedDynamicRoute = true;
|
||||
}
|
||||
|
@ -9,7 +9,11 @@ export function getTabRouteByVueRoute(route: RouteRecordNormalized | RouteLocati
|
||||
const tabRoute: GlobalTabRoute = {
|
||||
name: route.name,
|
||||
path: route.path,
|
||||
meta: route.meta
|
||||
meta: route.meta,
|
||||
scrollPosition: {
|
||||
left: 0,
|
||||
top: 0
|
||||
}
|
||||
};
|
||||
return tabRoute;
|
||||
}
|
||||
|
@ -23,6 +23,10 @@ export const useTabStore = defineStore('tab-store', {
|
||||
path: '/',
|
||||
meta: {
|
||||
title: 'root'
|
||||
},
|
||||
scrollPosition: {
|
||||
left: 0,
|
||||
top: 0
|
||||
}
|
||||
},
|
||||
activeTab: ''
|
||||
@ -132,6 +136,32 @@ export const useTabStore = defineStore('tab-store', {
|
||||
routerPush(path);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 记录tab滚动位置
|
||||
* @param path - 路由path
|
||||
* @param position - tab当前页的滚动位置
|
||||
*/
|
||||
recordTabScrollPosition(path: string, position: { left: number; top: number }) {
|
||||
const index = getIndexInTabRoutes(this.tabs, path);
|
||||
if (index > -1) {
|
||||
this.tabs[index].scrollPosition = position;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 获取tab滚动位置
|
||||
* @param path - 路由path
|
||||
*/
|
||||
getTabScrollPosition(path: string) {
|
||||
const position = {
|
||||
left: 0,
|
||||
top: 0
|
||||
};
|
||||
const index = getIndexInTabRoutes(this.tabs, path);
|
||||
if (index > -1) {
|
||||
Object.assign(position, this.tabs[index].scrollPosition);
|
||||
}
|
||||
return position;
|
||||
},
|
||||
/** 初始化Tab状态 */
|
||||
iniTabStore(currentRoute: RouteLocationNormalizedLoaded) {
|
||||
const theme = useThemeStore();
|
||||
|
@ -37,7 +37,7 @@ function getThemeColors(colors: [ColorType, string][]) {
|
||||
}
|
||||
|
||||
/** 获取naive的主题颜色 */
|
||||
export function getNaiveThemeOverrides(colors: { [key in ColorType]: string }): GlobalThemeOverrides {
|
||||
export function getNaiveThemeOverrides(colors: Record<ColorType, string>): GlobalThemeOverrides {
|
||||
const { primary, info, success, warning, error } = colors;
|
||||
const themeColors = getThemeColors([
|
||||
['primary', primary],
|
||||
|
Reference in New Issue
Block a user