完成权限管理

This commit is contained in:
shuzheng 2017-02-26 14:33:34 +08:00
parent 8d449c2b14
commit 1ccc192ca9
9 changed files with 406 additions and 45 deletions

View File

@ -17,6 +17,7 @@ body{font-size: 12px;}
.jconfirm .jconfirm-box .jconfirm-buttons button{-webkit-border-radius: 0; border-radius: 0;}
.btn:active{-webkit-box-shadow: none; box-shadow: none;}
/* input */
body .jconfirm{z-index: 999;}
.jconfirm-content form{margin-top: 10px;}
.crudDialog{padding: 0 0 2px;}
.dialog-buttons a{font-weight: bold;}

View File

@ -60,12 +60,16 @@ public class UpmsPermissionController extends BaseController {
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
@RequestParam(required = false, defaultValue = "0", value = "type") int type,
@RequestParam(required = false, defaultValue = "0", value = "systemId") int systemId,
@RequestParam(required = false, value = "sort") String sort,
@RequestParam(required = false, value = "order") String order) {
UpmsPermissionExample upmsPermissionExample = new UpmsPermissionExample();
UpmsPermissionExample.Criteria criteria = upmsPermissionExample.createCriteria();
if (0 != type) {
upmsPermissionExample.createCriteria()
.andTypeEqualTo((byte) type);
criteria.andTypeEqualTo((byte) type);
}
if (0 != systemId) {
criteria.andSystemIdEqualTo(systemId);
}
upmsPermissionExample.setOffset(offset);
upmsPermissionExample.setLimit(limit);
@ -124,8 +128,13 @@ public class UpmsPermissionController extends BaseController {
@RequiresPermissions("upms:permission:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
public String update(@PathVariable("id") int id, ModelMap modelMap) {
UpmsSystemExample upmsSystemExample = new UpmsSystemExample();
upmsSystemExample.createCriteria()
.andStatusEqualTo((byte) 1);
List<UpmsSystem> upmsSystems = upmsSystemService.selectByExample(upmsSystemExample);
UpmsPermission permission = upmsPermissionService.selectByPrimaryKey(id);
modelMap.put("permission", permission);
modelMap.put("upmsSystems", upmsSystems);
return "/manage/permission/update";
}

View File

@ -11,52 +11,56 @@
<div class="radio">
<div class="radio radio-inline radio-success">
<input id="type_1" type="radio" name="type" value="1" checked>
<label for="type_1"> 目录 </label>
<label for="type_1">目录 </label>
</div>
<div class="radio radio-inline radio-info">
<input id="type_2" type="radio" name="type" value="0">
<label for="type_2"> 菜单 </label>
<input id="type_2" type="radio" name="type" value="2">
<label for="type_2">菜单 </label>
</div>
<div class="radio radio-inline radio-warning">
<input id="type_3" type="radio" name="type" value="0">
<label for="type_3"> 按钮 </label>
<input id="type_3" type="radio" name="type" value="3">
<label for="type_3">按钮 </label>
</div>
</div>
<div class="form-group">
<select id="systemId" name="systemId">
<option value="0">请选择所属系统</option>
<c:forEach var="upmsSystem" items="${upmsSystems}">
<option value="${upmsSystem.systemId}">${upmsSystem.title}</option>
</c:forEach>
</select>
<select id="pid" name="pid">
<option value="0">请选择所属上级</option>
</select>
<span class="type1 type2 type3">
<select id="systemId" name="systemId">
<option value="0">请选择系统</option>
<c:forEach var="upmsSystem" items="${upmsSystems}">
<option value="${upmsSystem.systemId}">${upmsSystem.title}</option>
</c:forEach>
</select>
</span>
<span class="type2 type3" hidden>
<select id="pid" name="pid">
<option value="0">请选择上级</option>
</select>
</span>
</div>
<div class="form-group">
<label for="name">名称</label>
<input id="name" type="text" class="form-control" name="name" maxlength="20">
</div>
<div class="form-group">
<div class="form-group type2 type3" hidden>
<label for="permissionValue">权限值</label>
<input id="permissionValue" type="text" class="form-control" name="permissionValue" maxlength="50">
</div>
<div class="form-group">
<div class="form-group type2 type3" hidden>
<label for="uri">路径</label>
<input id="uri" type="text" class="form-control" name="uri" maxlength="100">
</div>
<div class="form-group">
<div class="form-group type1 type3">
<label for="icon">图标</label>
<input id="icon" type="text" class="form-control" name="icon" maxlength="50">
<input id="icon" type="text" class="form-control" name="icon" maxlength="50" value="zmdi zmdi-widgets">
</div>
<div class="radio">
<div class="radio radio-inline radio-success">
<input id="status_1" type="radio" name="status" value="1" checked>
<label for="status_1"> 正常 </label>
<label for="status_1">正常 </label>
</div>
<div class="radio radio-inline">
<input id="status_0" type="radio" name="status" value="0">
<label for="status_0"> 锁定 </label>
<label for="status_0">锁定 </label>
</div>
</div>
<div class="form-group text-right dialog-buttons">
@ -66,20 +70,114 @@
</form>
</div>
<script>
var pidType = 0;
var systemId = 0;
var type = 1;
$(function() {
// 选择分类
$('input:radio[name="type"]').change(function() {
type = $(this).val();
initType();
});
// 选择系统
$('#systemId').change(function() {
systemId = $(this).val();
initPid();
});
});
function initType() {
// 显示对应必填项
$('.type1,.type2,.type3').hide(0, function () {
$('.type' + type).show();
});
// 级联菜单
if (type == 2) {
pidType = 1;
initPid();
}
if (type == 3) {
pidType = 2
initPid();
}
}
function initPid() {
if (systemId != 0) {
$.getJSON('${basePath}/manage/permission/list', {systemId: systemId, type: pidType, limit: 10000}, function(json) {
var datas = [{id: 0, text: '请选择上级'}];
for (var i = 0; i < json.rows.length; i ++) {
var data = {};
data.id = json.rows[i].permissionId;
data.text = json.rows[i].name;
datas.push(data);
}
$('#pid').empty();
$('#pid').select2({
data : datas
});
});
} else {
$('#pid').empty();
$('#pid').select2({
data : [{id: 0, text: '请选择上级'}]
});
}
}
function createSubmit() {
$.ajax({
type: 'post',
url: '${basePath}/manage/user/create',
url: '${basePath}/manage/permission/create',
data: $('#createForm').serialize(),
beforeSend: function() {
if ($('#username').val() == '') {
$('#username').focus();
return false;
}
if ($('#password').val() == '' || $('#password').val().length < 5) {
$('#password').focus();
return false;
}
if ($('#systemId').val() == 0) {
$.confirm({
title: false,
content: '请选择系统!',
autoClose: 'cancel|3000',
backgroundDismiss: true,
buttons: {
cancel: {
text: '取消',
btnClass: 'waves-effect waves-button'
}
}
});
return false;
}
if (type == 1) {
if ($('#name').val() == '') {
$('#name').focus();
return false;
}
}
if (type == 2 || type == 3) {
if ($('#pid').val() == 0) {
$.confirm({
title: false,
content: '请选择上级!',
autoClose: 'cancel|3000',
backgroundDismiss: true,
buttons: {
cancel: {
text: '取消',
btnClass: 'waves-effect waves-button'
}
}
});
return false;
}
if ($('#name').val() == '') {
$('#name').focus();
return false;
}
if ($('#permissionValue').val() == '') {
$('#permissionValue').focus();
return false;
}
if ($('#uri').val() == '') {
$('#uri').focus();
return false;
}
}
},
success: function(result) {
if (result.code != 1) {

View File

@ -94,7 +94,7 @@ function statusFormatter(value, row, index) {
if (value == 1) {
return '<span class="label label-success">正常</span>';
} else {
return '<span class="label label-danger">锁定</span>';
return '<span class="label label-default">锁定</span>';
}
}
// 新增
@ -106,7 +106,7 @@ function createAction() {
content: 'url:${basePath}/manage/permission/create',
onContentReady: function () {
initMaterialInput();
$('select').select2();
$('select').select2({placeholder: "Select a state"});
}
});
}
@ -135,6 +135,8 @@ function updateAction() {
onContentReady: function () {
initMaterialInput();
$('select').select2();
initType();
initSelect2();
}
});
}

View File

@ -0,0 +1,251 @@
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="updateDialog" class="crudDialog">
<form id="updateForm" method="post">
<div class="radio">
<div class="radio radio-inline radio-success">
<input id="type_1" type="radio" name="type" value="1" <c:if test="${permission.type==1}">checked</c:if>>
<label for="type_1">目录 </label>
</div>
<div class="radio radio-inline radio-info">
<input id="type_2" type="radio" name="type" value="2" <c:if test="${permission.type==2}">checked</c:if>>
<label for="type_2">菜单 </label>
</div>
<div class="radio radio-inline radio-warning">
<input id="type_3" type="radio" name="type" value="3" <c:if test="${permission.type==3}">checked</c:if>>
<label for="type_3">按钮 </label>
</div>
</div>
<div class="form-group">
<span class="type1 type2 type3">
<select id="systemId" name="systemId">
<option value="0">请选择系统</option>
<c:forEach var="upmsSystem" items="${upmsSystems}">
<option value="${upmsSystem.systemId}" <c:if test="${permission.systemId==upmsSystem.systemId}">selected="selected"</c:if>>${upmsSystem.title}</option>
</c:forEach>
</select>
</span>
<span class="type2 type3" hidden>
<select id="pid" name="pid">
<option value="0">请选择上级</option>
</select>
</span>
</div>
<div class="form-group">
<label for="name">名称</label>
<input id="name" type="text" class="form-control" name="name" maxlength="20" value="${permission.name}">
</div>
<div class="form-group type2 type3" hidden>
<label for="permissionValue">权限值</label>
<input id="permissionValue" type="text" class="form-control" name="permissionValue" maxlength="50" value="${permission.permissionValue}">
</div>
<div class="form-group type2 type3" hidden>
<label for="uri">路径</label>
<input id="uri" type="text" class="form-control" name="uri" maxlength="100" value="${permission.uri}">
</div>
<div class="form-group type1 type3">
<label for="icon">图标</label>
<input id="icon" type="text" class="form-control" name="icon" maxlength="50" value="${permission.icon}">
</div>
<div class="radio">
<div class="radio radio-inline radio-success">
<input id="status_1" type="radio" name="status" value="1" <c:if test="${permission.status==1}">checked</c:if>>
<label for="status_1">正常 </label>
</div>
<div class="radio radio-inline">
<input id="status_0" type="radio" name="status" value="0" <c:if test="${permission.status==0}">checked</c:if>>
<label for="status_0">锁定 </label>
</div>
</div>
<div class="form-group text-right dialog-buttons">
<a class="waves-effect waves-button" href="javascript:;" onclick="updateSubmit();">保存</a>
<a class="waves-effect waves-button" href="javascript:;" onclick="updateDialog.close();">取消</a>
</div>
</form>
</div>
<script>
var pidType = 0;
var systemId = ${permission.systemId};
var type = ${permission.type};
$(function() {
// 选择分类
$('input:radio[name="type"]').change(function() {
type = $(this).val();
initType();
});
// 选择系统
$('#systemId').change(function() {
systemId = $(this).val();
initPid();
});
});
function initType() {
// 显示对应必填项
$('.type1,.type2,.type3').hide(0, function () {
$('.type' + type).show();
});
// 级联菜单
if (type == 2) {
pidType = 1;
initPid();
}
if (type == 3) {
pidType = 2
initPid();
}
}
function initPid(val) {
if (systemId != 0) {
$.getJSON('${basePath}/manage/permission/list', {systemId: systemId, type: pidType, limit: 10000}, function(json) {
var datas = [{id: 0, text: '请选择上级'}];
for (var i = 0; i < json.rows.length; i ++) {
var data = {};
data.id = json.rows[i].permissionId;
data.text = json.rows[i].name;
datas.push(data);
}
$('#pid').empty();
$('#pid').select2({
data : datas
});
if (!!val) {
console.log(val);
//$('#pid').select2('val', val);
$('#pid').select2().val(val).trigger('change');
}
});
} else {
$('#pid').empty();
$('#pid').select2({
data : [{id: 0, text: '请选择上级'}]
});
}
}
function initSelect2() {
if (type == 2) {
pidType = 1;
}
if (type == 3) {
pidType = 2
}
initPid(${permission.pid});
}
function updateSubmit() {
$.ajax({
type: 'post',
url: '${basePath}/manage/permission/update/${permission.permissionId}',
data: $('#updateForm').serialize(),
beforeSend: function() {
if ($('#systemId').val() == 0) {
$.confirm({
title: false,
content: '请选择系统!',
autoClose: 'cancel|3000',
backgroundDismiss: true,
buttons: {
cancel: {
text: '取消',
btnClass: 'waves-effect waves-button'
}
}
});
return false;
}
if (type == 1) {
if ($('#name').val() == '') {
$('#name').focus();
return false;
}
}
if (type == 2 || type == 3) {
if ($('#pid').val() == 0) {
$.confirm({
title: false,
content: '请选择上级!',
autoClose: 'cancel|3000',
backgroundDismiss: true,
buttons: {
cancel: {
text: '取消',
btnClass: 'waves-effect waves-button'
}
}
});
return false;
}
if ($('#name').val() == '') {
$('#name').focus();
return false;
}
if ($('#permissionValue').val() == '') {
$('#permissionValue').focus();
return false;
}
if ($('#uri').val() == '') {
$('#uri').focus();
return false;
}
}
},
success: function(result) {
if (result.code != 1) {
if (result.data instanceof Array) {
$.each(result.data, function(index, value) {
$.confirm({
theme: 'dark',
animation: 'rotateX',
closeAnimation: 'rotateX',
title: false,
content: value.errorMsg,
buttons: {
confirm: {
text: '确认',
btnClass: 'waves-effect waves-button waves-light'
}
}
});
});
} else {
$.confirm({
theme: 'dark',
animation: 'rotateX',
closeAnimation: 'rotateX',
title: false,
content: result.data.errorMsg,
buttons: {
confirm: {
text: '确认',
btnClass: 'waves-effect waves-button waves-light'
}
}
});
}
} else {
updateDialog.close();
$table.bootstrapTable('refresh');
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$.confirm({
theme: 'dark',
animation: 'rotateX',
closeAnimation: 'rotateX',
title: false,
content: textStatus,
buttons: {
confirm: {
text: '确认',
btnClass: 'waves-effect waves-button waves-light'
}
}
});
}
});
}
</script>

View File

@ -31,11 +31,11 @@
<div class="radio">
<div class="radio radio-inline radio-success">
<input id="status_1" type="radio" name="status" value="1" checked>
<label for="status_1"> 正常 </label>
<label for="status_1">正常 </label>
</div>
<div class="radio radio-inline">
<input id="status_0" type="radio" name="status" value="-1">
<label for="status_0"> 锁定 </label>
<label for="status_0">锁定 </label>
</div>
</div>
<div class="form-group text-right dialog-buttons">

View File

@ -31,11 +31,11 @@
<div class="radio">
<div class="radio radio-inline radio-success">
<input id="status_1" type="radio" name="status" value="1" <c:if test="${system.status==1}">checked</c:if>>
<label for="status_1"> 正常 </label>
<label for="status_1">正常 </label>
</div>
<div class="radio radio-inline">
<input id="status_0" type="radio" name="status" value="-1" <c:if test="${system.status!=1}">checked</c:if>>
<label for="status_0"> 锁定 </label>
<label for="status_0">锁定 </label>
</div>
</div>
<div class="form-group text-right dialog-buttons">

View File

@ -35,19 +35,19 @@
<div class="radio">
<div class="radio radio-inline radio-info">
<input id="sex_1" type="radio" name="sex" value="1" checked>
<label for="sex_1"> 男 </label>
<label for="sex_1">男 </label>
</div>
<div class="radio radio-inline radio-danger">
<input id="sex_0" type="radio" name="sex" value="0">
<label for="sex_0"> 女 </label>
<label for="sex_0">女 </label>
</div>
<div class="radio radio-inline radio-success">
<input id="locked_0" type="radio" name="locked" value="0" checked>
<label for="locked_0"> 正常 </label>
<label for="locked_0">正常 </label>
</div>
<div class="radio radio-inline">
<input id="locked_1" type="radio" name="locked" value="1">
<label for="locked_1"> 锁定 </label>
<label for="locked_1">锁定 </label>
</div>
</div>
<div class="form-group text-right dialog-buttons">

View File

@ -35,19 +35,19 @@
<div class="radio">
<div class="radio radio-inline radio-info">
<input id="sex_1" type="radio" name="sex" value="1" <c:if test="${user.sex==1}">checked</c:if>>
<label for="sex_1"> 男 </label>
<label for="sex_1">男 </label>
</div>
<div class="radio radio-inline radio-danger">
<input id="sex_0" type="radio" name="sex" value="0" <c:if test="${user.sex==0}">checked</c:if>>
<label for="sex_0"> 女 </label>
<label for="sex_0">女 </label>
</div>
<div class="radio radio-inline radio-success">
<input id="locked_0" type="radio" name="locked" value="0" <c:if test="${user.locked==0}">checked</c:if>>
<label for="locked_0"> 正常 </label>
<label for="locked_0">正常 </label>
</div>
<div class="radio radio-inline">
<input id="locked_1" type="radio" name="locked" value="1" <c:if test="${user.locked==1}">checked</c:if>>
<label for="locked_1"> 锁定 </label>
<label for="locked_1">锁定 </label>
</div>
</div>
<div class="form-group text-right dialog-buttons">