mirror of
https://github.com/yangzongzhuan/RuoYi-App.git
synced 2025-09-27 14:42:41 +00:00
全局数据存储用户编号
This commit is contained in:
@@ -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
|
||||
|
@@ -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,6 +71,7 @@ const user = {
|
||||
if (!isHttp(avatar)) {
|
||||
avatar = (isEmpty(avatar)) ? defAva : baseUrl + avatar
|
||||
}
|
||||
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)
|
||||
@@ -73,6 +79,7 @@ const user = {
|
||||
} else {
|
||||
commit('SET_ROLES', ['ROLE_DEFAULT'])
|
||||
}
|
||||
commit('SET_ID', userid)
|
||||
commit('SET_NAME', username)
|
||||
commit('SET_AVATAR', avatar)
|
||||
resolve(res)
|
||||
|
@@ -1,8 +1,9 @@
|
||||
const constant = {
|
||||
avatar: 'vuex_avatar',
|
||||
name: 'vuex_name',
|
||||
roles: 'vuex_roles',
|
||||
permissions: 'vuex_permissions'
|
||||
avatar: 'user_avatar',
|
||||
id: 'user_id',
|
||||
name: 'user_name',
|
||||
roles: 'user_roles',
|
||||
permissions: 'user_permissions'
|
||||
}
|
||||
|
||||
export default constant
|
||||
|
@@ -4,7 +4,7 @@ import constant from './constant'
|
||||
let storageKey = 'storage_data'
|
||||
|
||||
// 存储节点变量名
|
||||
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions]
|
||||
let storageNodeKeys = [constant.avatar, constant.id, constant.name, constant.roles, constant.permissions]
|
||||
|
||||
const storage = {
|
||||
set: function(key, value) {
|
||||
|
Reference in New Issue
Block a user