Commit be1659e8 by caoyanzhi

update: 缓存

parent 0299fc03
...@@ -25,33 +25,6 @@ export default { ...@@ -25,33 +25,6 @@ export default {
name: 'DmHbLayout', name: 'DmHbLayout',
components: { MainMenu, AsideMenu, BreadMenu }, components: { MainMenu, AsideMenu, BreadMenu },
provide: () => provideData, provide: () => provideData,
beforeRouteUpdate(to, from, next) {
if (Array.isArray(to.meta.fromPath)) {
const isKeepAlive = to.meta.fromPath.some(el => {
let menuUrlReg = el;
let pathConfigReg = /(:.*)(\/?)/;
const pathRegStr = '([\\d\\w]+[\\-]*[\\d\\w]*)';
while (pathConfigReg.test(menuUrlReg)) {
menuUrlReg = menuUrlReg.replace(pathConfigReg, `${pathRegStr}$2`);
}
pathConfigReg = /(\/\*)(\/?)/;
while (pathConfigReg.test(menuUrlReg)) {
menuUrlReg = menuUrlReg.replace(pathConfigReg, `${pathRegStr}$2`);
}
const reg = new RegExp(`^${menuUrlReg}$`);
return reg.test(from.path);
});
if (!isKeepAlive) {
this.keepAlive = this.keepAlive.filter(el => el != to.meta.componentName);
}
setTimeout(() => {
if (this.keepAlive.every(el => el != to.meta.componentName)) {
this.keepAlive.push(to.meta.componentName);
}
}, 100);
}
next();
},
props: { props: {
// 菜单树数据 // 菜单树数据
menuList: { menuList: {
...@@ -91,11 +64,10 @@ export default { ...@@ -91,11 +64,10 @@ export default {
} }
}, },
created() { created() {
if (Array.isArray(this.$route.meta.fromPath)) { this.setKeepAlive(this.$route, {});
this.keepAlive.push(this.$route.meta.componentName);
}
this.$router.beforeEach((to, from, next) => { this.$router.beforeEach((to, from, next) => {
this.activedMenu = this.getActivedMenu(this.getMenuByPath(to.path.slice(1))); this.activedMenu = this.getActivedMenu(this.getMenuByPath(to.path.slice(1)));
this.setKeepAlive(to, from);
next(); next();
}); });
provideData.layoutVm = this; provideData.layoutVm = this;
...@@ -144,6 +116,32 @@ export default { ...@@ -144,6 +116,32 @@ export default {
getMenuByPath(path) { getMenuByPath(path) {
return this.pageRight.find(el => el.regexp.test('/' + path)) || {}; return this.pageRight.find(el => el.regexp.test('/' + path)) || {};
}, },
setKeepAlive(to, from) {
if (Array.isArray(to.meta.fromPath)) {
const isKeepAlive = to.meta.fromPath.some(el => {
let menuUrlReg = el;
let pathConfigReg = /(:.*)(\/?)/;
const pathRegStr = '([\\d\\w]+[\\-]*[\\d\\w]*)';
while (pathConfigReg.test(menuUrlReg)) {
menuUrlReg = menuUrlReg.replace(pathConfigReg, `${pathRegStr}$2`);
}
pathConfigReg = /(\/\*)(\/?)/;
while (pathConfigReg.test(menuUrlReg)) {
menuUrlReg = menuUrlReg.replace(pathConfigReg, `${pathRegStr}$2`);
}
const reg = new RegExp(`^${menuUrlReg}$`);
return reg.test(from.path);
});
if (!isKeepAlive) {
this.keepAlive = this.keepAlive.filter(el => el != to.meta.componentName);
}
setTimeout(() => {
if (this.keepAlive.every(el => el != to.meta.componentName)) {
this.keepAlive.push(to.meta.componentName);
}
}, 100);
}
},
onShowLoading(loading) { onShowLoading(loading) {
if (loading) { if (loading) {
this.fullLoading.visible = true; this.fullLoading.visible = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment