项目列表没有权限灰色显示,用户管理项目默认选择修改

This commit is contained in:
ArnoHand 2019-02-28 10:54:28 +08:00
parent 2a2ca4b2c6
commit 3a4868b806
7 changed files with 28 additions and 23 deletions

View File

@ -18,9 +18,6 @@ import javax.annotation.Resource;
@RequestMapping(value = "/")
public class IndexControl extends BaseController {
@Resource
private UserService userService;
@RequestMapping(value = "error", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
@NotLogin
public String error() {
@ -34,7 +31,6 @@ public class IndexControl extends BaseController {
*/
@RequestMapping(value = {"index", "", "index.html", "/"}, method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public String index() {
setAttribute("manager", userService.isManager("", getUserName()));
return "index";
}

View File

@ -55,13 +55,16 @@ public class ManageControl extends BaseController {
*/
@RequestMapping(value = "getProjectInfo")
@ResponseBody
public String getProjectInfo() {
public String getProjectInfo(String userId) {
try {
// 查询数据
JSONObject json = manageService.getAllProjectInfo();
// 转换为数据
List<JSONObject> array = new ArrayList<>();
Set<String> setKey = json.keySet();
if (StrUtil.isEmpty(userId)) {
userId = getUserName();
}
for (String asetKey : setKey) {
ProjectInfoModel projectInfoModel = manageService.getProjectInfo(asetKey);
String result = commandService.execCommand(CommandService.CommandOp.status, projectInfoModel);
@ -69,7 +72,7 @@ public class ManageControl extends BaseController {
projectInfoModel.setStatus(status);
String id = projectInfoModel.getId();
JSONObject object = (JSONObject) JSONObject.toJSON(projectInfoModel);
object.put("manager", userService.isManager(id, getUserName()));
object.put("manager", userService.isManager(id, userId));
array.add(object);
}
array.sort((o1, o2) -> {

View File

@ -44,7 +44,11 @@ public class UserInfoController extends BaseController {
* @return String
*/
@RequestMapping(value = "addUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String addUser(String id, String name, String role, String password) {
public String addUser(String id, String name, String manage, String password) {
boolean manager = userService.isManager("", getUserName());
if (!manager) {
return JsonMessage.getString(400, "你还没有权限");
}
if (StrUtil.isEmpty(id)) {
return JsonMessage.getString(400, "登录名不能为空");
}
@ -55,7 +59,7 @@ public class UserInfoController extends BaseController {
if (length < 6) {
return JsonMessage.getString(400, "密码长度为6-12位");
}
boolean b = userService.addUser(id, name, password);
boolean b = userService.addUser(id, name, password, "true".equals(manage));
if (b) {
return JsonMessage.getString(200, "添加成功");
}

View File

@ -188,14 +188,16 @@ public class UserService extends BaseDataService {
* @param id 用户登录名
* @param name 昵称
* @param password 密码
* @param manage 是否是管理员
* @return true
*/
public boolean addUser(String id, String name, String password) {
public boolean addUser(String id, String name, String password, boolean manage) {
try {
UserModel userModel = new UserModel();
userModel.setName(name);
userModel.setId(id);
userModel.setPassword(password);
userModel.setManage(manage);
return addUser(userModel);
} catch (Exception e) {
DefaultSystemLog.LOG().error(e.getMessage(), e);

View File

@ -35,8 +35,7 @@
<a href="javascript:;" data-options="{'id':'manage', 'title':'项目管理', 'url':'/manage/projectInfo'}">项目管理</a>
</li>
<li class="layui-nav-item">
<a href="javascript:;"
#if($manager)data-options="{'id':'user', 'title':'用户管理', 'url':'/user/list'}" #end>用户管理</a>
<a href="javascript:;" data-options="{'id':'user', 'title':'用户管理', 'url':'/user/list'}">用户管理</a>
</li>
</ul>
</div>
@ -104,9 +103,6 @@
} catch (e) {
options = eval('(' + dataJSON + ')');
}
if (!options) {
return;
}
tabChange(options);
});

View File

@ -126,7 +126,7 @@
if (!d.manager) {
rgb = [211, 211, 211];
}
return "<div title='" + d.group + "(" + d.id + ")' style='background: rgb(" + rgb + ");color: #fff;margin: 0 -15px;padding: 0 15px;'>" + (d.runLibDesc || "") + " / " + (d.useLibDesc || "") + "</div>";
return "<div name='" + d.id + "' title='" + d.group + "(" + d.id + ")' style='background: rgb(" + rgb + ");color: #fff;margin: 0 -15px;padding: 0 15px;'>" + (d.runLibDesc || "") + " / " + (d.useLibDesc || "") + "</div>";
}
},
{field: 'createTime', title: '创建时间', width: '13%'},
@ -139,6 +139,13 @@
statusCode: 200
},
done: function (data) {
var projects = data.data;
for (var i = 0; i < projects.length; i++) {
var project = projects[i];
if (!project.manager) {
$('tr[data-index="' + i + '"').css('background-color', 'rgb(211,211,211)');
}
}
}
});

View File

@ -93,8 +93,8 @@
<div class="layui-inline">
<label class="layui-form-label">管理项目</label>
{{# layui.each(d.data, function(index, item){ }}
<input type="checkbox" name="project" value={{ item.id }} title={{ item.name }} {{# if(item.manager){ }}
checked {{# } }}>
<input type="checkbox" name="project" value="{{= item.id }}"
title="{{= item.name }}" {{# if(item.manager){ }} checked {{# } }}>
{{# }); }}
</div>
</div>
@ -131,18 +131,15 @@
document.getElementById('form_user').reset();
$('#form_user [name="id"]').attr('readonly', true).addClass('layui-disabled');
// 设置表单值
var projects = [];
for (var key in data) {
if ("manage" === key) {
if (true === data[key])
$('#form_user [name="manage"]').attr('checked', true);
} else if ("projects" === key) {
projects = data[key];
} else {
$('#form_user [name="' + key + '"]').val(data[key]);
}
}
getProject(projects);
getProject(data.id);
// 弹出
layer.open({
type: 1,
@ -159,12 +156,12 @@
}
function getProject(projects) {
var length = projects.length;
function getProject(userId) {
$.ajax({
url: "/manage/getProjectInfo",
type: 'POST',
dataType: 'json',
data: {userId: userId},
success: function (data) {
if (200 == data.code) {
var manager = manageProject.innerHTML;