Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sup-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
sup-server
Commits
b9b3cefe
Commit
b9b3cefe
authored
Nov 11, 2022
by
tyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
路由守卫
parent
68a10ac9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
11 deletions
+62
-11
index.js
dsk-srm-server/src/router/index.js
+14
-10
permission.js
dsk-srm-server/src/router/permission.js
+47
-0
index.js
dsk-srm-server/src/store/index.js
+1
-1
No files found.
dsk-srm-server/src/router/index.js
View file @
b9b3cefe
import
Vue
from
'vue'
import
VueRouter
from
'vue-router'
import
Vue
from
'vue'
;
import
VueRouter
from
'vue-router'
;
Vue
.
use
(
VueRouter
)
Vue
.
use
(
VueRouter
)
;
const
routes
=
[
]
]
;
const
router
=
new
VueRouter
({
mode
:
'history'
,
base
:
process
.
env
.
BASE_URL
,
routes
:[
routes
:
[
{
path
:
'/'
,
path
:
'/'
,
redirect
:
'/login'
,
},
{
path
:
'/login'
,
path
:
'/login'
,
// redirect: '/login',
name
:
'login'
,
name
:
'login'
,
component
:
()
=>
import
(
'@/login'
),
meta
:
{
title
:
"登录页"
,
needToken
:
false
}
},
]
})
})
;
export
default
router
export
default
router
;
dsk-srm-server/src/router/permission.js
0 → 100644
View file @
b9b3cefe
import
router
from
'./index'
;
import
store
from
'@/store/index'
;
import
{
Message
}
from
'element-ui'
;
import
{
getToken
}
from
'@/utils/auth'
;
// 路由前置守卫
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
to
.
meta
?.
title
&&
(
document
.
title
=
to
.
meta
.
title
);
// 从cookie中获取token
if
(
getToken
())
{
/**
* 判断前往的path是否为登录页
* 是重定向
* 否则根据用户基本信息 获取当前状态
*/
// 跳转拉取用户基本信息
if
(
!
store
.
state
.
user
.
userInfo
?.
userId
)
{
store
.
dispatch
(
"user/getUserInfo"
).
then
(()
=>
{
next
();
})
.
catch
(
err
=>
{
Message
.
error
(
err
.
msg
||
"获取用户信息失败!"
);
store
.
dispatch
(
'user/loginOut'
).
finally
(()
=>
{
location
.
href
=
'/login'
;
});
});
}
else
{
next
();
}
}
else
{
/**
* 判断当前前往页面是否需要token
* 不匹配 以及 未带token重定向到登录页
*/
if
(
to
.
meta
?.
needToken
===
false
)
{
next
();
}
else
{
next
({
path
:
"/login"
});
}
}
});
\ No newline at end of file
dsk-srm-server/src/store/index.js
View file @
b9b3cefe
...
...
@@ -5,6 +5,6 @@ Vue.use(Vuex);
export
default
new
Vuex
.
Store
({
modules
:
{
userModule
user
:
user
Module
}
});
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