294 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			294 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
{% extends 'layout/base.html' %}
 | 
						|
 | 
						|
{% block title %}学生管理 - SmartDSP考勤管理系统{% endblock %}
 | 
						|
 | 
						|
{% block content %}
 | 
						|
<div class="container-fluid mt-4">
 | 
						|
    <!-- 页面标题 -->
 | 
						|
    <div class="d-flex justify-content-between align-items-center mb-4">
 | 
						|
        <h1 class="h3 mb-0">
 | 
						|
            <i class="fas fa-users me-2"></i>学生管理
 | 
						|
        </h1>
 | 
						|
        <div>
 | 
						|
            <a href="{{ url_for('admin.add_student') }}" class="btn btn-success">
 | 
						|
                <i class="fas fa-plus me-1"></i>添加学生
 | 
						|
            </a>
 | 
						|
            <div class="btn-group ms-2">
 | 
						|
                <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
 | 
						|
                    批量操作
 | 
						|
                </button>
 | 
						|
                <ul class="dropdown-menu">
 | 
						|
                    <li><a class="dropdown-item" href="#" onclick="batchAction('graduate')">设为毕业</a></li>
 | 
						|
                    <li><a class="dropdown-item text-danger" href="#" onclick="batchAction('delete')">批量删除</a></li>
 | 
						|
                </ul>
 | 
						|
            </div>
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
 | 
						|
    <!-- 搜索和筛选 -->
 | 
						|
    <div class="card shadow mb-4">
 | 
						|
        <div class="card-body">
 | 
						|
            <form method="GET" class="row g-3">
 | 
						|
                <div class="col-md-3">
 | 
						|
                    <label class="form-label">搜索</label>
 | 
						|
                    <input type="text" class="form-control" name="search" value="{{ search }}"
 | 
						|
                           placeholder="学号或姓名">
 | 
						|
                </div>
 | 
						|
                <div class="col-md-2">
 | 
						|
                    <label class="form-label">年级</label>
 | 
						|
                    <select class="form-select" name="grade">
 | 
						|
                        <option value="">全部年级</option>
 | 
						|
                        {% for grade in grades %}
 | 
						|
                        <option value="{{ grade }}" {% if grade|string == selected_grade %}selected{% endif %}>
 | 
						|
                            {{ grade }}级
 | 
						|
                        </option>
 | 
						|
                        {% endfor %}
 | 
						|
                    </select>
 | 
						|
                </div>
 | 
						|
                <div class="col-md-3">
 | 
						|
                    <label class="form-label">学院</label>
 | 
						|
                    <select class="form-select" name="college">
 | 
						|
                        <option value="">全部学院</option>
 | 
						|
                        {% for college in colleges %}
 | 
						|
                        <option value="{{ college }}" {% if college == selected_college %}selected{% endif %}>
 | 
						|
                            {{ college }}
 | 
						|
                        </option>
 | 
						|
                        {% endfor %}
 | 
						|
                    </select>
 | 
						|
                </div>
 | 
						|
                <div class="col-md-3">
 | 
						|
                    <label class="form-label">导师</label>
 | 
						|
                    <select class="form-select" name="supervisor">
 | 
						|
                        <option value="">全部导师</option>
 | 
						|
                        {% for supervisor in supervisors %}
 | 
						|
                        <option value="{{ supervisor }}" {% if supervisor == selected_supervisor %}selected{% endif %}>
 | 
						|
                            {{ supervisor }}
 | 
						|
                        </option>
 | 
						|
                        {% endfor %}
 | 
						|
                    </select>
 | 
						|
                </div>
 | 
						|
                <div class="col-md-1">
 | 
						|
                    <label class="form-label"> </label>
 | 
						|
                    <div>
 | 
						|
                        <button type="submit" class="btn btn-primary">搜索</button>
 | 
						|
                    </div>
 | 
						|
                </div>
 | 
						|
            </form>
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
 | 
						|
    <!-- 学生列表 -->
 | 
						|
    <div class="card shadow">
 | 
						|
        <div class="card-header py-3">
 | 
						|
            <h6 class="m-0 font-weight-bold text-primary">
 | 
						|
                学生列表 (共 {{ pagination.total }} 人)
 | 
						|
            </h6>
 | 
						|
        </div>
 | 
						|
        <div class="card-body">
 | 
						|
            {% if students %}
 | 
						|
            <div class="table-responsive">
 | 
						|
                <table class="table table-hover">
 | 
						|
                    <thead>
 | 
						|
                        <tr>
 | 
						|
                            <th>
 | 
						|
                                <input type="checkbox" id="selectAll" onchange="toggleSelectAll()">
 | 
						|
                            </th>
 | 
						|
                            <th>学号</th>
 | 
						|
                            <th>姓名</th>
 | 
						|
                            <th>性别</th>
 | 
						|
                            <th>年级</th>
 | 
						|
                            <th>学院</th>
 | 
						|
                            <th>导师</th>
 | 
						|
                            <th>学位类型</th>
 | 
						|
                            <th>状态</th>
 | 
						|
                            <th>操作</th>
 | 
						|
                        </tr>
 | 
						|
                    </thead>
 | 
						|
                    <tbody>
 | 
						|
                        {% for student in students %}
 | 
						|
                        <tr>
 | 
						|
                            <td>
 | 
						|
                                <input type="checkbox" class="student-checkbox"
 | 
						|
                                       value="{{ student.student_number }}">
 | 
						|
                            </td>
 | 
						|
                            <td>{{ student.student_number }}</td>
 | 
						|
                            <td>
 | 
						|
                                <strong>{{ student.name }}</strong>
 | 
						|
                                {% if student.phone %}
 | 
						|
                                <br><small class="text-muted">{{ student.phone }}</small>
 | 
						|
                                {% endif %}
 | 
						|
                            </td>
 | 
						|
                            <td>{{ student.gender }}</td>
 | 
						|
                            <td>{{ student.grade }}级</td>
 | 
						|
                            <td>{{ student.college or '-' }}</td>
 | 
						|
                            <td>{{ student.supervisor or '-' }}</td>
 | 
						|
                            <td>
 | 
						|
                                {% if student.degree_type %}
 | 
						|
                                <span class="badge bg-info">{{ student.degree_type }}</span>
 | 
						|
                                {% else %}
 | 
						|
                                -
 | 
						|
                                {% endif %}
 | 
						|
                            </td>
 | 
						|
                            <td>
 | 
						|
                                {% if student.status == '在读' %}
 | 
						|
                                <span class="badge bg-success">在读</span>
 | 
						|
                                {% else %}
 | 
						|
                                <span class="badge bg-secondary">毕业</span>
 | 
						|
                                {% endif %}
 | 
						|
                            </td>
 | 
						|
                            <td>
 | 
						|
                                <div class="btn-group btn-group-sm">
 | 
						|
                                    <a href="{{ url_for('admin.student_detail', student_number=student.student_number) }}"
 | 
						|
                                       class="btn btn-outline-info" title="查看详情">
 | 
						|
                                        <i class="fas fa-eye"></i>
 | 
						|
                                    </a>
 | 
						|
                                    <a href="{{ url_for('admin.edit_student', student_number=student.student_number) }}"
 | 
						|
                                       class="btn btn-outline-primary" title="编辑">
 | 
						|
                                        <i class="fas fa-edit"></i>
 | 
						|
                                    </a>
 | 
						|
                                    <button class="btn btn-outline-danger"
 | 
						|
                                            onclick="deleteStudent('{{ student.student_number }}')" title="删除">
 | 
						|
                                        <i class="fas fa-trash"></i>
 | 
						|
                                    </button>
 | 
						|
                                </div>
 | 
						|
                            </td>
 | 
						|
                        </tr>
 | 
						|
                        {% endfor %}
 | 
						|
                    </tbody>
 | 
						|
                </table>
 | 
						|
            </div>
 | 
						|
 | 
						|
            <!-- 分页 -->
 | 
						|
            {% if pagination.pages > 1 %}
 | 
						|
            <nav aria-label="Page navigation" class="mt-4">
 | 
						|
                <ul class="pagination justify-content-center">
 | 
						|
                    {% if pagination.has_prev %}
 | 
						|
                    <li class="page-item">
 | 
						|
                        <a class="page-link" href="{{ url_for('admin.student_list', page=pagination.prev_num, **request.args) }}">
 | 
						|
                            上一页
 | 
						|
                        </a>
 | 
						|
                    </li>
 | 
						|
                    {% endif %}
 | 
						|
 | 
						|
                    {% for page_num in pagination.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
 | 
						|
                        {% if page_num %}
 | 
						|
                            {% if page_num != pagination.page %}
 | 
						|
                            <li class="page-item">
 | 
						|
                                <a class="page-link" href="{{ url_for('admin.student_list', page=page_num, **request.args) }}">
 | 
						|
                                    {{ page_num }}
 | 
						|
                                </a>
 | 
						|
                            </li>
 | 
						|
                            {% else %}
 | 
						|
                            <li class="page-item active">
 | 
						|
                                <span class="page-link">{{ page_num }}</span>
 | 
						|
                            </li>
 | 
						|
                            {% endif %}
 | 
						|
                        {% else %}
 | 
						|
                        <li class="page-item disabled">
 | 
						|
                            <span class="page-link">…</span>
 | 
						|
                        </li>
 | 
						|
                        {% endif %}
 | 
						|
                    {% endfor %}
 | 
						|
 | 
						|
                    {% if pagination.has_next %}
 | 
						|
                    <li class="page-item">
 | 
						|
                        <a class="page-link" href="{{ url_for('admin.student_list', page=pagination.next_num, **request.args) }}">
 | 
						|
                            下一页
 | 
						|
                        </a>
 | 
						|
                    </li>
 | 
						|
                    {% endif %}
 | 
						|
                </ul>
 | 
						|
            </nav>
 | 
						|
            {% endif %}
 | 
						|
 | 
						|
            {% else %}
 | 
						|
            <div class="text-center py-5">
 | 
						|
                <i class="fas fa-users fa-3x text-muted mb-3"></i>
 | 
						|
                <p class="text-muted">暂无学生数据</p>
 | 
						|
                <a href="{{ url_for('admin.add_student') }}" class="btn btn-primary">
 | 
						|
                    <i class="fas fa-plus me-1"></i>添加第一个学生
 | 
						|
                </a>
 | 
						|
            </div>
 | 
						|
            {% endif %}
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
</div>
 | 
						|
{% endblock %}
 | 
						|
 | 
						|
{% block extra_js %}
 | 
						|
<script>
 | 
						|
// 全选/取消全选
 | 
						|
function toggleSelectAll() {
 | 
						|
    const selectAll = document.getElementById('selectAll');
 | 
						|
    const checkboxes = document.querySelectorAll('.student-checkbox');
 | 
						|
    checkboxes.forEach(checkbox => {
 | 
						|
        checkbox.checked = selectAll.checked;
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
// 删除学生
 | 
						|
function deleteStudent(studentNumber) {
 | 
						|
    if (confirm('确认删除这个学生吗?此操作不可恢复!')) {
 | 
						|
        fetch(`/admin/students/${studentNumber}/delete`, {
 | 
						|
            method: 'POST'
 | 
						|
        })
 | 
						|
        .then(response => response.json())
 | 
						|
        .then(result => {
 | 
						|
            if (result.success) {
 | 
						|
                location.reload();
 | 
						|
            } else {
 | 
						|
                alert(result.message);
 | 
						|
            }
 | 
						|
        })
 | 
						|
        .catch(error => {
 | 
						|
            console.error('Error:', error);
 | 
						|
            alert('删除失败,请稍后重试');
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
// 批量操作
 | 
						|
function batchAction(action) {
 | 
						|
    const selectedStudents = Array.from(document.querySelectorAll('.student-checkbox:checked'))
 | 
						|
        .map(checkbox => checkbox.value);
 | 
						|
 | 
						|
    if (selectedStudents.length === 0) {
 | 
						|
        alert('请选择要操作的学生');
 | 
						|
        return;
 | 
						|
    }
 | 
						|
 | 
						|
    let confirmMessage = '';
 | 
						|
    if (action === 'delete') {
 | 
						|
        confirmMessage = `确认删除选中的 ${selectedStudents.length} 个学生吗?此操作不可恢复!`;
 | 
						|
    } else if (action === 'graduate') {
 | 
						|
        confirmMessage = `确认将选中的 ${selectedStudents.length} 个学生设为毕业状态吗?`;
 | 
						|
    }
 | 
						|
 | 
						|
    if (confirm(confirmMessage)) {
 | 
						|
        fetch('/admin/students/batch_action', {
 | 
						|
            method: 'POST',
 | 
						|
            headers: {
 | 
						|
                'Content-Type': 'application/json',
 | 
						|
            },
 | 
						|
            body: JSON.stringify({
 | 
						|
                action: action,
 | 
						|
                student_numbers: selectedStudents
 | 
						|
            })
 | 
						|
        })
 | 
						|
        .then(response => response.json())
 | 
						|
        .then(result => {
 | 
						|
            if (result.success) {
 | 
						|
                location.reload();
 | 
						|
            } else {
 | 
						|
                alert(result.message);
 | 
						|
            }
 | 
						|
        })
 | 
						|
        .catch(error => {
 | 
						|
            console.error('Error:', error);
 | 
						|
            alert('操作失败,请稍后重试');
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 | 
						|
</script>
 | 
						|
{% endblock %}
 |