mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-15 14:24:39 +00:00
perf: 修改路由过滤 (#1443)
* perf: 修改路由过滤 * fix: 去掉 debug Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
@@ -4,7 +4,8 @@ import NProgress from 'nprogress' // progress bar
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
||||
import { startup } from '@/utils/startup'
|
||||
import store from '@/store'
|
||||
import { isSameView } from '@/utils/jms'
|
||||
import { getPropView, hasRouteViewPerm, isSameView } from '@/utils/jms'
|
||||
import Vue from 'vue'
|
||||
|
||||
NProgress.configure({
|
||||
showSpinner: false
|
||||
@@ -29,6 +30,21 @@ function generateViewRoutesIfChange({ to, from }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function changeCurrentViewIfNeed({ to, from, next }) {
|
||||
if (!to.path || isSameView(to, from)) {
|
||||
return
|
||||
}
|
||||
const hasPerm = hasRouteViewPerm(to)
|
||||
Vue.$log.debug('Change has current view, has perm: ', hasPerm)
|
||||
if (hasPerm) {
|
||||
Vue.$log.debug('Has current view perm')
|
||||
return
|
||||
}
|
||||
const view = getPropView()
|
||||
Vue.$log.debug('Get prop view and goto: ', view)
|
||||
next(`/${view}`)
|
||||
}
|
||||
|
||||
function setPageTitle() {
|
||||
const currentRoute = router.currentRoute
|
||||
const loginTitle = store.getters.publicSettings['LOGIN_TITLE']
|
||||
@@ -38,7 +54,13 @@ function setPageTitle() {
|
||||
}
|
||||
}
|
||||
|
||||
router.afterEach(async(to, from, next) => {
|
||||
router.beforeResolve(async(to, from, next) => {
|
||||
/* must call `next` */
|
||||
await changeCurrentViewIfNeed({ to, from, next })
|
||||
next()
|
||||
})
|
||||
|
||||
router.afterEach(async(to, from) => {
|
||||
// finish progress bar
|
||||
await setPageTitle()
|
||||
await generateViewRoutesIfChange({ to, from })
|
||||
|
||||
Reference in New Issue
Block a user