mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-09 13:53:38 +08:00
@@ -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 = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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() {
|
||||
|
||||
6
src/store/modules/types.ts
Normal file
6
src/store/modules/types.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { RouteRecordName } from "vue-router";
|
||||
|
||||
export type cacheType = {
|
||||
mode: string;
|
||||
name?: RouteRecordName;
|
||||
};
|
||||
Reference in New Issue
Block a user