Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
web-template
Project
Project
Details
Activity
Releases
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
张伯涛
web-template
Commits
a1061e7b
Commit
a1061e7b
authored
Apr 15, 2024
by
张伯涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vuex存储以及数据权限更新
parent
f4b37b33
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
12 deletions
+14
-12
index.js
src/router/index.js
+13
-2
user.js
src/store/modules/user.js
+0
-1
index.vue
src/views/homePage/index.vue
+1
-9
No files found.
src/router/index.js
View file @
a1061e7b
...
...
@@ -4,7 +4,8 @@ import NProgress from 'nprogress' // progress bar
import
'nprogress/nprogress.css'
// progress bar style
import
{
PageIntercept
}
from
'@/router/USER_level'
import
routes
from
'@/router/routes'
import
{
getToken
}
from
'@/utils/auth'
import
store
from
'../store'
NProgress
.
configure
({
showSpinner
:
false
})
// NProgress Configuration
Vue
.
use
(
Router
)
const
createRouter
=
()
=>
new
Router
({
...
...
@@ -20,7 +21,17 @@ router.beforeEach((to, from, next) => {
}
else
{
to
.
meta
.
needAnimation
=
true
}
new
PageIntercept
(
to
,
from
,
next
)[
to
.
meta
.
USER_LEVEL
||
'USER_VISITOR'
]()
if
(
getToken
())
{
// 是否有token
if
(
store
.
getters
.
roles
.
length
===
0
)
{
// 确认登录了有token后判断vuex存储的roles是否还有(预防浏览器刷新后清空vuex存储)
store
.
dispatch
(
'GetInfo'
).
then
(()
=>
{
// 浏览器刷新会清空vuex存储所以从新调用getinfo
new
PageIntercept
(
to
,
from
,
next
)[
to
.
meta
.
USER_LEVEL
||
'USER_VISITOR'
]()
})
}
else
{
new
PageIntercept
(
to
,
from
,
next
)[
to
.
meta
.
USER_LEVEL
||
'USER_VISITOR'
]()
}
}
else
{
new
PageIntercept
(
to
,
from
,
next
)[
to
.
meta
.
USER_LEVEL
||
'USER_VISITOR'
]()
}
})
router
.
afterEach
(()
=>
{
// finish progress bar
...
...
src/store/modules/user.js
View file @
a1061e7b
...
...
@@ -56,7 +56,6 @@ const user = {
GetInfo
({
commit
,
state
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getInfo
(
state
.
token
).
then
(
res
=>
{
localStorage
.
setItem
(
'userInfo'
,
JSON
.
stringify
(
res
.
data
.
user
))
// 在浏览器存储用户信息
const
user
=
res
.
data
.
user
// const avatar = user.avatar === null ? require('@/assets/image/profile.jpg') : user.avatar
if
(
res
.
data
.
roles
&&
res
.
data
.
roles
.
length
>
0
)
{
// 验证返回的roles是否是一个非空数组
...
...
src/views/homePage/index.vue
View file @
a1061e7b
...
...
@@ -283,16 +283,9 @@ export default {
}
},
created
()
{
this
.
getLocalInfo
()
},
methods
:
{
/** 获取浏览器缓存*/
getLocalInfo
()
{
const
list
=
JSON
.
parse
(
localStorage
.
getItem
(
'userInfo'
))
if
(
list
)
{
this
.
userForm
=
list
}
},
changeType
(
item
)
{
this
.
choseType
=
item
.
name
},
...
...
@@ -308,7 +301,6 @@ export default {
type
:
'warning'
}).
then
(()
=>
{
this
.
$store
.
dispatch
(
'FedLogOut'
).
then
(()
=>
{
localStorage
.
removeItem
(
'userInfo'
)
location
.
reload
()
})
})
...
...
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