perf: 修改路由过滤 (#1443)

* perf: 修改路由过滤

* fix: 去掉 debug

Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
fit2bot
2022-03-10 20:18:58 +08:00
committed by GitHub
parent a8beac0b7a
commit be118172e2
6 changed files with 31 additions and 23 deletions

View File

@@ -131,6 +131,9 @@ export function getRouteViewRequirePerms(route) {
}
export function hasRouteViewPerm(route) {
if (route.name) {
return hasPermission(route.meta.permissions)
}
const viewName = route.path.split('/')[1]
const perms = getViewRequirePerms(viewName)
return hasPermission(perms)

View File

@@ -7,7 +7,6 @@ import 'nprogress/nprogress.css' // progress bar style
import { getTokenFromCookie } from '@/utils/auth'
import orgUtil from '@/utils/org'
import { getCurrentOrg } from '@/api/orgs'
import { getPropView, hasRouteViewPerm, isSameView } from '@/utils/jms'
const whiteList = ['/login', process.env.VUE_APP_LOGIN_PATH] // no redirect whitelist
let initial = false
@@ -108,21 +107,6 @@ export async function checkUserFirstLogin({ to, from, next }) {
}
}
export async function changeCurrentViewIfNeed({ to, from, next }) {
if (!to.path || isSameView(to, from)) {
return
}
const hasPerm = hasRouteViewPerm(to)
Vue.$log.debug('Change current view if need: ', 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}`)
}
export async function startup({ to, from, next }) {
if (initial) {
return true
@@ -133,9 +117,8 @@ export async function startup({ to, from, next }) {
await getPublicSetting({ to, from, next })
// await setHeadTitle({ to, from, next })
await checkLogin({ to, from, next })
await changeCurrentOrgIfNeed({ to, from, next })
await generatePageRoutes({ to, from, next })
await changeCurrentViewIfNeed({ to, from, next })
await changeCurrentOrgIfNeed({ to, from, next })
await checkUserFirstLogin({ to, from, next })
return true
}