|
|
<%--
|
|
|
Created by IntelliJ IDEA.
|
|
|
User: hkw
|
|
|
Date: 2018/10/31
|
|
|
Time: 14:06
|
|
|
To change this template use File | Settings | File Templates.
|
|
|
--%>
|
|
|
<%@ page contentType="text/html;charset=UTF-8" language="java" import="com.itheima.po.Admin" %>
|
|
|
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
|
|
|
|
|
|
<html>
|
|
|
<head>
|
|
|
<title>后台登录</title>
|
|
|
<!-- 设置页面相关元数据 -->
|
|
|
<meta name="renderer" content="webkit|ie-comp|ie-stand">
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
|
|
|
<%--<meta http-equiv="Cache-Control" content="no-siteapp" />--%>
|
|
|
|
|
|
<!-- 引入图标 -->
|
|
|
<link rel="icon" href="/images/favicon.ico" sizes="32x32" />
|
|
|
<!-- 引入CSS样式文件 -->
|
|
|
<link rel="stylesheet" href="/css/font.css">
|
|
|
<link rel="stylesheet" href="/css/xadmin.css">
|
|
|
<!-- 引入JavaScript脚本文件 -->
|
|
|
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
|
|
|
<script src="/lib/layui/layui.js"></script>
|
|
|
<script type="text/javascript" src="/js/xadmin.js"></script>
|
|
|
<script src="/layui_exts/excel.js"></script>
|
|
|
|
|
|
<!-- 自定义样式 -->
|
|
|
<style type="text/css">
|
|
|
.layui-table{
|
|
|
text-align: center;
|
|
|
}
|
|
|
.layui-table th{
|
|
|
text-align: center;
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
<div class="x-nav">
|
|
|
<!-- 面包屑导航 -->
|
|
|
<span class="layui-breadcrumb">
|
|
|
<a href="">首页</a>
|
|
|
<a href="/findAdmin">管理员信息</a>
|
|
|
</span>
|
|
|
<!-- 刷新按钮 -->
|
|
|
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="/findAdmin" title="刷新">
|
|
|
<i class="layui-icon" style="line-height:30px">ဂ</i></a>
|
|
|
</div>
|
|
|
<div class="x-body">
|
|
|
<div class="layui-row">
|
|
|
<!-- 搜索表单 -->
|
|
|
<form class="layui-form layui-col-md12 x-so" action="/findAdmin" >
|
|
|
<input type="hidden" class="layui-input" placeholder="请输入用户名" name="a_id" id="a_id">
|
|
|
<input class="layui-input" placeholder="请输入用户名" name="a_username" id="a_username">
|
|
|
<input class="layui-input" placeholder="请输入级别描述" name="a_describe" id="a_describe" >
|
|
|
|
|
|
<!-- 分页信息,隐藏字段 -->
|
|
|
<input class="layui-input" type="hidden" name="pageIndex" value="1">
|
|
|
<input class="layui-input" type="hidden" name="pageSize" value="3">
|
|
|
<!-- 搜索按钮 -->
|
|
|
<button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon"></i></button>
|
|
|
</form>
|
|
|
</div>
|
|
|
|
|
|
<xblock>
|
|
|
<!-- 添加管理员按钮 -->
|
|
|
<button id="addStudnetBtn" class="layui-btn layui-btn-normal"> <i class="layui-icon"></i>添加</button>
|
|
|
<!-- 导出按钮 -->
|
|
|
<button class="layui-btn layui-btn-warm" lay-filter="toolbarDemo" lay-submit=""><i class="layui-icon"></i>导出</button>
|
|
|
<!-- 显示数据总数 -->
|
|
|
<span class="x-right" style="line-height:40px">共有数据:${ai.totalCount} 条</span>
|
|
|
</xblock>
|
|
|
|
|
|
<%--表格数据--%>
|
|
|
<table class="layui-table" >
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<%--<th>--%>
|
|
|
<%--<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>--%>
|
|
|
<%--</th>--%>
|
|
|
<th>ID</th>
|
|
|
<th>用户名</th>
|
|
|
<%--<th>密码</th>--%>
|
|
|
<th>姓名</th>
|
|
|
<th>电话</th>
|
|
|
<%--<th>级别</th>--%>
|
|
|
<th>级别描述</th>
|
|
|
<th>操作</th>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
<!-- 循环遍历管理员信息列表,为每个管理员生成一行数据 -->
|
|
|
<c:forEach items="${ai.list}" var="ai">
|
|
|
<tr>
|
|
|
<%--<td>--%>
|
|
|
<%--<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon"></i></div>--%>
|
|
|
<%--</td>--%>
|
|
|
<td class="myid">${ai.a_id}</td>
|
|
|
<!-- 显示管理员ID -->
|
|
|
<td>${ai.a_username}</td>
|
|
|
<!-- 显示管理员用户名 -->
|
|
|
<%--<td>${ai.a_password}</td>--%> <!-- 注释掉密码显示 -->
|
|
|
<td>${ai.a_name}</td>
|
|
|
<!-- 显示管理员姓名 -->
|
|
|
<td>${ai.a_phone}</td>
|
|
|
<!-- 显示管理员电话 -->
|
|
|
<%--<td>${ai.a_power}</td>--%> <!-- 注释掉级别显示 -->
|
|
|
<td>${ai.a_describe}</td> <!-- 显示管理员级别描述 -->
|
|
|
<td class="td-manage">
|
|
|
<!-- 编辑和删除按钮 -->
|
|
|
<a title="编辑" class="updateEdit" href="#">
|
|
|
<i class="layui-icon"></i>
|
|
|
</a>
|
|
|
<a title="删除" onclick="member_del(this,'${ai.a_id}','${ai.a_power}')" href="javascript:;">
|
|
|
<i class="layui-icon"></i>
|
|
|
</a>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</c:forEach>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
|
|
|
<%--添加模态框--%>
|
|
|
<div class="layui-row" id="test" style="display: none;">
|
|
|
<div class="layui-col-md10">
|
|
|
<form class="layui-form" id="addEmployeeForm">
|
|
|
<div class="layui-form-item">
|
|
|
<label class="layui-form-label">用户名:</label>
|
|
|
<div class="layui-input-block">
|
|
|
<input type="text" name="a_username" class="layui-input" placeholder="请输入用户名">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
<label class="layui-form-label">密码:</label>
|
|
|
<div class="layui-input-block">
|
|
|
<input type="password" lay-verify="required" name="a_password" class="layui-input" placeholder="请输入密码">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
<label class="layui-form-label">姓名:</label>
|
|
|
<div class="layui-input-block">
|
|
|
<input type="text" name="a_name" class="layui-input" placeholder="请输入姓名">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
<label class="layui-form-label">电话:</label>
|
|
|
<div class="layui-input-block">
|
|
|
<input type="text" name="a_phone" class="layui-input" placeholder="请输入电话">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
<label class="layui-form-label">级别:</label>
|
|
|
<div class="layui-input-block">
|
|
|
<input type="text" lay-verify="required" name="a_power" class="layui-input" placeholder="请输入级别1-2">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
<label class="layui-form-label">级别描述:</label>
|
|
|
<div class="layui-input-block">
|
|
|
<input type="text" name="a_describe" class="layui-input" placeholder="请输入级别描述">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
<div class="layui-input-block">
|
|
|
<button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">提交</button>
|
|
|
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</form>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="" >
|
|
|
<input type="hidden" id="totalPageCount" value="${ai.pageTotalCount}"/>
|
|
|
<c:import url="pageBtn.jsp">
|
|
|
<c:param name="totalCount" value="${ai.totalCount}"/>
|
|
|
<c:param name="currentPageNo" value="${ai.pageIndex}"/>
|
|
|
<c:param name="totalPageCount" value="${ai.pageTotalCount}"/>
|
|
|
</c:import>
|
|
|
</div>
|
|
|
</div>
|
|
|
<script>
|
|
|
|
|
|
// 配置layui的扩展模块路径
|
|
|
layui.config({
|
|
|
base: 'layui_exts/',
|
|
|
// 设置扩展模块的路径
|
|
|
}).extend({
|
|
|
excel: 'excel',
|
|
|
// 添加excel模块
|
|
|
});
|
|
|
|
|
|
// 使用layui模块
|
|
|
layui.use(['jquery', 'excel', 'form', 'layer', 'laydate'], function(){
|
|
|
var form = layui.form,
|
|
|
// 获取form模块
|
|
|
$ = layui.jquery,
|
|
|
// 获取jQuery模块
|
|
|
laydate = layui.laydate;
|
|
|
// 获取laydate模块
|
|
|
var excel = parent.layui.excel;
|
|
|
// 获取父页面的excel模块
|
|
|
|
|
|
// 初始化laydate日期选择器
|
|
|
laydate.render({
|
|
|
elem: '#start'
|
|
|
// 指定绑定日期选择器的元素
|
|
|
});
|
|
|
form.render();
|
|
|
// 重新渲染表单元素,以便layui能够识别新的表单元素
|
|
|
|
|
|
// 监听表单提交事件
|
|
|
form.on('submit(toolbarDemo)', function(){
|
|
|
// 发起ajax请求,获取导出数据
|
|
|
$.ajax({
|
|
|
url: '/exportadminlist',
|
|
|
// 请求的URL
|
|
|
type: 'post',
|
|
|
// 请求类型
|
|
|
dataType: 'json',
|
|
|
// 预期服务器返回的数据类型
|
|
|
contentType: "application/json; charset=utf-8",
|
|
|
// 发送信息至服务器时内容编码类型
|
|
|
success: function (data) {
|
|
|
// 请求成功后的回调函数
|
|
|
console.log(data);
|
|
|
// 在控制台打印返回的数据
|
|
|
|
|
|
// 1. 调整导出数据的顺序
|
|
|
var dt = excel.filterExportData(data, [
|
|
|
'a_id',
|
|
|
// ID
|
|
|
'a_username',
|
|
|
// 用户名
|
|
|
'a_name',
|
|
|
// 姓名
|
|
|
'a_phone',
|
|
|
// 电话
|
|
|
'a_describe'
|
|
|
// 级别描述
|
|
|
]);
|
|
|
|
|
|
// 2. 在数据数组头部添加表头信息
|
|
|
dt.unshift({
|
|
|
a_id: 'ID',
|
|
|
a_username: '用户名',
|
|
|
a_name: '姓名',
|
|
|
a_phone: '电话',
|
|
|
a_describe: '级别描述'
|
|
|
});
|
|
|
|
|
|
// 3. 设置列宽配置
|
|
|
var colConf = excel.makeColConfig({
|
|
|
'A': 40,
|
|
|
// A列宽度40px
|
|
|
'D': 90
|
|
|
// D列宽度90px
|
|
|
}, 60);
|
|
|
// 其他未定义列的默认宽度为60px
|
|
|
|
|
|
// 4. 记录开始时间
|
|
|
var timestart = Date.now();
|
|
|
|
|
|
// 5. 执行导出函数,系统会弹出下载框
|
|
|
excel.exportExcel({
|
|
|
sheet1: dt
|
|
|
// 数据
|
|
|
}, '管理员数据.xlsx', 'xlsx', {
|
|
|
// 文件名和类型
|
|
|
extend: {
|
|
|
'!cols': colConf
|
|
|
// 列配置
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 6. 记录结束时间
|
|
|
var timeend = Date.now();
|
|
|
|
|
|
// 7. 计算耗时
|
|
|
var spent = (timeend - timestart) / 1000;
|
|
|
layer.alert('导出耗时 '+spent+' s');
|
|
|
// 弹出耗时信息
|
|
|
//setTimeout(function () {window.location.href='/findAdmin';},2000); // 2秒后跳转页面
|
|
|
},
|
|
|
error: function () {
|
|
|
// 请求失败后的回调函数
|
|
|
//console.log(data);
|
|
|
// 在控制台打印错误信息
|
|
|
setTimeout(function () {window.location.href='/findAdmin';},2000);
|
|
|
// 2秒后跳转页面
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
// 当点击添加管理员按钮时,打开一个弹出层
|
|
|
$("#addStudnetBtn").click(function () {
|
|
|
// 使用layer.open方法打开一个弹出层
|
|
|
layer.open({
|
|
|
type: 1,
|
|
|
// 类型为页面层
|
|
|
title: "添加管理员",
|
|
|
// 弹出层的标题
|
|
|
skin: "myclass",
|
|
|
// 弹出层的皮肤样式
|
|
|
area: ["50%"],
|
|
|
// 弹出层的宽度,这里设置为屏幕宽度的50%
|
|
|
anim: 2,
|
|
|
// 弹出层的动画效果
|
|
|
content: $("#test").html()
|
|
|
// 弹出层的内容,这里是通过jQuery选择器获取的HTML内容
|
|
|
});
|
|
|
// 重置表单
|
|
|
$("#addEmployeeForm")[0].reset();
|
|
|
// 监听表单提交事件
|
|
|
form.on('submit(formDemo)', function(data) {
|
|
|
// 可以在这里使用layer.msg显示消息提示,这里被注释掉了
|
|
|
// layer.msg('aaa',{icon:1,time:3000});
|
|
|
var param = data.field; // 获取表单数据
|
|
|
// console.log(JSON.stringify(param)); // 在控制台打印表单数据,这里被注释掉了
|
|
|
|
|
|
// 发起ajax请求,提交表单数据
|
|
|
$.ajax({
|
|
|
url: '/addAdmin', // 请求的URL
|
|
|
type: "post",
|
|
|
// 请求类型
|
|
|
data: JSON.stringify(param),
|
|
|
// 发送到服务器的数据,这里是表单数据的JSON字符串
|
|
|
contentType: "application/json; charset=utf-8",
|
|
|
// 发送信息至服务器时内容编码类型
|
|
|
success: function(da){
|
|
|
// 请求成功后的回调函数
|
|
|
console.log(da);
|
|
|
// 在控制台打印服务器返回的数据
|
|
|
layer.msg('添加成功', {icon: 1, time: 2000});
|
|
|
// 显示成功消息提示
|
|
|
setTimeout(function () {window.location.href='/findAdmin';},2000);
|
|
|
// 2秒后跳转到管理员列表页面
|
|
|
},
|
|
|
error: function(){
|
|
|
// 请求失败后的回调函数
|
|
|
layer.msg('添加失败',{icon:0,time:2000});
|
|
|
// 显示失败消息提示
|
|
|
setTimeout(function () {window.location.href='/findAdmin';},2000);
|
|
|
// 2秒后跳转到管理员列表页面
|
|
|
}
|
|
|
});
|
|
|
// return false; // 阻止表单默认提交行为,这里被注释掉了
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*编辑*/
|
|
|
$(".updateEdit").click(function () {
|
|
|
var myid = $(this).parent("td").parent("tr").children(".myid").html();
|
|
|
//判断
|
|
|
// 获取当前行的管理员ID
|
|
|
var admin_id = ${sessionScope.ad.a_id};
|
|
|
// 获取当前登录管理员的ID
|
|
|
if(admin_id != myid){
|
|
|
// 判断当前登录管理员是否有权限编辑
|
|
|
layer.alert("对不起,您没有权限:(");
|
|
|
// 如果没有权限,弹出提示框
|
|
|
}else {
|
|
|
<%--window.location.href = "/findAdminById?a_id=${ai.a_id}";--%>
|
|
|
window.location.href = "/findAdminById?a_id=" + myid;
|
|
|
// 如果有权限,跳转到编辑页面,并传递管理员ID
|
|
|
// 这里的注释表示原来的代码被注释掉了
|
|
|
// window.location.href = "/findAdminById?a_id=${ai.a_id}";
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
/*删除*/
|
|
|
function member_del(obj,a_id,a_power){
|
|
|
|
|
|
var power = ${sessionScope.ad.a_power};
|
|
|
// 获取当前登录管理员的权限
|
|
|
var id = ${sessionScope.ad.a_id};
|
|
|
// 获取当前登录管理员的ID
|
|
|
if(power != 1 && id != a_id){
|
|
|
// 如果没有权限,弹出提示框
|
|
|
layer.alert("对不起,您没有权限:(");
|
|
|
}
|
|
|
// else if(power == 1 && id == a_id){
|
|
|
// layer.alert("对不起,您没有权限:(");
|
|
|
// }
|
|
|
else {
|
|
|
layer.confirm('确认要删除吗?',function(index){
|
|
|
// 如果有权限,弹出确认框
|
|
|
//发异步删除数据
|
|
|
$.get("/deleteAdmin",{"a_id":a_id},function (data) {
|
|
|
// 发起GET请求删除管理员信息
|
|
|
if(data = true){
|
|
|
// 判断删除操作是否成功
|
|
|
layer.msg('删除成功!',{icon:1,time:2000});
|
|
|
setTimeout(function () {window.location.href='/findAdmin';},2000);
|
|
|
// 如果成功,显示成功消息并跳转
|
|
|
|
|
|
}else {
|
|
|
layer.msg('删除失败!',{icon:1,time:2000});
|
|
|
setTimeout(function () {window.location.href='/findAdmin';},2000);
|
|
|
// 如果失败,显示失败消息并跳转
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
|
</html>
|