Skip to content

Commit 91a65a1

Browse files
committed
登录返回角色信息
(cherry picked from commit 23c3aa914de9915f57f48f04b04e9ca1d48d7cca)
1 parent 0735dd6 commit 91a65a1

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

api/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){
102102
userInfo(sysUser, result);
103103
sysBaseAPI.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null);
104104

105+
List<String> roleCodes = sysUserService.getRole(sysUser.getUsername());
106+
result.getResult().put("role", roleCodes);
107+
105108
return result;
106109
}
107110

web/public/js/common.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ window.getUserInfo = function() {
2727
}
2828
}
2929

30+
window.getUserRole = function(){
31+
userRole = localStorage.getItem('pro__Login_UserRole')
32+
if(userRole){
33+
userRole = JSON.parse(userRole).value
34+
console.log(userRole)
35+
return userRole
36+
}
37+
}
38+
3039
window.getUserToken = function() {
3140
var token = JSON.parse(localStorage.getItem("pro__Access-Token"))
3241
return token==null?null:token.value

web/src/store/modules/user.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import { login, logout, phoneLogin, thirdLogin } from "@/api/login"
3-
import { ACCESS_TOKEN, USER_NAME,USER_INFO,USER_AUTH,SYS_BUTTON_AUTH,UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"
3+
import { ACCESS_TOKEN, USER_NAME,USER_INFO, USER_ROLE, USER_AUTH,SYS_BUTTON_AUTH,UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"
44
import { welcome } from "@/utils/util"
55
import { queryPermissionsByUser } from '@/api/api'
66
import { getAction } from '@/api/manage'
@@ -13,7 +13,8 @@ const user = {
1313
welcome: '',
1414
avatar: '',
1515
permissionList: [],
16-
info: {}
16+
info: {},
17+
userRole: [],
1718
},
1819

1920
mutations: {
@@ -34,6 +35,9 @@ const user = {
3435
SET_INFO: (state, info) => {
3536
state.info = info
3637
},
38+
SET_USER_ROLE: (state, info) => {
39+
state.userRole = info
40+
},
3741
},
3842

3943
actions: {
@@ -68,12 +72,16 @@ const user = {
6872
if(response.code =='200'){
6973
const result = response.result
7074
const userInfo = result.userInfo
71-
Vue.ls.set(ACCESS_TOKEN, result.token, 7 * 24 * 60 * 60 * 1000)
72-
Vue.ls.set(USER_NAME, userInfo.username, 7 * 24 * 60 * 60 * 1000)
73-
Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000)
74-
Vue.ls.set(UI_CACHE_DB_DICT_DATA, result.sysAllDictItems, 7 * 24 * 60 * 60 * 1000)
75+
const userRole = result.role
76+
const expire = 7 * 24 * 60 * 60 * 1000
77+
Vue.ls.set(ACCESS_TOKEN, result.token, expire)
78+
Vue.ls.set(USER_NAME, userInfo.username, expire)
79+
Vue.ls.set(USER_INFO, userInfo, expire)
80+
Vue.ls.set(USER_ROLE, userRole, expire)
81+
Vue.ls.set(UI_CACHE_DB_DICT_DATA, result.sysAllDictItems, expire)
7582
commit('SET_TOKEN', result.token)
7683
commit('SET_INFO', userInfo)
84+
commit('SET_USER_ROLE', userRole)
7785
commit('SET_NAME', { username: userInfo.username,realname: userInfo.realname, welcome: welcome() })
7886
commit('SET_AVATAR', userInfo.avatar)
7987
resolve(response)

web/src/store/mutation-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const DEFAULT_CONTENT_WIDTH_TYPE = 'DEFAULT_CONTENT_WIDTH_TYPE'
1111
export const DEFAULT_MULTI_PAGE = 'DEFAULT_MULTI_PAGE'
1212
export const USER_NAME = 'Login_Username'
1313
export const USER_INFO = 'Login_Userinfo'
14+
export const USER_ROLE = 'Login_UserRole'
1415
export const USER_AUTH = 'LOGIN_USER_BUTTON_AUTH'
1516
export const SYS_BUTTON_AUTH = 'SYS_BUTTON_AUTH'
1617
export const ENCRYPTED_STRING = 'ENCRYPTED_STRING'

0 commit comments

Comments
 (0)