解决登录后用户权限加载的问题
This commit is contained in:
@@ -14,7 +14,8 @@ HROS.app = (function(){
|
||||
HROS.app.get();
|
||||
},
|
||||
get : function(){
|
||||
$.getJSON('../../app/findDesk', function (sc) {
|
||||
var userId = sessionStorage.getItem("userId");
|
||||
$.getJSON('../../app/findAppByUserId?userId=' + userId, function (sc) {
|
||||
HROS.VAR.dock = sc['dock'];
|
||||
HROS.VAR.desk = sc['desk'];
|
||||
//输出桌面应用
|
||||
|
||||
@@ -62,8 +62,8 @@
|
||||
});
|
||||
|
||||
//登录按钮绑定处理事件
|
||||
$('#btn_login').bind({
|
||||
click: checkUserInput
|
||||
$('#btn_login').off("click").on("click", function () {
|
||||
checkUserInput();
|
||||
});
|
||||
|
||||
//检测用户输入数据
|
||||
@@ -123,7 +123,24 @@
|
||||
}
|
||||
//跳转到用户管理界面
|
||||
else if (loginInfoTip.indexOf("user can login") != -1 || loginInfoTip == "user already login") {
|
||||
window.location.href = "/";
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/user/getUserSession",
|
||||
dataType: "json",
|
||||
success: function (res) {
|
||||
if(res && res.code === 200) {
|
||||
if(res.data.user) {
|
||||
var user = res.data.user;
|
||||
sessionStorage.setItem("userId", user.id);
|
||||
window.location.href = "/";
|
||||
}
|
||||
}
|
||||
},
|
||||
//此处添加错误处理
|
||||
error: function () {
|
||||
alert("后台访问错误,请联系管理员!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.jsh.erp.controller;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.datasource.entities.App;
|
||||
import com.jsh.erp.datasource.entities.UserBusiness;
|
||||
import com.jsh.erp.service.app.AppService;
|
||||
import com.jsh.erp.service.userBusiness.UserBusinessService;
|
||||
import com.jsh.erp.utils.BaseResponseInfo;
|
||||
@@ -32,6 +33,73 @@ public class AppController {
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
/**
|
||||
* 根据用户查询有权限的app
|
||||
* @param userId
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findAppByUserId")
|
||||
public JSONObject findAppByUserId(@RequestParam("userId") String userId, HttpServletRequest request) {
|
||||
List<UserBusiness> roleList = userBusinessService.findRoleByUserId(userId);
|
||||
String roles = null;
|
||||
if(roleList!=null && roleList.size()>0 && roleList.get(0)!=null){
|
||||
roles = roleList.get(0).getValue();
|
||||
}
|
||||
if(roles!=null) {
|
||||
roles = roles.replaceAll("\\]\\[",",").replaceAll("\\]","").replaceAll("\\[",""); //转为逗号隔开的
|
||||
}
|
||||
List<UserBusiness> appList = userBusinessService.findAppByRoles(roles);
|
||||
String apps = null;
|
||||
if(appList!=null && appList.size()>0 && appList.get(0)!=null){
|
||||
apps = appList.get(0).getValue();
|
||||
}
|
||||
if(apps!=null) {
|
||||
apps = apps.replaceAll("\\]\\[",",").replaceAll("\\]","").replaceAll("\\[",""); //转为逗号隔开的
|
||||
}
|
||||
JSONObject obj = new JSONObject();
|
||||
List<App> dockList = appService.findAppInIds(apps,"dock");
|
||||
JSONArray dockArray = new JSONArray();
|
||||
if (null != dockList) {
|
||||
for (App app : dockList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", app.getId());
|
||||
item.put("title", app.getName());
|
||||
item.put("type", app.getType());
|
||||
item.put("icon", "../../upload/images/deskIcon/" + app.getIcon());
|
||||
item.put("url", app.getUrl());
|
||||
item.put("width", app.getWidth());
|
||||
item.put("height", app.getHeight());
|
||||
item.put("isresize", app.getResize());
|
||||
item.put("isopenmax", app.getOpenmax());
|
||||
item.put("isflash", app.getFlash());
|
||||
dockArray.add(item);
|
||||
}
|
||||
}
|
||||
obj.put("dock",dockArray);
|
||||
|
||||
List<App> deskList = appService.findAppInIds(apps,"desk");
|
||||
JSONArray deskArray = new JSONArray();
|
||||
if (null != deskList) {
|
||||
for (App app : deskList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", app.getId());
|
||||
item.put("title", app.getName());
|
||||
item.put("type", app.getType());
|
||||
item.put("icon", "../../upload/images/deskIcon/" + app.getIcon());
|
||||
item.put("url", "../../pages/common/menu.html?appID=" + app.getNumber() + "&id=" + app.getId());
|
||||
item.put("width", app.getWidth());
|
||||
item.put("height", app.getHeight());
|
||||
item.put("isresize", app.getResize());
|
||||
item.put("isopenmax", app.getOpenmax());
|
||||
item.put("isflash", app.getFlash());
|
||||
deskArray.add(item);
|
||||
}
|
||||
}
|
||||
obj.put("desk",deskArray);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/findDesk")
|
||||
public JSONObject findDesk(HttpServletRequest request) {
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
@@ -82,4 +82,13 @@ public class AppService {
|
||||
List<App> list = appMapper.selectByExample(example);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<App> findAppInIds(String ids, String type){
|
||||
List<Long> idList = StringUtil.strToLongList(ids);
|
||||
AppExample example = new AppExample();
|
||||
example.createCriteria().andZlEqualTo(type).andEnabledEqualTo(true).andIdIn(idList);
|
||||
example.setOrderByClause("Sort");
|
||||
List<App> list = appMapper.selectByExample(example);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,4 +97,19 @@ public class UserBusinessService {
|
||||
return userBusinessMapper.updateByExampleSelective(userBusiness, example);
|
||||
}
|
||||
|
||||
public List<UserBusiness> findRoleByUserId(String userId){
|
||||
UserBusinessExample example = new UserBusinessExample();
|
||||
example.createCriteria().andKeyidEqualTo(userId).andTypeEqualTo("UserRole");
|
||||
List<UserBusiness> list = userBusinessMapper.selectByExample(example);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserBusiness> findAppByRoles(String roles){
|
||||
List<String> rolesList = StringUtil.strToStringList(roles);
|
||||
UserBusinessExample example = new UserBusinessExample();
|
||||
example.createCriteria().andKeyidIn(rolesList).andTypeEqualTo("RoleAPP");
|
||||
List<UserBusiness> list = userBusinessMapper.selectByExample(example);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -172,6 +172,24 @@ public class StringUtil {
|
||||
return idList;
|
||||
}
|
||||
|
||||
/**
|
||||
* String字符串转成List<String>数据格式
|
||||
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
||||
*
|
||||
* @param strArr
|
||||
* @return
|
||||
*/
|
||||
public static List<String> strToStringList(String strArr) {
|
||||
List<String> idList=new ArrayList<String>();
|
||||
String[] d=strArr.split(",");
|
||||
for (int i = 0, size = d.length; i < size; i++) {
|
||||
if(d[i]!=null) {
|
||||
idList.add(d[i].toString());
|
||||
}
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
public static List<String> searchCondition(String search) {
|
||||
if (isEmpty(search)) {
|
||||
return new ArrayList<String>();
|
||||
|
||||
Reference in New Issue
Block a user