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.

184 lines
9.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" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!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();
}
});
// Ajax搜索 - 实时搜索
$("#searchBtn").click(function() {
$("#searchForm").submit();
});
// 回车搜索
$("#keywordInput").keypress(function(e) {
if (e.which === 13) {
$("#searchForm").submit();
}
});
// 状态筛选变化时自动提交
$("#statusFilter").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">
<c:if test="${loginUser.isAdmin()}">
<a href="${pageContext.request.contextPath}/admin/user?action=list">用户管理</a>
</c:if>
<a href="${pageContext.request.contextPath}/student?action=list" class="active">学生列表</a>
<a href="${pageContext.request.contextPath}/addStudent">添加学生</a>
<a href="${pageContext.request.contextPath}/profile">${loginUser.realName != null ? loginUser.realName : loginUser.username}</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}/addStudent" class="btn btn-success">+ 添加学生</a>
</div>
</div>
<!-- 搜索栏 -->
<div class="search-bar">
<form id="searchForm" action="${pageContext.request.contextPath}/student" method="get">
<input type="hidden" name="action" value="search">
<div class="search-group">
<input type="text" id="keywordInput" name="keyword"
placeholder="输入学号/姓名/班级/专业搜索..."
value="${keyword}" class="search-input">
<select name="status" id="statusFilter" class="search-select">
<option value="">全部状态</option>
<option value="在读" ${statusFilter == '在读' ? 'selected' : ''}>在读</option>
<option value="休学" ${statusFilter == '休学' ? 'selected' : ''}>休学</option>
<option value="毕业" ${statusFilter == '毕业' ? 'selected' : ''}>毕业</option>
</select>
<button type="submit" id="searchBtn" class="btn btn-primary">搜索</button>
<c:if test="${not empty keyword or not empty statusFilter}">
<a href="${pageContext.request.contextPath}/student?action=list" class="btn btn-secondary">清除</a>
</c:if>
</div>
</form>
</div>
<!-- 状态提示 -->
<c:if test="${not empty keyword or not empty statusFilter}">
<div class="search-tip">
搜索结果:
<c:if test="${not empty keyword}">关键词 "<strong>${keyword}</strong>" </c:if>
<c:if test="${not empty statusFilter}">状态 "<strong>${statusFilter}</strong>" </c:if>
共找到 <strong>${totalCount}</strong> 条记录
</div>
</c:if>
<!-- 学生列表 -->
<div class="table-container">
<c:choose>
<c:when test="${empty studentList}">
<div class="empty-state">
<p>暂无学生数据</p>
<a href="${pageContext.request.contextPath}/addStudent" class="btn btn-success">添加第一位学生</a>
</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>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${studentList}" var="student" varStatus="status">
<tr>
<td>${student.id}</td>
<td>${student.studentNo}</td>
<td>${student.name}</td>
<td>${student.gender}</td>
<td>${student.age}</td>
<td>${student.className}</td>
<td>${student.major}</td>
<td>${student.phone}</td>
<td>
<span class="status-badge status-${student.status}">
${student.status}
</span>
</td>
<td class="action-cell">
<a href="${pageContext.request.contextPath}/editStudent.jsp?id=${student.id}"
class="btn btn-sm btn-edit">编辑</a>
<a href="${pageContext.request.contextPath}/student?action=delete&id=${student.id}"
class="btn btn-sm btn-delete">删除</a>
</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}/student?action=${empty keyword ? 'list' : 'search'}&page=1${not empty keyword ? '&keyword=' : ''}${keyword}${not empty statusFilter ? '&status=' : ''}${statusFilter}"
class="page-link">首页</a>
<a href="${pageContext.request.contextPath}/student?action=${empty keyword ? 'list' : 'search'}&page=${currentPage - 1}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty statusFilter ? '&status=' : ''}${statusFilter}"
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}/student?action=${empty keyword ? 'list' : 'search'}&page=${i}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty statusFilter ? '&status=' : ''}${statusFilter}"
class="page-link ${i == currentPage ? 'active' : ''}">${i}</a>
</c:if>
</c:forEach>
<c:if test="${currentPage < totalPages}">
<a href="${pageContext.request.contextPath}/student?action=${empty keyword ? 'list' : 'search'}&page=${currentPage + 1}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty statusFilter ? '&status=' : ''}${statusFilter}"
class="page-link">下一页</a>
<a href="${pageContext.request.contextPath}/student?action=${empty keyword ? 'list' : 'search'}&page=${totalPages}${not empty keyword ? '&keyword=' : ''}${keyword}${not empty statusFilter ? '&status=' : ''}${statusFilter}"
class="page-link">末页</a>
</c:if>
</div>
</div>
</c:otherwise>
</c:choose>
</div>
</div>
</body>
</html>