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