You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
8.5 KiB

6 days ago
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用户管理 - 学生信息管理系统</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(function() {
$(".btn-delete").click(function(e) {
if (!confirm("确定要删除该用户吗?")) e.preventDefault();
});
$("#searchBtn").click(function() { $("#searchForm").submit(); });
$("#keywordInput").keypress(function(e) {
if (e.which === 13) $("#searchForm").submit();
});
$("#roleFilter").change(function() { $("#searchForm").submit(); });
});
</script>
</head>
<body>
<div class="container">
<nav class="navbar">
<div class="nav-brand">
<a href="${pageContext.request.contextPath}/">学生信息管理系统</a>
</div>
<div class="nav-links">
<a href="${pageContext.request.contextPath}/admin/user?action=list" class="active">用户管理</a>
<a href="${pageContext.request.contextPath}/student?action=list">学生管理</a>
<a href="${pageContext.request.contextPath}/profile">个人中心</a>
<a href="${pageContext.request.contextPath}/logout">退出登录</a>
</div>
</nav>
<div class="page-header">
<h2>用户管理(管理员)</h2>
<div class="header-actions">
<a href="${pageContext.request.contextPath}/admin/user?action=add" class="btn btn-success">+ 新增用户</a>
<a href="${pageContext.request.contextPath}/admin/upload" class="btn btn-primary">📤 导入Excel</a>
<a href="${pageContext.request.contextPath}/admin/download" class="btn btn-secondary">📥 导出Excel</a>
</div>
</div>
<div class="search-bar">
<form id="searchForm" action="${pageContext.request.contextPath}/admin/user" method="get">
<input type="hidden" name="action" value="search">
<div class="search-group">
<input type="text" id="keywordInput" name="keyword" class="search-input"
placeholder="搜索用户名/姓名/邮箱/电话..." value="${keyword}">
<select name="role" id="roleFilter" class="search-select">
<option value="">全部角色</option>
<option value="admin" ${roleFilter == 'admin' ? 'selected' : ''}>管理员</option>
<option value="user" ${roleFilter == 'user' ? 'selected' : ''}>一般用户</option>
</select>
<button type="submit" id="searchBtn" class="btn btn-primary">搜索</button>
<c:if test="${not empty keyword or not empty roleFilter}">
<a href="${pageContext.request.contextPath}/admin/user?action=list" class="btn btn-secondary">清除</a>
</c:if>
</div>
</form>
</div>
<div class="table-container">
<c:choose>
<c:when test="${empty userList}">
<div class="empty-state"><p>暂无用户数据</p></div>
</c:when>
<c:otherwise>
<table class="data-table">
<thead>
<tr>
<th>ID</th>
<th>用户名</th>
<th>真实姓名</th>
<th>角色</th>
<th>邮箱</th>
<th>电话</th>
<th>状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${userList}" var="u">
<tr>
<td>${u.id}</td>
<td>${u.username}</td>
<td>${u.realName}</td>
<td>
<span class="status-badge ${u.isAdmin() ? 'status-在读' : 'status-毕业'}">
${u.isAdmin() ? '管理员' : '一般用户'}
</span>
</td>
<td>${u.email}</td>
<td>${u.phone}</td>
<td>
<span class="status-badge ${u.status == '正常' ? 'status-在读' : 'status-休学'}">
${u.status}
</span>
</td>
<td>${u.createdAt}</td>
<td class="action-cell">
<a href="${pageContext.request.contextPath}/admin/user?action=edit&id=${u.id}"
class="btn btn-sm btn-edit">编辑</a>
<c:if test="${u.id != loginUser.id}">
<a href="${pageContext.request.contextPath}/admin/user?action=delete&id=${u.id}"
class="btn btn-sm btn-delete">删除</a>
</c:if>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<div class="pagination">
<div class="page-info">共 ${totalCount} 条,第 ${currentPage}/${totalPages} 页</div>
<div class="page-links">
<c:if test="${currentPage > 1}">
<a href="${pageContext.request.contextPath}/admin/user?action=${empty keyword ? 'list' : 'search'}&page=1${not empty keyword ? '&keyword=' : ''}${keyword}${not empty roleFilter ? '&role=' : ''}${roleFilter}"
class="page-link">首页</a>
<a href="${pageContext.request.contextPath}/admin/user?action=${empty keyword ? 'list' : 'search'}&page=${currentPage - 1}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty roleFilter ? '&role=' : ''}${roleFilter}"
class="page-link">上一页</a>
</c:if>
<c:forEach begin="1" end="${totalPages}" var="i">
<c:if test="${i >= currentPage - 2 && i <= currentPage + 2}">
<a href="${pageContext.request.contextPath}/admin/user?action=${empty keyword ? 'list' : 'search'}&page=${i}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty roleFilter ? '&role=' : ''}${roleFilter}"
class="page-link ${i == currentPage ? 'active' : ''}">${i}</a>
</c:if>
</c:forEach>
<c:if test="${currentPage < totalPages}">
<a href="${pageContext.request.contextPath}/admin/user?action=${empty keyword ? 'list' : 'search'}&page=${currentPage + 1}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty roleFilter ? '&role=' : ''}${roleFilter}"
class="page-link">下一页</a>
<a href="${pageContext.request.contextPath}/admin/user?action=${empty keyword ? 'list' : 'search'}&page=${totalPages}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty roleFilter ? '&role=' : ''}${roleFilter}"
class="page-link">末页</a>
</c:if>
</div>
</div>
</c:otherwise>
</c:choose>
</div>
</div>
</body>
</html>