mirror of
https://github.com/jumpserver/lina.git
synced 2025-07-16 16:21:21 +00:00
feat: 增加默认进入上次登录的角色功能;优化权限判断逻辑
This commit is contained in:
parent
db825c5c30
commit
13eca9da63
@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import Router from 'vue-router'
|
||||
import { getBeforeViewRouter } from '@/utils/jms'
|
||||
|
||||
Vue.use(Router)
|
||||
|
||||
@ -51,6 +52,16 @@ import ticketsRoutes from './tickets'
|
||||
import settingsRoutes from './settings'
|
||||
import profileRoutes from './profile'
|
||||
|
||||
const permissionRoutes = [
|
||||
workspaceViewRoutes,
|
||||
consoleViewRoutes,
|
||||
auditViewRoutes,
|
||||
ticketsRoutes,
|
||||
settingsRoutes,
|
||||
profileRoutes
|
||||
]
|
||||
const beforeViewRouter = getBeforeViewRouter(permissionRoutes) || ''
|
||||
|
||||
/**
|
||||
* admin
|
||||
* the routes that need to be dynamically loaded based on admin roles
|
||||
@ -58,17 +69,12 @@ import profileRoutes from './profile'
|
||||
export const allRoutes = [
|
||||
{
|
||||
path: '',
|
||||
redirect: '/workspace/home',
|
||||
redirect: beforeViewRouter,
|
||||
meta: {
|
||||
permissions: []
|
||||
}
|
||||
},
|
||||
workspaceViewRoutes,
|
||||
consoleViewRoutes,
|
||||
auditViewRoutes,
|
||||
ticketsRoutes,
|
||||
settingsRoutes,
|
||||
profileRoutes
|
||||
...permissionRoutes
|
||||
]
|
||||
|
||||
const createRouter = () => new Router({
|
||||
|
@ -13,24 +13,6 @@ function hasLicense(route, rootState) {
|
||||
return !(!licenseIsValid && licenseRequired)
|
||||
}
|
||||
|
||||
export function filterLicenseRequiredRoutes(routes, rootState) {
|
||||
const res = []
|
||||
|
||||
routes.forEach(route => {
|
||||
const tmp = {
|
||||
...route
|
||||
}
|
||||
if (hasLicense(route, rootState)) {
|
||||
if (tmp.children) {
|
||||
tmp.children = filterLicenseRequiredRoutes(tmp.children, rootState)
|
||||
}
|
||||
res.push(tmp)
|
||||
}
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
function isNeedHidden(route, rootState) {
|
||||
let hidden = route.meta ? route.meta.hidden : false
|
||||
if (typeof hidden === 'function') {
|
||||
@ -46,7 +28,7 @@ export function filterHiddenRoutes(routes, rootState) {
|
||||
const tmp = {
|
||||
...route
|
||||
}
|
||||
if (!isNeedHidden(route, rootState)) {
|
||||
if (!isNeedHidden(route, rootState) || hasLicense(route, rootState)) {
|
||||
if (tmp.children) {
|
||||
tmp.children = filterHiddenRoutes(tmp.children, rootState)
|
||||
}
|
||||
@ -223,6 +205,9 @@ const actions = {
|
||||
viewRoute = route
|
||||
}
|
||||
}
|
||||
if (viewRoute.meta?.showNavSwitcher) {
|
||||
localStorage.setItem('BeforeViewRouter', JSON.stringify(viewRoute.path))
|
||||
}
|
||||
commit('SET_VIEW_ROUTE', viewRoute)
|
||||
})
|
||||
},
|
||||
@ -230,7 +215,6 @@ const actions = {
|
||||
return new Promise(resolve => {
|
||||
let routes = filterPermedRoutes(allRoutes, rootState)
|
||||
routes = filterHiddenRoutes(routes, rootState)
|
||||
routes = filterLicenseRequiredRoutes(routes, rootState)
|
||||
if (routes.length === 0) {
|
||||
console.log('No route find')
|
||||
} else {
|
||||
|
@ -58,3 +58,13 @@ export function hasActionPerm(route, action) {
|
||||
const permsRequired = getRouteRequiredPerms(route, action)
|
||||
return hasPermission(permsRequired)
|
||||
}
|
||||
|
||||
export function getBeforeViewRouter(permissionRoutes) {
|
||||
let prefer = JSON.parse(localStorage.getItem('BeforeViewRouter')) || ''
|
||||
const hasRole = permissionRoutes.some(i => (i.path === prefer && i.path !== ''))
|
||||
if (!prefer) {
|
||||
prefer = hasRole ? prefer : '/workspace'
|
||||
localStorage.setItem('BeforeViewRouter', JSON.stringify(prefer))
|
||||
}
|
||||
return prefer
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user