|
@@ -1,23 +1,91 @@
|
|
import { defineStore } from "pinia";
|
|
import { defineStore } from "pinia";
|
|
import { KeepAliveState } from "@/stores/interface";
|
|
import { KeepAliveState } from "@/stores/interface";
|
|
|
|
+import { cloneDeep } from "lodash-es";
|
|
|
|
|
|
export const useKeepAliveStore = defineStore({
|
|
export const useKeepAliveStore = defineStore({
|
|
id: "geeker-keepAlive",
|
|
id: "geeker-keepAlive",
|
|
state: (): KeepAliveState => ({
|
|
state: (): KeepAliveState => ({
|
|
- keepAliveName: []
|
|
|
|
|
|
+ keepAliveName: [],
|
|
|
|
+ keepAliveList: []
|
|
}),
|
|
}),
|
|
|
|
+ getters: {
|
|
|
|
+ getKeepAliveList(): any[] {
|
|
|
|
+ return this.keepAliveList;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
actions: {
|
|
actions: {
|
|
|
|
+ setKeepAliveList(keepAliveList: any) {
|
|
|
|
+ this.keepAliveList = keepAliveList;
|
|
|
|
+
|
|
|
|
+ console.log("getKeepAliveName routeItem setKeepAliveList :>> ", JSON.stringify(this.keepAliveList));
|
|
|
|
+ console.log("getKeepAliveName routeItem setKeepAliveList :>> ", this.keepAliveList);
|
|
|
|
+ },
|
|
// Add KeepAliveName
|
|
// Add KeepAliveName
|
|
- async addKeepAliveName(name: string) {
|
|
|
|
- !this.keepAliveName.includes(name) && this.keepAliveName.push(name);
|
|
|
|
|
|
+ async addKeepAliveName(route: any) {
|
|
|
|
+ !this.keepAliveName.includes(route.name) && this.keepAliveName.push(route.name);
|
|
|
|
+
|
|
|
|
+ let routeItem = this.keepAliveList.find((item: any) => item.fullPath == route.fullPath);
|
|
|
|
+ if (!routeItem) {
|
|
|
|
+ routeItem = {
|
|
|
|
+ fullPath: route.fullPath,
|
|
|
|
+ times: 0
|
|
|
|
+ };
|
|
|
|
+ this.keepAliveList.push(routeItem);
|
|
|
|
+ }
|
|
},
|
|
},
|
|
// Remove KeepAliveName
|
|
// Remove KeepAliveName
|
|
- async removeKeepAliveName(name: string) {
|
|
|
|
- this.keepAliveName = this.keepAliveName.filter(item => item !== name);
|
|
|
|
|
|
+ removeKeepAliveName(route: any) {
|
|
|
|
+ console.log("removeKeepAliveName :>> ", route.name, route);
|
|
|
|
+ this.keepAliveName = this.keepAliveName.filter(item => item !== route.name);
|
|
|
|
+
|
|
|
|
+ // this.keepAliveList = this.keepAliveList.filter(item => item.fullPath !== route.path);
|
|
|
|
+
|
|
|
|
+ let index = this.keepAliveList.findIndex(item => item.fullPath === route.path);
|
|
|
|
+ if (index > -1) {
|
|
|
|
+ this.keepAliveList.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // const { keepAliveList } = this;
|
|
|
|
+ // let arr = cloneDeep(this.keepAliveList);
|
|
|
|
+ // this.keepAliveList = [];
|
|
|
|
+ // arr.filter(item => item.fullPath !== route.path);
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
+ // keepAliveList = arr;
|
|
|
|
+ // }, 0);
|
|
|
|
+ // .forEach(item => {
|
|
|
|
+ // this.keepAliveList.push(item);
|
|
|
|
+ // });
|
|
|
|
+ // this.keepAliveList = arr;
|
|
|
|
+ // this.setKeepAliveList(arr);
|
|
|
|
+
|
|
|
|
+ console.log("getKeepAliveName routeItem removeKeepAliveName :>> ", JSON.stringify(this.keepAliveList));
|
|
|
|
+ console.log("getKeepAliveName routeItem removeKeepAliveName :>> ", this.keepAliveList);
|
|
|
|
+ console.log("getKeepAliveName routeItem keepAliveName :>> ", this.keepAliveName);
|
|
},
|
|
},
|
|
// Set KeepAliveName
|
|
// Set KeepAliveName
|
|
async setKeepAliveName(keepAliveName: string[] = []) {
|
|
async setKeepAliveName(keepAliveName: string[] = []) {
|
|
this.keepAliveName = keepAliveName;
|
|
this.keepAliveName = keepAliveName;
|
|
|
|
+ },
|
|
|
|
+ async updateKeepAliveName(route: any) {
|
|
|
|
+ this.addKeepAliveName(route);
|
|
|
|
+ this.keepAliveList.forEach((item: any) => {
|
|
|
|
+ console.log("updateKeepAliveName item :>> ", item.fullPath, route.fullPath, item.fullPath == route.fullPath);
|
|
|
|
+ if (item.fullPath == route.fullPath) {
|
|
|
|
+ item.times++;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ getKeepAliveName(name: string) {
|
|
|
|
+ let routeItem = this.keepAliveList.find((item: any) => item.fullPath == name);
|
|
|
|
+ if (!routeItem) {
|
|
|
|
+ routeItem = {
|
|
|
|
+ fullPath: name,
|
|
|
|
+ times: 0
|
|
|
|
+ };
|
|
|
|
+ this.keepAliveList.push(routeItem);
|
|
|
|
+ }
|
|
|
|
+ console.log("getKeepAliveName routeItem :>> ", routeItem, this.keepAliveList);
|
|
|
|
+ return routeItem;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|