perf/route (#54)

* perf: router

* perf: route
This commit is contained in:
啝裳
2021-10-12 23:33:13 +08:00
committed by GitHub
parent 0408fa6f96
commit a31d154806
18 changed files with 257 additions and 38 deletions

View File

@@ -1,5 +1,6 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { cacheType } from "./types";
import { constantRoutesArr, ascending, filterTree } from "/@/router/index";
export const usePermissionStore = defineStore({
@@ -8,7 +9,9 @@ export const usePermissionStore = defineStore({
// 静态路由
constantRoutes: constantRoutesArr,
wholeRoutes: [],
buttonAuth: []
buttonAuth: [],
// 缓存页面keepAlive
cachePageList: []
}),
actions: {
asyncActionRoutes(routes) {
@@ -33,6 +36,23 @@ export const usePermissionStore = defineStore({
},
async changeSetting(routes) {
await this.asyncActionRoutes(routes);
},
cacheOperate({ mode, name }: cacheType) {
switch (mode) {
case "add":
this.cachePageList.push(name);
this.cachePageList = [...new Set(this.cachePageList)];
break;
case "delete":
// eslint-disable-next-line no-case-declarations
const delIndex = this.cachePageList.findIndex(v => v === name);
this.cachePageList.splice(delIndex, 1);
break;
}
},
// 清空缓存页面
clearAllCachePage() {
this.cachePageList = [];
}
}
});

View File

@@ -5,16 +5,13 @@ import { store } from "/@/store";
interface SettingState {
title: string;
fixedHeader: boolean;
cachedPageList: string[];
}
export const useSettingStore = defineStore({
id: "pure-setting",
state: (): SettingState => ({
title: defaultSettings.title,
fixedHeader: defaultSettings.fixedHeader,
// 需要开启keepalive的页面数组里面放页面的name即可
cachedPageList: ["welcome", "reEditor"]
fixedHeader: defaultSettings.fixedHeader
}),
getters: {
getTitle() {

View File

@@ -0,0 +1,6 @@
import { RouteRecordName } from "vue-router";
export type cacheType = {
mode: string;
name?: RouteRecordName;
};