全局数据存储用户编号

This commit is contained in:
RuoYi
2025-04-23 21:13:20 +08:00
parent c3d9e4e913
commit c9f9f5c6ff
4 changed files with 15 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
const getters = {
token: state => state.user.token,
avatar: state => state.user.avatar,
id: state => state.user.id,
name: state => state.user.name,
roles: state => state.user.roles,
permissions: state => state.user.permissions

View File

@@ -11,6 +11,7 @@ const baseUrl = config.baseUrl
const user = {
state: {
token: getToken(),
id: storage.get(constant.id),
name: storage.get(constant.name),
avatar: storage.get(constant.avatar),
roles: storage.get(constant.roles),
@@ -21,6 +22,10 @@ const user = {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_ID: (state, id) => {
state.id = id
storage.set(constant.id, id)
},
SET_NAME: (state, name) => {
state.name = name
storage.set(constant.name, name)
@@ -66,13 +71,15 @@ const user = {
if (!isHttp(avatar)) {
avatar = (isEmpty(avatar)) ? defAva : baseUrl + avatar
}
const username = (isEmpty(user) || isEmpty(user.userName)) ? "" : user.userName
const userid = (isEmpty(user) || isEmpty(user.userId)) ? "" : user.userId
const username = (isEmpty(user) || isEmpty(user.userName)) ? "" : user.userName
if (res.roles && res.roles.length > 0) {
commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions)
} else {
commit('SET_ROLES', ['ROLE_DEFAULT'])
}
commit('SET_ID', userid)
commit('SET_NAME', username)
commit('SET_AVATAR', avatar)
resolve(res)