Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
bdc
/
bdcjg-web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
5f9fcd8b
authored
2023-02-15 15:25:47 +0800
by
yangwei
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
每次登录都重新请求用户信息查询接口并存入vuex
1 parent
888d73dc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
17 deletions
src/permission.js
src/store/modules/user.js
src/permission.js
View file @
5f9fcd8
...
...
@@ -11,6 +11,7 @@ router.beforeEach(async (to, from, next) => {
NProgress
.
start
();
document
.
title
=
getPageTitle
(
to
.
meta
.
title
);
let
hasAddDict
=
store
.
state
.
dict
.
addDict
;
let
hasUser
=
store
.
state
.
user
.
hasUser
;
let
hasAddRoute
=
store
.
state
.
permission
.
addRoutes
;
if
(
to
.
path
==
"/login"
)
{
sessionStorage
.
removeItem
(
"token"
);
...
...
@@ -19,6 +20,10 @@ router.beforeEach(async (to, from, next) => {
//判断token是否存在
const
hasToken
=
sessionStorage
.
getItem
(
"token"
);
if
(
hasToken
)
{
//请求用户信息
if
(
!
hasUser
)
{
store
.
dispatch
(
"user/getUserInfo"
);
}
//加载字典
if
(
!
hasAddDict
)
{
store
.
dispatch
(
"dict/generateDic"
);
...
...
@@ -27,7 +32,7 @@ router.beforeEach(async (to, from, next) => {
next
();
}
else
{
//请求菜单
const
{
result
:
getMenuData
}
=
await
getMenuInfo
(
)
||
[];
const
{
result
:
getMenuData
}
=
(
await
getMenuInfo
()
)
||
[];
const
accessRoutes
=
await
store
.
dispatch
(
"permission/generateRoutes"
,
getMenuData
...
...
src/store/modules/user.js
View file @
5f9fcd8
import
{
getUserInfo
}
from
'@/api/user'
import
{
getUserInfo
}
from
"@/api/user"
;
const
state
=
{
name
:
''
,
avatar
:
'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
,
}
hasUser
:
false
,
name
:
""
,
avatar
:
"https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
,
userInfo
:
null
,
};
const
mutations
=
{
SET_NAME
:
(
state
,
data
)
=>
{
state
.
name
=
data
.
loginName
}
}
SET_USERINFO
:
(
state
,
data
)
=>
{
state
.
hasUser
=
true
;
state
.
userInfo
=
data
;
state
.
name
=
data
.
loginName
;
},
RESET_USER
:
(
state
)
=>
{
state
.
hasUser
=
false
;
},
};
const
actions
=
{
getUserInfo
({
commit
})
{
getUserInfo
({
commit
})
{
if
(
!
state
.
hasUser
)
{
return
new
Promise
(
async
(
resolve
)
=>
{
let
{
result
:
res
}
=
await
getUserInfo
()
commit
(
'SET_NAME'
,
res
)
resolve
(
true
)
})
let
{
result
:
res
}
=
await
getUserInfo
();
commit
(
"SET_USERINFO"
,
res
);
resolve
(
true
);
});
}
else
{
return
}
},
resetdict
({
commit
})
{
commit
(
"RESET_USER"
);
},
}
}
;
export
default
{
namespaced
:
true
,
state
,
mutations
,
actions
}
actions
,
}
;
...
...
Please
register
or
sign in
to post a comment