feat(projects): 添加页面缓存、记录在tab中的缓存页面的滚动条位置

This commit is contained in:
Soybean
2022-01-21 23:59:14 +08:00
parent db3c25ea14
commit 1d63a83822
26 changed files with 343 additions and 160 deletions

View File

@ -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();