|
|
@@ -1,8 +1,7 @@
|
|
1
|
|
-<!-- @author ruoyi 20201128 支持三级以上菜单缓存 -->
|
|
2
|
1
|
<template>
|
|
3
|
2
|
<section class="app-main">
|
|
4
|
3
|
<transition name="fade-transform" mode="out-in">
|
|
5
|
|
- <keep-alive :max="20" :exclude="notCacheName">
|
|
|
4
|
+ <keep-alive :include="cachedViews">
|
|
6
|
5
|
<router-view :key="key" />
|
|
7
|
6
|
</keep-alive>
|
|
8
|
7
|
</transition>
|
|
|
@@ -10,119 +9,17 @@
|
|
10
|
9
|
</template>
|
|
11
|
10
|
|
|
12
|
11
|
<script>
|
|
13
|
|
-import Global from "@/layout/components/global.js";
|
|
14
|
|
-
|
|
15
|
12
|
export default {
|
|
16
|
13
|
name: 'AppMain',
|
|
17
|
14
|
computed: {
|
|
18
|
|
- notCacheName() {
|
|
19
|
|
- var visitedViews = this.$store.state.tagsView.visitedViews;
|
|
20
|
|
- var noCacheViews = [];
|
|
21
|
|
- Object.keys(visitedViews).some((index) => {
|
|
22
|
|
- if (visitedViews[index].meta.noCache) {
|
|
23
|
|
- noCacheViews.push(visitedViews[index].name);
|
|
24
|
|
- }
|
|
25
|
|
- });
|
|
26
|
|
- return noCacheViews;
|
|
|
15
|
+ cachedViews() {
|
|
|
16
|
+ return this.$store.state.tagsView.cachedViews
|
|
27
|
17
|
},
|
|
28
|
18
|
key() {
|
|
29
|
|
- return this.$route.path;
|
|
30
|
|
- },
|
|
31
|
|
- },
|
|
32
|
|
- mounted() {
|
|
33
|
|
- // 关闭标签触发
|
|
34
|
|
- Global.$on("removeCache", (name, view) => {
|
|
35
|
|
- this.removeCache(name, view);
|
|
36
|
|
- });
|
|
37
|
|
- },
|
|
38
|
|
- methods: {
|
|
39
|
|
- // 获取有keep-alive子节点的Vnode
|
|
40
|
|
- getVnode() {
|
|
41
|
|
- // 判断子集非空
|
|
42
|
|
- if (this.$children.length == 0) return false;
|
|
43
|
|
- let vnode;
|
|
44
|
|
- for (let item of this.$children) {
|
|
45
|
|
- // 如果data中有key则代表找到了keep-alive下面的子集,这个key就是router-view上的key
|
|
46
|
|
- if (item.$vnode.data.key) {
|
|
47
|
|
- vnode = item.$vnode;
|
|
48
|
|
- break;
|
|
49
|
|
- }
|
|
50
|
|
- }
|
|
51
|
|
- return vnode ? vnode : false;
|
|
52
|
|
- },
|
|
53
|
|
- // 移除keep-alive缓存
|
|
54
|
|
- removeCache(name, view = {}) {
|
|
55
|
|
- let vnode = this.getVnode();
|
|
56
|
|
- if (!vnode) return false;
|
|
57
|
|
- let componentInstance = vnode.parent.componentInstance;
|
|
58
|
|
- // 这个key是用来获取前缀用来后面正则匹配用的
|
|
59
|
|
- let keyStart = vnode.key.split("/")[0];
|
|
60
|
|
- let thisKey = `${keyStart}${view.fullPath}`;
|
|
61
|
|
- let regKey = `${keyStart}${view.path}`;
|
|
62
|
|
-
|
|
63
|
|
- this[name]({ componentInstance, thisKey, regKey });
|
|
64
|
|
- },
|
|
65
|
|
- // 移除其他
|
|
66
|
|
- closeOthersTags({ componentInstance, thisKey }) {
|
|
67
|
|
- Object.keys(componentInstance.cache).forEach((key, index) => {
|
|
68
|
|
- if (key != thisKey) {
|
|
69
|
|
- // 销毁实例(这里存在多个key指向一个缓存的情况可能前面一个已经清除掉了所有要加判断)
|
|
70
|
|
- if (componentInstance.cache[key]) {
|
|
71
|
|
- componentInstance.cache[key].componentInstance.$destroy();
|
|
72
|
|
- }
|
|
73
|
|
- // 删除缓存
|
|
74
|
|
- delete componentInstance.cache[key];
|
|
75
|
|
- // 移除key中对应的key
|
|
76
|
|
- componentInstance.keys.splice(index, 1);
|
|
77
|
|
- }
|
|
78
|
|
- });
|
|
79
|
|
- },
|
|
80
|
|
- // 移除所有缓存
|
|
81
|
|
- closeAllTags({ componentInstance }) {
|
|
82
|
|
- // 销毁实例
|
|
83
|
|
- Object.keys(componentInstance.cache).forEach((key) => {
|
|
84
|
|
- if (componentInstance.cache[key]) {
|
|
85
|
|
- componentInstance.cache[key].componentInstance.$destroy();
|
|
86
|
|
- }
|
|
87
|
|
- });
|
|
88
|
|
- // 删除缓存
|
|
89
|
|
- componentInstance.cache = {};
|
|
90
|
|
- // 移除key中对应的key
|
|
91
|
|
- componentInstance.keys = [];
|
|
92
|
|
- },
|
|
93
|
|
- // 移除单个缓存
|
|
94
|
|
- closeSelectedTag({ componentInstance, regKey }) {
|
|
95
|
|
- let reg = new RegExp(`^${regKey}`);
|
|
96
|
|
- Object.keys(componentInstance.cache).forEach((key, i) => {
|
|
97
|
|
- if (reg.test(key)) {
|
|
98
|
|
- // 销毁实例
|
|
99
|
|
- if (componentInstance.cache[key]) {
|
|
100
|
|
- componentInstance.cache[key].componentInstance.$destroy();
|
|
101
|
|
- }
|
|
102
|
|
- // 删除缓存
|
|
103
|
|
- delete componentInstance.cache[key];
|
|
104
|
|
- // 移除key中对应的key
|
|
105
|
|
- componentInstance.keys.splice(i, 1);
|
|
106
|
|
- }
|
|
107
|
|
- });
|
|
108
|
|
- },
|
|
109
|
|
- // 刷新单个缓存
|
|
110
|
|
- refreshSelectedTag({ componentInstance, thisKey }) {
|
|
111
|
|
- Object.keys(componentInstance.cache).forEach((key, index) => {
|
|
112
|
|
- if (null != thisKey && key.replace("/redirect", "") == thisKey) {
|
|
113
|
|
- // 1 销毁实例(这里存在多个key指向一个缓存的情况可能前面一个已经清除掉了所有要加判断)
|
|
114
|
|
- if (componentInstance.cache[key]) {
|
|
115
|
|
- componentInstance.cache[key].componentInstance.$destroy();
|
|
116
|
|
- }
|
|
117
|
|
- // 2 删除缓存
|
|
118
|
|
- delete componentInstance.cache[key];
|
|
119
|
|
- // 3 移除key中对应的key
|
|
120
|
|
- componentInstance.keys.splice(index, 1);
|
|
121
|
|
- }
|
|
122
|
|
- });
|
|
123
|
|
- },
|
|
124
|
|
- },
|
|
125
|
|
-};
|
|
|
19
|
+ return this.$route.path
|
|
|
20
|
+ }
|
|
|
21
|
+ }
|
|
|
22
|
+}
|
|
126
|
23
|
</script>
|
|
127
|
24
|
|
|
128
|
25
|
<style lang="scss" scoped>
|
|
|
@@ -134,7 +31,7 @@ export default {
|
|
134
|
31
|
overflow: hidden;
|
|
135
|
32
|
}
|
|
136
|
33
|
|
|
137
|
|
-.fixed-header + .app-main {
|
|
|
34
|
+.fixed-header+.app-main {
|
|
138
|
35
|
padding-top: 50px;
|
|
139
|
36
|
}
|
|
140
|
37
|
|
|
|
@@ -144,7 +41,7 @@ export default {
|
|
144
|
41
|
min-height: calc(100vh - 84px);
|
|
145
|
42
|
}
|
|
146
|
43
|
|
|
147
|
|
- .fixed-header + .app-main {
|
|
|
44
|
+ .fixed-header+.app-main {
|
|
148
|
45
|
padding-top: 84px;
|
|
149
|
46
|
}
|
|
150
|
47
|
}
|