Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
07512c16
Commit
07512c16
authored
Jan 11, 2023
by
“yiyousong”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pref:修改路由守卫
parent
03f6b05c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
38 deletions
+41
-38
base-manager-ui/admin/src/router/guards.js
base-manager-ui/admin/src/router/guards.js
+41
-38
No files found.
base-manager-ui/admin/src/router/guards.js
View file @
07512c16
import
{
hasAuthority
}
from
'
@/utils/authority-utils
'
import
{
hasAuthority
}
from
"
@/utils/authority-utils
"
;
// import {loginIgnore} from '@/router/index'
// import {loginIgnore} from '@/router/index'
// import {checkAuthorization} from '@/utils/request'
// import {checkAuthorization} from '@/utils/request'
import
NProgress
from
'
nprogress
'
import
NProgress
from
"
nprogress
"
;
import
local
from
"
@/utils/local
"
import
local
from
"
@/utils/local
"
;
NProgress
.
configure
({
showSpinner
:
false
})
NProgress
.
configure
({
showSpinner
:
false
})
;
/**
/**
* 进度条开始
* 进度条开始
...
@@ -15,10 +15,10 @@ NProgress.configure({ showSpinner: false })
...
@@ -15,10 +15,10 @@ NProgress.configure({ showSpinner: false })
const
progressStart
=
(
to
,
from
,
next
)
=>
{
const
progressStart
=
(
to
,
from
,
next
)
=>
{
// start progress bar
// start progress bar
if
(
!
NProgress
.
isStarted
())
{
if
(
!
NProgress
.
isStarted
())
{
NProgress
.
start
()
NProgress
.
start
()
;
}
}
next
()
next
()
;
}
}
;
/**
/**
* 登录守卫
* 登录守卫
...
@@ -28,15 +28,15 @@ const progressStart = (to, from, next) => {
...
@@ -28,15 +28,15 @@ const progressStart = (to, from, next) => {
* @param options
* @param options
*/
*/
const
loginGuard
=
(
to
,
from
,
next
)
=>
{
const
loginGuard
=
(
to
,
from
,
next
)
=>
{
let
token
=
local
.
getLocal
(
'
token
'
)
?
true
:
false
let
token
=
local
.
getLocal
(
"
token
"
)
?
true
:
false
;
if
(
token
)
{
if
(
token
)
{
next
()
next
()
;
}
else
{
}
else
{
// 再次判断防止死循环
// 再次判断防止死循环
if
(
to
.
path
===
'
/jump
'
)
{
if
(
to
.
path
===
"
/jump
"
)
{
next
()
next
()
;
}
else
{
}
else
{
location
.
href
=
'
http://192.168.0.98:11072/#/
'
location
.
href
=
process
.
env
.
VUE_APP_API_portal_URL
+
"
/#/
"
;
}
}
}
}
// const {message} = options
// const {message} = options
...
@@ -46,7 +46,7 @@ const loginGuard = (to, from, next) => {
...
@@ -46,7 +46,7 @@ const loginGuard = (to, from, next) => {
// } else {
// } else {
// }
// }
// next()
// next()
}
}
;
/**
/**
* 权限守卫
* 权限守卫
...
@@ -56,17 +56,17 @@ const loginGuard = (to, from, next) => {
...
@@ -56,17 +56,17 @@ const loginGuard = (to, from, next) => {
* @param options
* @param options
*/
*/
const
authorityGuard
=
(
to
,
from
,
next
,
options
)
=>
{
const
authorityGuard
=
(
to
,
from
,
next
,
options
)
=>
{
const
{
store
,
message
}
=
options
const
{
store
,
message
}
=
options
;
const
permissions
=
store
.
getters
[
'
account/permissions
'
]
const
permissions
=
store
.
getters
[
"
account/permissions
"
];
const
roles
=
store
.
getters
[
'
account/roles
'
]
const
roles
=
store
.
getters
[
"
account/roles
"
];
if
(
!
hasAuthority
(
to
,
permissions
,
roles
))
{
if
(
!
hasAuthority
(
to
,
permissions
,
roles
))
{
message
.
warning
(
`对不起,您无权访问页面:
${
to
.
fullPath
}
,请联系管理员`
)
message
.
warning
(
`对不起,您无权访问页面:
${
to
.
fullPath
}
,请联系管理员`
)
;
next
({
path
:
'
/403
'
})
next
({
path
:
"
/403
"
});
// NProgress.done()
// NProgress.done()
}
else
{
}
else
{
next
()
next
()
;
}
}
}
}
;
/**
/**
* 混合导航模式下一级菜单跳转重定向
* 混合导航模式下一级菜单跳转重定向
...
@@ -77,28 +77,31 @@ const authorityGuard = (to, from, next, options) => {
...
@@ -77,28 +77,31 @@ const authorityGuard = (to, from, next, options) => {
* @returns {*}
* @returns {*}
*/
*/
const
redirectGuard
=
(
to
,
from
,
next
,
options
)
=>
{
const
redirectGuard
=
(
to
,
from
,
next
,
options
)
=>
{
const
{
store
}
=
options
const
{
store
}
=
options
;
const
getFirstChild
=
(
routes
)
=>
{
const
getFirstChild
=
(
routes
)
=>
{
const
route
=
routes
[
0
]
const
route
=
routes
[
0
]
;
if
(
!
route
.
children
||
route
.
children
.
length
===
0
)
{
if
(
!
route
.
children
||
route
.
children
.
length
===
0
)
{
return
route
return
route
;
}
}
return
getFirstChild
(
route
.
children
)
return
getFirstChild
(
route
.
children
)
;
}
}
;
// 自定义 || head模式展示一级菜单
// 自定义 || head模式展示一级菜单
if
(
store
.
state
.
setting
.
layout
===
'
mix
'
||
store
.
state
.
setting
.
layout
===
'
head
'
)
{
if
(
const
firstMenu
=
store
.
getters
[
'
setting/firstMenu
'
]
store
.
state
.
setting
.
layout
===
"
mix
"
||
if
(
firstMenu
.
find
(
item
=>
item
.
fullPath
===
to
.
fullPath
))
{
store
.
state
.
setting
.
layout
===
"
head
"
store
.
commit
(
'
setting/setActivatedFirst
'
,
to
.
fullPath
)
)
{
const
subMenu
=
store
.
getters
[
'
setting/subMenu
'
]
const
firstMenu
=
store
.
getters
[
"
setting/firstMenu
"
];
if
(
firstMenu
.
find
((
item
)
=>
item
.
fullPath
===
to
.
fullPath
))
{
store
.
commit
(
"
setting/setActivatedFirst
"
,
to
.
fullPath
);
const
subMenu
=
store
.
getters
[
"
setting/subMenu
"
];
if
(
subMenu
.
length
>
0
)
{
if
(
subMenu
.
length
>
0
)
{
const
redirect
=
getFirstChild
(
subMenu
)
const
redirect
=
getFirstChild
(
subMenu
)
;
return
next
({
path
:
redirect
.
fullPath
})
return
next
({
path
:
redirect
.
fullPath
})
;
}
}
}
}
}
}
next
()
next
()
;
}
}
;
/**
/**
* 进度条结束
* 进度条结束
...
@@ -108,10 +111,10 @@ const redirectGuard = (to, from, next, options) => {
...
@@ -108,10 +111,10 @@ const redirectGuard = (to, from, next, options) => {
*/
*/
const
progressDone
=
()
=>
{
const
progressDone
=
()
=>
{
// finish progress bar
// finish progress bar
NProgress
.
done
()
NProgress
.
done
()
;
}
}
;
export
default
{
export
default
{
beforeEach
:
[
progressStart
,
authorityGuard
,
loginGuard
,
redirectGuard
],
beforeEach
:
[
progressStart
,
authorityGuard
,
loginGuard
,
redirectGuard
],
afterEach
:
[
progressDone
]
afterEach
:
[
progressDone
]
,
}
}
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment