import { LogoutOutlined, PlusOutlined, UserOutlined } from '@ant-design/icons' import { Button, Card, Col, Form, Input, Modal, Row, Select, Space, Spin, Tag, Typography, message } from 'antd' import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { studentApi } from '../api/client' import { formatStudentMeta, GRADE_OPTIONS, SCHOOL_LEVEL_LABELS } from '../constants/school' import { useAuth } from '../context/AuthContext' import type { SchoolLevel, Student } from '../types' export default function StudentsPage() { const { user, logout } = useAuth() const [students, setStudents] = useState([]) const [loading, setLoading] = useState(true) const [modalOpen, setModalOpen] = useState(false) const [form] = Form.useForm() const schoolLevel = Form.useWatch('school_level', form) as SchoolLevel | undefined const load = async () => { setLoading(true) try { const { data } = await studentApi.list() setStudents(data) } finally { setLoading(false) } } useEffect(() => { load() }, []) const openCreate = () => { form.setFieldsValue({ school_level: 'junior_high', grade: undefined }) setModalOpen(true) } const handleCreate = async () => { const values = await form.validateFields() await studentApi.create(values) message.success('学生已添加') setModalOpen(false) form.resetFields() load() } return (
学生档案 欢迎,{user?.username}
{students.map((s) => (
{s.name} {SCHOOL_LEVEL_LABELS[s.school_level]}
{formatStudentMeta(s)}
))} {!loading && students.length === 0 && ( 暂无学生,点击「添加学生」开始 )}
setModalOpen(false)} onOk={handleCreate} destroyOnHidden >
({ value: g, label: g, }))} />
) }