piexlmax 3 years ago
parent
commit
aeabe8ccb7
  1. 20
      web/src/permission.js
  2. 2
      web/src/view/layout/index.vue

20
web/src/permission.js

@ -14,7 +14,26 @@ const getRouter = async() => {
}) })
} }
async function handleKeepAlive(to) {
if (to.matched && to.matched.length > 2) {
for (let i = 1; i < to.matched.length; i++) {
const element = to.matched[i - 1]
if (element.name === "layout") {
to.matched.splice(i, 1)
await handleKeepAlive(to)
}
// 如果没有按需加载完成则等待加载
if (typeof element.components.default === 'function') {
await element.components.default()
await handleKeepAlive(to)
}
}
}
}
router.beforeEach(async(to, from, next) => { router.beforeEach(async(to, from, next) => {
to.meta.matcheds =JSON.parse(JSON.stringify(to.matched))
handleKeepAlive(to)
const token = store.getters['user/token'] const token = store.getters['user/token']
// 在白名单中的判断情况 // 在白名单中的判断情况
document.title = getPageTitle(to.meta.title) document.title = getPageTitle(to.meta.title)
@ -35,6 +54,7 @@ router.beforeEach(async(to, from, next) => {
if (!asyncRouterFlag) { if (!asyncRouterFlag) {
asyncRouterFlag++ asyncRouterFlag++
await getRouter() await getRouter()
next({...to, replace: true }) next({...to, replace: true })
} else { } else {
if (to.matched.length) { if (to.matched.length) {

2
web/src/view/layout/index.vue

@ -152,7 +152,7 @@ export default {
return this.$route.meta.title || '当前页面' return this.$route.meta.title || '当前页面'
}, },
matched() { matched() {
return this.$route.matched
return this.$route.meta.matcheds
} }
}, },
created() { created() {

Loading…
Cancel
Save