完成用户管理
This commit is contained in:
parent
e42fa328b6
commit
f8cf93aebd
|
@ -0,0 +1,128 @@
|
|||
<%@ 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="createDialog" class="crudDialog">
|
||||
<form id="createForm" method="post">
|
||||
<div class="form-group">
|
||||
<label for="username">帐号</label>
|
||||
<input id="username" type="text" class="form-control" name="username" maxlength="20">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">密码</label>
|
||||
<input id="password" type="text" class="form-control" name="password" maxlength="32">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="realname">姓名</label>
|
||||
<input id="realname" type="text" class="form-control" name="realname" maxlength="20">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="avatar">头像</label>
|
||||
<input id="avatar" type="text" class="form-control" name="avatar" maxlength="50">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="phone">电话</label>
|
||||
<input id="phone" type="text" class="form-control" name="phone" maxlength="20">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">邮箱</label>
|
||||
<input id="email" type="text" class="form-control" name="email" maxlength="50">
|
||||
</div>
|
||||
<div>
|
||||
<label class="checkbox-inline">
|
||||
<label for="sex_1"><input id="sex_1" type="radio" name="sex" value="1" checked> 男</label>
|
||||
</label>
|
||||
<label class="checkbox-inline">
|
||||
<label for="sex_0"><input id="sex_0" type="radio" name="sex" value="0"> 女</label>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label class="checkbox-inline">
|
||||
<label for="locked_0"><input id="locked_0" type="radio" name="locked" value="0" checked> 正常</label>
|
||||
</label>
|
||||
<label class="checkbox-inline">
|
||||
<label for="locked_1"><input id="locked_1" type="radio" name="locked" value="1"> 锁定</label>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group text-right">
|
||||
<a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
|
||||
<a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function createSubmit() {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '${basePath}/manage/user/create',
|
||||
data: $('#createForm').serialize(),
|
||||
beforeSend: function() {
|
||||
if ($('#username').val() == '') {
|
||||
$('#username').focus();
|
||||
return false;
|
||||
}
|
||||
if ($('#password').val() == '' || $('#password').val().length < 5) {
|
||||
$('#password').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 {
|
||||
createDialog.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>
|
|
@ -29,35 +29,6 @@
|
|||
</div>
|
||||
<table id="table"></table>
|
||||
</div>
|
||||
<!-- 新增 -->
|
||||
<div id="createDialog" class="crudDialog" hidden>
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="input1">帐号</label>
|
||||
<input id="input1" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="input2">姓名</label>
|
||||
<input id="input2" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="input3">头像</label>
|
||||
<input id="input3" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="input4">电话</label>
|
||||
<input id="input4" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="input5">邮箱</label>
|
||||
<input id="input5" type="text" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="input6">性别</label>
|
||||
<input id="input6" type="text" class="form-control">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script src="${basePath}/resources/zheng-ui/plugins/jquery.1.12.4.min.js"></script>
|
||||
<script src="${basePath}/resources/zheng-ui/plugins/bootstrap-3.3.0/js/bootstrap.min.js"></script>
|
||||
<script src="${basePath}/resources/zheng-ui/plugins/bootstrap-table-1.11.0/bootstrap-table.min.js"></script>
|
||||
|
@ -98,7 +69,7 @@ $(function() {
|
|||
maintainSelected: true,
|
||||
toolbar: '#toolbar',
|
||||
columns: [
|
||||
{field: 'state', checkbox: true},
|
||||
{field: 'ck', checkbox: true},
|
||||
{field: 'userId', title: '编号', sortable: true, align: 'center'},
|
||||
{field: 'username', title: '帐号'},
|
||||
{field: 'realname', title: '姓名'},
|
||||
|
@ -106,12 +77,9 @@ $(function() {
|
|||
{field: 'phone', title: '电话'},
|
||||
{field: 'email', title: '邮箱'},
|
||||
{field: 'sex', title: '性别', formatter: 'sexFormatter'},
|
||||
{field: 'locked', title: '状态', sortable: true, align: 'center', formatter: 'statusFormatter'},
|
||||
{field: 'locked', title: '状态', sortable: true, align: 'center', formatter: 'lockedFormatter'},
|
||||
{field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
|
||||
]
|
||||
}).on('all.bs.table', function (e, name, args) {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
$('[data-toggle="popover"]').popover();
|
||||
});
|
||||
});
|
||||
// 格式化操作按钮
|
||||
|
@ -136,7 +104,7 @@ function sexFormatter(value, row, index) {
|
|||
return '-';
|
||||
}
|
||||
// 格式化状态
|
||||
function statusFormatter(value, row, index) {
|
||||
function lockedFormatter(value, row, index) {
|
||||
if (value == 1) {
|
||||
return '<span class="label label-danger">锁定</span>';
|
||||
} else {
|
||||
|
@ -144,34 +112,22 @@ function statusFormatter(value, row, index) {
|
|||
}
|
||||
}
|
||||
// 新增
|
||||
var createDialog;
|
||||
function createAction() {
|
||||
$.confirm({
|
||||
type: 'dark',
|
||||
createDialog = $.dialog({
|
||||
animationSpeed: 300,
|
||||
title: '新增用户',
|
||||
content: $('#createDialog').html(),
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: '确认',
|
||||
btnClass: 'waves-effect waves-button',
|
||||
action: function () {
|
||||
$.alert('确认');
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: '取消',
|
||||
btnClass: 'waves-effect waves-button'
|
||||
}
|
||||
}
|
||||
content: 'url:${basePath}/manage/user/create'
|
||||
});
|
||||
}
|
||||
// 编辑
|
||||
var updateDialog;
|
||||
function updateAction() {
|
||||
var rows = $table.bootstrapTable('getSelections');
|
||||
if (rows.length == 0) {
|
||||
if (rows.length != 1) {
|
||||
$.confirm({
|
||||
title: false,
|
||||
content: '请至少选择一条记录!',
|
||||
content: '请选择一条记录!',
|
||||
autoClose: 'cancel|3000',
|
||||
backgroundDismiss: true,
|
||||
buttons: {
|
||||
|
@ -182,28 +138,15 @@ function updateAction() {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
$.confirm({
|
||||
type: 'blue',
|
||||
updateDialog = $.dialog({
|
||||
animationSpeed: 300,
|
||||
title: '编辑用户',
|
||||
content: $('#createDialog').html(),
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: '确认',
|
||||
btnClass: 'waves-effect waves-button',
|
||||
action: function () {
|
||||
$.alert('确认');
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: '取消',
|
||||
btnClass: 'waves-effect waves-button'
|
||||
}
|
||||
}
|
||||
content: 'url:${basePath}/manage/user/update/' + rows[0].userId
|
||||
});
|
||||
}
|
||||
}
|
||||
// 删除
|
||||
var deleteDialog;
|
||||
function deleteAction() {
|
||||
var rows = $table.bootstrapTable('getSelections');
|
||||
if (rows.length == 0) {
|
||||
|
@ -220,7 +163,7 @@ function deleteAction() {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
$.confirm({
|
||||
deleteDialog = $.confirm({
|
||||
type: 'red',
|
||||
animationSpeed: 300,
|
||||
title: false,
|
||||
|
@ -234,7 +177,63 @@ function deleteAction() {
|
|||
for (var i in rows) {
|
||||
ids.push(rows[i].userId);
|
||||
}
|
||||
$.alert('删除:id=' + ids.join("-"));
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '${basePath}/manage/user/delete/' + ids.join("-"),
|
||||
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 {
|
||||
deleteDialog.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'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
<%@ 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="form-group">
|
||||
<label for="username">帐号</label>
|
||||
<input id="username" type="text" class="form-control" name="username" maxlength="20" value="${user.username}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">密码</label>
|
||||
<input id="password" type="text" class="form-control" name="password" maxlength="32" value="${user.password}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="realname">姓名</label>
|
||||
<input id="realname" type="text" class="form-control" name="realname" maxlength="20" value="${user.realname}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="avatar">头像</label>
|
||||
<input id="avatar" type="text" class="form-control" name="avatar" maxlength="50" value="${user.avatar}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="phone">电话</label>
|
||||
<input id="phone" type="text" class="form-control" name="phone" maxlength="20" value="${user.phone}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">邮箱</label>
|
||||
<input id="email" type="text" class="form-control" name="email" maxlength="50" value="${user.email}">
|
||||
</div>
|
||||
<div>
|
||||
<label class="checkbox-inline">
|
||||
<label for="sex_1"><input id="sex_1" type="radio" name="sex" value="1" <c:if test="${user.sex==1}">checked</c:if>> 男</label>
|
||||
</label>
|
||||
<label class="checkbox-inline">
|
||||
<label for="sex_0"><input id="sex_0" type="radio" name="sex" value="0" <c:if test="${user.sex==0}">checked</c:if>> 女</label>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label class="checkbox-inline">
|
||||
<label for="locked_0"><input id="locked_0" type="radio" name="locked" value="0" <c:if test="${user.locked==0}">checked</c:if>> 正常</label>
|
||||
</label>
|
||||
<label class="checkbox-inline">
|
||||
<label for="locked_1"><input id="locked_1" type="radio" name="locked" value="1" <c:if test="${user.locked==1}">checked</c:if>> 锁定</label>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group text-right">
|
||||
<a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
|
||||
<a class="waves-effect waves-button" href="javascript:;" onclick="updateDialog.close();">取消</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
function createSubmit() {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '${basePath}/manage/user/update/${user.userId}',
|
||||
data: $('#updateForm').serialize(),
|
||||
beforeSend: function() {
|
||||
if ($('#username').val() == '') {
|
||||
$('#username').focus();
|
||||
return false;
|
||||
}
|
||||
if ($('#password').val() == '' || $('#password').val().length < 5) {
|
||||
$('#password').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>
|
Loading…
Reference in New Issue