dvc890 commited on
Commit
9e660ce
·
verified ·
1 Parent(s): cdd3023

Upload 65 files

Browse files
Files changed (5) hide show
  1. App.tsx +5 -2
  2. Sidebar.tsx +174 -0
  3. models.js +9 -2
  4. pages/MyClass.tsx +582 -0
  5. types.ts +8 -1
App.tsx CHANGED
@@ -57,6 +57,7 @@ const AttendancePage = lazyRetry(() => import('./pages/Attendance'), 'Attendance
57
  const Profile = lazyRetry(() => import('./pages/Profile'), 'Profile');
58
  const WishesAndFeedback = lazyRetry(() => import('./pages/WishesAndFeedback'), 'WishesAndFeedback');
59
  const AIAssistant = lazyRetry(() => import('./pages/AIAssistant'), 'AIAssistant');
 
60
 
61
  class ErrorBoundary extends React.Component<{children: React.ReactNode}, {hasError: boolean, error: Error | null}> {
62
  constructor(props: any) {
@@ -161,6 +162,7 @@ const AppContent: React.FC = () => {
161
  case 'wishes': return <WishesAndFeedback />;
162
  case 'ai-assistant': return <AIAssistant />;
163
  case 'profile': return <Profile />;
 
164
  default: return <Dashboard onNavigate={(view: string) => setCurrentView(view)} />;
165
  }
166
  };
@@ -180,7 +182,8 @@ const AppContent: React.FC = () => {
180
  attendance: '考勤管理',
181
  wishes: '心愿与反馈',
182
  'ai-assistant': 'AI 智能助教',
183
- profile: '个人中心'
 
184
  };
185
 
186
  if (loading) return <div className="min-h-screen flex items-center justify-center bg-gray-50 text-blue-600">加载中...</div>;
@@ -224,4 +227,4 @@ const App: React.FC = () => {
224
  );
225
  };
226
 
227
- export default App;
 
57
  const Profile = lazyRetry(() => import('./pages/Profile'), 'Profile');
58
  const WishesAndFeedback = lazyRetry(() => import('./pages/WishesAndFeedback'), 'WishesAndFeedback');
59
  const AIAssistant = lazyRetry(() => import('./pages/AIAssistant'), 'AIAssistant');
60
+ const MyClass = lazyRetry(() => import('./pages/MyClass'), 'MyClass');
61
 
62
  class ErrorBoundary extends React.Component<{children: React.ReactNode}, {hasError: boolean, error: Error | null}> {
63
  constructor(props: any) {
 
162
  case 'wishes': return <WishesAndFeedback />;
163
  case 'ai-assistant': return <AIAssistant />;
164
  case 'profile': return <Profile />;
165
+ case 'my-class': return <MyClass />;
166
  default: return <Dashboard onNavigate={(view: string) => setCurrentView(view)} />;
167
  }
168
  };
 
182
  attendance: '考勤管理',
183
  wishes: '心愿与反馈',
184
  'ai-assistant': 'AI 智能助教',
185
+ profile: '个人中心',
186
+ 'my-class': '我的班级 (班主任)'
187
  };
188
 
189
  if (loading) return <div className="min-h-screen flex items-center justify-center bg-gray-50 text-blue-600">加载中...</div>;
 
227
  );
228
  };
229
 
230
+ export default App;
Sidebar.tsx ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import React, { useState, useEffect } from 'react';
3
+ import { LayoutDashboard, Users, BookOpen, GraduationCap, Settings, LogOut, FileText, School, UserCog, Palette, X, Building, Gamepad2, CalendarCheck, UserCircle, MessageSquare, Bot, ArrowUp, ArrowDown, Save, UserCheck } from 'lucide-react';
4
+ import { UserRole } from '../types';
5
+ import { api } from '../services/api';
6
+
7
+ interface SidebarProps {
8
+ currentView: string;
9
+ onChangeView: (view: string) => void;
10
+ userRole: UserRole;
11
+ onLogout: () => void;
12
+ isOpen: boolean;
13
+ onClose: () => void;
14
+ }
15
+
16
+ interface MenuItem {
17
+ id: string;
18
+ label: string;
19
+ icon: React.ElementType;
20
+ roles: UserRole[];
21
+ }
22
+
23
+ export const Sidebar: React.FC<SidebarProps> = ({ currentView, onChangeView, userRole, onLogout, isOpen, onClose }) => {
24
+ const currentUser = api.auth.getCurrentUser();
25
+ const canSeeAI = userRole === UserRole.ADMIN || (userRole === UserRole.TEACHER && currentUser?.aiAccess);
26
+ const isHomeroom = userRole === UserRole.TEACHER && !!currentUser?.homeroomClass;
27
+
28
+ // Default Items
29
+ const defaultItems: MenuItem[] = [
30
+ { id: 'dashboard', label: '工作台', icon: LayoutDashboard, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER, UserRole.STUDENT] },
31
+ { id: 'my-class', label: '我的班级', icon: UserCheck, roles: isHomeroom ? [UserRole.TEACHER] : [] },
32
+ { id: 'ai-assistant', label: 'AI 智能助教', icon: Bot, roles: canSeeAI ? [UserRole.ADMIN, UserRole.TEACHER] : [] },
33
+ { id: 'attendance', label: '考勤管理', icon: CalendarCheck, roles: [UserRole.TEACHER, UserRole.PRINCIPAL] },
34
+ { id: 'games', label: '互动教学', icon: Gamepad2, roles: [UserRole.TEACHER, UserRole.STUDENT] },
35
+ { id: 'wishes', label: '心愿与反馈', icon: MessageSquare, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER, UserRole.STUDENT] },
36
+ { id: 'students', label: '学生管理', icon: Users, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER] },
37
+ { id: 'classes', label: '班级管理', icon: School, roles: [UserRole.ADMIN, UserRole.PRINCIPAL] },
38
+ { id: 'schools', label: '学校管理', icon: Building, roles: [UserRole.ADMIN] },
39
+ { id: 'courses', label: '课程管理', icon: BookOpen, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER] },
40
+ { id: 'grades', label: '成绩管理', icon: GraduationCap, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER] },
41
+ { id: 'reports', label: '报表统计', icon: FileText, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER, UserRole.STUDENT] },
42
+ { id: 'subjects', label: '学科设置', icon: Palette, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER] },
43
+ { id: 'users', label: '用户管理', icon: UserCog, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER] },
44
+ { id: 'profile', label: '个人中心', icon: UserCircle, roles: [UserRole.ADMIN, UserRole.PRINCIPAL, UserRole.TEACHER, UserRole.STUDENT] },
45
+ { id: 'settings', label: '系统设置', icon: Settings, roles: [UserRole.ADMIN, UserRole.PRINCIPAL] },
46
+ ];
47
+
48
+ const [menuItems, setMenuItems] = useState<MenuItem[]>(defaultItems);
49
+ const [isEditing, setIsEditing] = useState(false);
50
+
51
+ useEffect(() => {
52
+ // Load saved order
53
+ if (currentUser?.menuOrder && currentUser.menuOrder.length > 0) {
54
+ const ordered: MenuItem[] = [];
55
+ const map = new Map(defaultItems.map(i => [i.id, i]));
56
+ // Add saved items in order
57
+ currentUser.menuOrder.forEach(id => {
58
+ if (map.has(id)) {
59
+ ordered.push(map.get(id)!);
60
+ map.delete(id);
61
+ }
62
+ });
63
+ // Append any new/remaining items
64
+ map.forEach(item => ordered.push(item));
65
+ setMenuItems(ordered);
66
+ }
67
+ }, []);
68
+
69
+ const handleMove = (index: number, direction: -1 | 1) => {
70
+ const newItems = [...menuItems];
71
+ const targetIndex = index + direction;
72
+ if (targetIndex < 0 || targetIndex >= newItems.length) return;
73
+ [newItems[index], newItems[targetIndex]] = [newItems[targetIndex], newItems[index]];
74
+ setMenuItems(newItems);
75
+ };
76
+
77
+ const saveOrder = async () => {
78
+ setIsEditing(false);
79
+ const orderIds = menuItems.map(i => i.id);
80
+ if (currentUser && currentUser._id) {
81
+ try {
82
+ await api.users.saveMenuOrder(currentUser._id, orderIds);
83
+ // Update local user object
84
+ const updatedUser = { ...currentUser, menuOrder: orderIds };
85
+ localStorage.setItem('user', JSON.stringify(updatedUser));
86
+ } catch(e) { console.error("Failed to save menu order"); }
87
+ }
88
+ };
89
+
90
+ const sidebarClasses = `
91
+ fixed inset-y-0 left-0 z-50 w-64 bg-slate-900 text-white transition-transform duration-300 ease-in-out transform
92
+ ${isOpen ? 'translate-x-0' : '-translate-x-full'}
93
+ lg:relative lg:translate-x-0 lg:flex lg:flex-col lg:h-screen shadow-2xl lg:shadow-none
94
+ `;
95
+
96
+ return (
97
+ <>
98
+ {isOpen && <div className="fixed inset-0 bg-black/50 z-40 lg:hidden backdrop-blur-sm" onClick={onClose}></div>}
99
+
100
+ <div className={sidebarClasses}>
101
+ <div className="flex items-center justify-between h-20 border-b border-slate-700 px-6">
102
+ <div className="flex items-center space-x-2">
103
+ <GraduationCap className="h-8 w-8 text-blue-400" />
104
+ <span className="text-xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-teal-300">
105
+ 智慧校园
106
+ </span>
107
+ </div>
108
+ <button onClick={onClose} className="lg:hidden text-slate-400 hover:text-white"><X size={24} /></button>
109
+ </div>
110
+
111
+ <div className="flex-1 overflow-y-auto py-4 custom-scrollbar">
112
+ <div className="px-4 mb-2 flex justify-between items-center">
113
+ <span className="text-xs text-slate-500 font-bold uppercase">主菜单</span>
114
+ <button
115
+ onClick={() => isEditing ? saveOrder() : setIsEditing(true)}
116
+ className={`text-xs px-2 py-1 rounded hover:bg-slate-800 ${isEditing ? 'text-green-400' : 'text-slate-600'}`}
117
+ >
118
+ {isEditing ? '完成' : '调整'}
119
+ </button>
120
+ </div>
121
+ <nav className="space-y-1 px-2">
122
+ {menuItems.map((item, idx) => {
123
+ if (item.roles.length > 0 && !item.roles.includes(userRole)) return null;
124
+ if (item.id === 'ai-assistant' && !canSeeAI) return null;
125
+ // Special check for 'my-class': only homeroom teachers
126
+ if (item.id === 'my-class' && !isHomeroom) return null;
127
+
128
+ const Icon = item.icon;
129
+ const isActive = currentView === item.id;
130
+
131
+ return (
132
+ <div key={item.id} className="flex items-center gap-1 group">
133
+ <button
134
+ onClick={() => !isEditing && onChangeView(item.id)}
135
+ disabled={isEditing}
136
+ className={`flex-1 flex items-center space-x-3 px-4 py-3 rounded-lg transition-colors duration-200 ${
137
+ isActive
138
+ ? 'bg-blue-600 text-white shadow-lg shadow-blue-900/50'
139
+ : 'text-slate-300 hover:bg-slate-800 hover:text-white'
140
+ } ${isEditing ? 'opacity-70 cursor-grab' : ''}`}
141
+ >
142
+ <Icon size={20} />
143
+ <span className="font-medium">{item.label}</span>
144
+ </button>
145
+ {isEditing && (
146
+ <div className="flex flex-col gap-1 pr-1">
147
+ <button onClick={()=>handleMove(idx, -1)} className="p-1 hover:bg-slate-700 rounded text-slate-400 hover:text-white"><ArrowUp size={12}/></button>
148
+ <button onClick={()=>handleMove(idx, 1)} className="p-1 hover:bg-slate-700 rounded text-slate-400 hover:text-white"><ArrowDown size={12}/></button>
149
+ </div>
150
+ )}
151
+ </div>
152
+ );
153
+ })}
154
+ </nav>
155
+ </div>
156
+
157
+ <div className="p-4 border-t border-slate-700">
158
+ <div className="px-4 py-2 mb-2 text-xs text-slate-500 flex justify-between">
159
+ <span>当前角色:</span>
160
+ <span className="text-slate-300 font-bold">
161
+ {userRole === 'ADMIN' ? '超级管理员' :
162
+ userRole === 'PRINCIPAL' ? '校长' :
163
+ userRole === 'TEACHER' ? '教师' : '学生'}
164
+ </span>
165
+ </div>
166
+ <button onClick={onLogout} className="w-full flex items-center space-x-3 px-4 py-3 rounded-lg text-slate-400 hover:bg-red-500/10 hover:text-red-400 transition-all duration-200">
167
+ <LogOut size={20} />
168
+ <span className="font-medium">退出登录</span>
169
+ </button>
170
+ </div>
171
+ </div>
172
+ </>
173
+ );
174
+ };
models.js CHANGED
@@ -60,7 +60,13 @@ const StudentSchema = new mongoose.Schema({
60
  teamId: String,
61
  drawAttempts: { type: Number, default: 0 },
62
  dailyDrawLog: { date: String, count: { type: Number, default: 0 } },
63
- flowerBalance: { type: Number, default: 0 }
 
 
 
 
 
 
64
  });
65
  const Student = mongoose.model('Student', StudentSchema);
66
 
@@ -88,7 +94,8 @@ const ClassSchema = new mongoose.Schema({
88
  className: String,
89
  teacherName: String,
90
  homeroomTeacherIds: [String],
91
- periodConfig: [{ period: Number, name: String, startTime: String, endTime: String }]
 
92
  });
93
  const ClassModel = mongoose.model('Class', ClassSchema);
94
 
 
60
  teamId: String,
61
  drawAttempts: { type: Number, default: 0 },
62
  dailyDrawLog: { date: String, count: { type: Number, default: 0 } },
63
+ flowerBalance: { type: Number, default: 0 },
64
+ // Seating Fields
65
+ height: Number,
66
+ vision: { type: String, default: 'Normal' }, // Normal, Near-Mild, Near-Severe, Far
67
+ character: { type: String, default: 'Normal' }, // Active, Quiet, Normal
68
+ seatRow: Number,
69
+ seatCol: Number
70
  });
71
  const Student = mongoose.model('Student', StudentSchema);
72
 
 
94
  className: String,
95
  teacherName: String,
96
  homeroomTeacherIds: [String],
97
+ periodConfig: [{ period: Number, name: String, startTime: String, endTime: String }],
98
+ seatingConfig: { rows: Number, cols: Number }
99
  });
100
  const ClassModel = mongoose.model('Class', ClassSchema);
101
 
pages/MyClass.tsx ADDED
@@ -0,0 +1,582 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import React, { useState, useEffect, useRef } from 'react';
3
+ import { api } from '../services/api';
4
+ import { Student, ClassInfo } from '../types';
5
+ import {
6
+ Users, Grid, ArrowLeftRight, Save, Wand2, Eye, EyeOff, Smile, Frown, Meh,
7
+ Ruler, Search, Info, Edit, Upload, FileSpreadsheet, Loader2, AlertTriangle
8
+ } from 'lucide-react';
9
+ import { Toast, ToastState } from '../components/Toast';
10
+ import { ConfirmModal } from '../components/ConfirmModal';
11
+ import { Emoji } from '../components/Emoji';
12
+
13
+ export const MyClass: React.FC = () => {
14
+ const [loading, setLoading] = useState(true);
15
+ const [students, setStudents] = useState<Student[]>([]);
16
+ const [activeTab, setActiveTab] = useState<'roster' | 'seating'>('roster');
17
+ const [myClassInfo, setMyClassInfo] = useState<ClassInfo | null>(null);
18
+
19
+ // Seating State
20
+ const [rows, setRows] = useState(6);
21
+ const [cols, setCols] = useState(8);
22
+ const [draggedStudentId, setDraggedStudentId] = useState<string | null>(null);
23
+
24
+ // UI State
25
+ const [searchTerm, setSearchTerm] = useState('');
26
+ const [toast, setToast] = useState<ToastState>({ show: false, message: '', type: 'success' });
27
+ const [isEditModalOpen, setIsEditModalOpen] = useState(false);
28
+ const [isImportOpen, setIsImportOpen] = useState(false);
29
+ const [importFile, setImportFile] = useState<File | null>(null);
30
+ const [importing, setImporting] = useState(false);
31
+
32
+ const [editingStudent, setEditingStudent] = useState<Student | null>(null);
33
+ const [editForm, setEditForm] = useState({ height: '', vision: 'Normal', character: 'Normal' });
34
+
35
+ const currentUser = api.auth.getCurrentUser();
36
+ const homeroomClass = currentUser?.homeroomClass;
37
+
38
+ useEffect(() => {
39
+ loadData();
40
+ }, [homeroomClass]);
41
+
42
+ const loadData = async () => {
43
+ if (!homeroomClass) { setLoading(false); return; }
44
+ setLoading(true);
45
+ try {
46
+ // Fetch Students
47
+ const allStus = await api.students.getAll();
48
+ const classStus = allStus.filter((s: Student) => s.className === homeroomClass);
49
+
50
+ // Sort by seat number if available
51
+ classStus.sort((a: Student, b: Student) => {
52
+ const seatA = parseInt(a.seatNo || '9999');
53
+ const seatB = parseInt(b.seatNo || '9999');
54
+ return seatA - seatB;
55
+ });
56
+ setStudents(classStus);
57
+
58
+ // Fetch Class Info (for seating config)
59
+ const allClasses = await api.classes.getAll();
60
+ const cls = allClasses.find((c: ClassInfo) => (c.grade + c.className) === homeroomClass || c.className === homeroomClass);
61
+ if (cls) {
62
+ setMyClassInfo(cls);
63
+ if (cls.seatingConfig) {
64
+ setRows(cls.seatingConfig.rows);
65
+ setCols(cls.seatingConfig.cols);
66
+ }
67
+ }
68
+ } catch (e) { console.error(e); }
69
+ finally { setLoading(false); }
70
+ };
71
+
72
+ // --- Roster Logic ---
73
+ const handleOpenEdit = (s: Student) => {
74
+ setEditingStudent(s);
75
+ setEditForm({
76
+ height: s.height ? String(s.height) : '',
77
+ vision: s.vision || 'Normal',
78
+ character: s.character || 'Normal'
79
+ });
80
+ setIsEditModalOpen(true);
81
+ };
82
+
83
+ const handleSaveStudentAttr = async () => {
84
+ if (!editingStudent) return;
85
+ try {
86
+ await api.students.update(editingStudent._id || String(editingStudent.id), {
87
+ height: editForm.height ? Number(editForm.height) : undefined,
88
+ vision: editForm.vision,
89
+ character: editForm.character
90
+ });
91
+ setToast({ show: true, message: '特征信息已保存', type: 'success' });
92
+ setIsEditModalOpen(false);
93
+ loadData();
94
+ } catch (e) { setToast({ show: true, message: '保存失败', type: 'error' }); }
95
+ };
96
+
97
+ const handleExcelImport = async () => {
98
+ if (!importFile) return;
99
+ setImporting(true);
100
+
101
+ let XLSX: any;
102
+ try { XLSX = await import('xlsx'); }
103
+ catch (e) { setToast({ show: true, message: 'Excel 插件加载失败', type: 'error' }); setImporting(false); return; }
104
+
105
+ const reader = new FileReader();
106
+ reader.onload = async (e) => {
107
+ try {
108
+ const data = e.target?.result;
109
+ const workbook = XLSX.read(data, { type: 'array' });
110
+ const sheet = workbook.Sheets[workbook.SheetNames[0]];
111
+ const rows: any[] = XLSX.utils.sheet_to_json(sheet);
112
+
113
+ let updatedCount = 0;
114
+ const promises = rows.map(async (row: any) => {
115
+ const name = row['姓名'] || row['Name'];
116
+ if (!name) return;
117
+
118
+ const target = students.find(s => s.name === name);
119
+ if (!target) return;
120
+
121
+ const updates: any = {};
122
+ if (row['身高']) updates.height = Number(row['身高']);
123
+
124
+ // Vision Mapping
125
+ const v = row['视力'];
126
+ if (v) {
127
+ if (v.includes('好') || v.includes('正常')) updates.vision = 'Normal';
128
+ else if (v.includes('轻') || v > 4.8) updates.vision = 'Near-Mild';
129
+ else if (v.includes('重') || v <= 4.8) updates.vision = 'Near-Severe';
130
+ else if (v.includes('远')) updates.vision = 'Far';
131
+ }
132
+
133
+ // Character Mapping
134
+ const c = row['性格'];
135
+ if (c) {
136
+ if (c.includes('活') || c.includes('话')) updates.character = 'Active';
137
+ else if (c.includes('静') || c.includes('少')) updates.character = 'Quiet';
138
+ else if (c.includes('皮')) updates.character = 'Naughty';
139
+ else updates.character = 'Steady';
140
+ }
141
+
142
+ if (Object.keys(updates).length > 0) {
143
+ await api.students.update(target._id || String(target.id), updates);
144
+ updatedCount++;
145
+ }
146
+ });
147
+
148
+ await Promise.all(promises);
149
+ setToast({ show: true, message: `成功更新 ${updatedCount} 名学生信息`, type: 'success' });
150
+ setIsImportOpen(false);
151
+ loadData();
152
+ } catch (err) { setToast({ show: true, message: '解析失败', type: 'error' }); }
153
+ finally { setImporting(false); }
154
+ };
155
+ reader.readAsArrayBuffer(importFile);
156
+ };
157
+
158
+ // --- Seating Logic ---
159
+ const getStudentAt = (r: number, c: number) => {
160
+ return students.find(s => s.seatRow === r && s.seatCol === c);
161
+ };
162
+
163
+ const handleDrop = async (targetRow: number, targetCol: number) => {
164
+ if (!draggedStudentId) return;
165
+
166
+ const draggedStudent = students.find(s => s._id === draggedStudentId);
167
+ const targetStudent = getStudentAt(targetRow, targetCol);
168
+
169
+ if (!draggedStudent) return;
170
+
171
+ // Optimistic Update
172
+ const newStudents = [...students];
173
+
174
+ // 1. Move Dragged to Target
175
+ const dIndex = newStudents.findIndex(s => s._id === draggedStudentId);
176
+ newStudents[dIndex] = { ...draggedStudent, seatRow: targetRow, seatCol: targetCol };
177
+
178
+ // 2. If target occupied, swap to dragged's old position (or unseat if dragged was unseated)
179
+ if (targetStudent) {
180
+ const tIndex = newStudents.findIndex(s => s._id === targetStudent._id);
181
+ newStudents[tIndex] = {
182
+ ...targetStudent,
183
+ seatRow: draggedStudent.seatRow,
184
+ seatCol: draggedStudent.seatCol
185
+ };
186
+ }
187
+
188
+ setStudents(newStudents);
189
+ setDraggedStudentId(null);
190
+ };
191
+
192
+ const autoArrange = () => {
193
+ if (!confirm('确定要自动重新排座吗?当前所有座位将被重置。')) return;
194
+
195
+ const toSort = [...students];
196
+
197
+ // Score Algorithm
198
+ // Height: Shortest first (Score highest)
199
+ // Vision: Worst first (Score highest)
200
+
201
+ toSort.sort((a, b) => {
202
+ let scoreA = 0;
203
+ let scoreB = 0;
204
+
205
+ // Vision Priority (High weight)
206
+ if (a.vision === 'Near-Severe') scoreA += 1000;
207
+ if (a.vision === 'Near-Mild') scoreA += 500;
208
+
209
+ if (b.vision === 'Near-Severe') scoreB += 1000;
210
+ if (b.vision === 'Near-Mild') scoreB += 500;
211
+
212
+ // Height Priority (Low weight, inverse)
213
+ // Assumed range 100-200. Shorter = Higher Score.
214
+ // 200 - 150 = 50. 200 - 130 = 70.
215
+ if (a.height) scoreA += (200 - a.height);
216
+ if (b.height) scoreB += (200 - b.height);
217
+
218
+ // If vision & height similar, try to alternate gender? (Complex, skip for simple sort)
219
+
220
+ return scoreB - scoreA;
221
+ });
222
+
223
+ // Fill Grid
224
+ const arranged = toSort.map((s, idx) => {
225
+ // Check if grid is full
226
+ if (idx >= rows * cols) return { ...s, seatRow: undefined, seatCol: undefined };
227
+
228
+ const r = Math.floor(idx / cols) + 1;
229
+ // Snaking layout? Or simple LTR? Simple LTR for now.
230
+ // Let's do simple: Row 1 L->R, Row 2 L->R...
231
+ const c = (idx % cols) + 1;
232
+
233
+ return { ...s, seatRow: r, seatCol: c };
234
+ });
235
+
236
+ setStudents(arranged);
237
+ setToast({ show: true, message: '智能排座完成,请微调后保存', type: 'success' });
238
+ };
239
+
240
+ const saveSeating = async () => {
241
+ setLoading(true);
242
+ try {
243
+ // Save seating config (rows/cols)
244
+ if (myClassInfo) {
245
+ await fetch(`/api/classes/${myClassInfo._id}`, {
246
+ method: 'PUT',
247
+ headers: { 'Content-Type': 'application/json', 'x-school-id': currentUser?.schoolId || '' },
248
+ body: JSON.stringify({ seatingConfig: { rows, cols } })
249
+ });
250
+ }
251
+
252
+ // Save students positions
253
+ const promises = students.map(s => api.students.update(s._id || String(s.id), {
254
+ seatRow: s.seatRow,
255
+ seatCol: s.seatCol
256
+ }));
257
+ await Promise.all(promises);
258
+ setToast({ show: true, message: '座位表已保存', type: 'success' });
259
+ } catch (e) { setToast({ show: true, message: '保存失败', type: 'error' }); }
260
+ finally { setLoading(false); }
261
+ };
262
+
263
+ // --- Render Helpers ---
264
+ const getVisionIcon = (v?: string) => {
265
+ if (v === 'Near-Severe') return <EyeOff size={12} className="text-red-500"/>;
266
+ if (v === 'Near-Mild') return <Eye size={12} className="text-orange-500"/>;
267
+ if (v === 'Far') return <Eye size={12} className="text-blue-500"/>;
268
+ return <Eye size={12} className="text-green-500"/>;
269
+ };
270
+
271
+ const getCharIcon = (c?: string) => {
272
+ if (c === 'Active') return <Smile size={12} className="text-orange-500"/>;
273
+ if (c === 'Quiet') return <Meh size={12} className="text-blue-500"/>;
274
+ if (c === 'Naughty') return <Frown size={12} className="text-red-500"/>;
275
+ return <Smile size={12} className="text-green-500"/>;
276
+ };
277
+
278
+ if (!homeroomClass) return <div className="p-10 text-center text-gray-500">您尚未绑定班级,请先联系管理员或在个人中心申请。</div>;
279
+
280
+ const filteredStudents = students.filter(s => s.name.includes(searchTerm) || s.studentNo.includes(searchTerm));
281
+ const unseatedStudents = students.filter(s => !s.seatRow || !s.seatCol);
282
+
283
+ return (
284
+ <div className="h-full flex flex-col bg-slate-50 overflow-hidden relative">
285
+ {toast.show && <Toast message={toast.message} type={toast.type} onClose={()=>setToast({...toast, show: false})}/>}
286
+
287
+ {/* Header */}
288
+ <div className="bg-white border-b border-gray-200 px-6 py-4 flex justify-between items-center shrink-0">
289
+ <div className="flex items-center gap-4">
290
+ <button onClick={() => window.history.back()} className="text-gray-400 hover:text-gray-600 lg:hidden"><ArrowLeftRight size={20}/></button>
291
+ <div>
292
+ <h1 className="text-xl font-bold text-gray-800 flex items-center">
293
+ {homeroomClass} 班级管理
294
+ <span className="ml-3 text-xs bg-blue-100 text-blue-700 px-2 py-0.5 rounded-full border border-blue-200">班主任: {currentUser?.trueName}</span>
295
+ </h1>
296
+ </div>
297
+ </div>
298
+ <div className="flex bg-gray-100 p-1 rounded-lg">
299
+ <button onClick={() => setActiveTab('roster')} className={`px-4 py-2 rounded-md text-sm font-bold transition-all flex items-center gap-2 ${activeTab === 'roster' ? 'bg-white shadow text-blue-600' : 'text-gray-500'}`}>
300
+ <Users size={16}/> 学生画像
301
+ </button>
302
+ <button onClick={() => setActiveTab('seating')} className={`px-4 py-2 rounded-md text-sm font-bold transition-all flex items-center gap-2 ${activeTab === 'seating' ? 'bg-white shadow text-purple-600' : 'text-gray-500'}`}>
303
+ <Grid size={16}/> 教室排座
304
+ </button>
305
+ </div>
306
+ </div>
307
+
308
+ {/* Content */}
309
+ <div className="flex-1 overflow-hidden relative">
310
+
311
+ {/* TAB: ROSTER */}
312
+ {activeTab === 'roster' && (
313
+ <div className="h-full flex flex-col p-6 overflow-y-auto">
314
+ {/* Stats Bar */}
315
+ <div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
316
+ <div className="bg-white p-4 rounded-xl border border-blue-100 shadow-sm">
317
+ <div className="text-xs text-gray-500 font-bold uppercase mb-1">男生 / 女生</div>
318
+ <div className="flex items-end gap-2">
319
+ <span className="text-2xl font-black text-blue-600">{students.filter(s=>s.gender==='Male').length}</span>
320
+ <span className="text-gray-300">/</span>
321
+ <span className="text-2xl font-black text-pink-500">{students.filter(s=>s.gender==='Female').length}</span>
322
+ </div>
323
+ </div>
324
+ <div className="bg-white p-4 rounded-xl border border-green-100 shadow-sm">
325
+ <div className="text-xs text-gray-500 font-bold uppercase mb-1">视力不良率</div>
326
+ <div className="text-2xl font-black text-green-600">
327
+ {Math.round((students.filter(s=>s.vision==='Near-Severe'||s.vision==='Near-Mild').length / students.length)*100) || 0}%
328
+ </div>
329
+ </div>
330
+ <div className="bg-white p-4 rounded-xl border border-orange-100 shadow-sm">
331
+ <div className="text-xs text-gray-500 font-bold uppercase mb-1">平均身高</div>
332
+ <div className="text-2xl font-black text-orange-600">
333
+ {Math.round(students.reduce((acc,s)=>acc+(s.height||0),0) / students.filter(s=>s.height).length) || '-'} <span className="text-xs text-gray-400">cm</span>
334
+ </div>
335
+ </div>
336
+ <div className="bg-white p-4 rounded-xl border border-purple-100 shadow-sm flex flex-col justify-center">
337
+ <button onClick={() => setIsImportOpen(true)} className="w-full bg-purple-50 text-purple-700 py-2 rounded-lg font-bold text-sm hover:bg-purple-100 flex items-center justify-center gap-2 border border-purple-200">
338
+ <FileSpreadsheet size={16}/> 批量导入特征
339
+ </button>
340
+ </div>
341
+ </div>
342
+
343
+ {/* Search & List */}
344
+ <div className="bg-white border border-gray-200 rounded-xl shadow-sm flex-1 flex flex-col overflow-hidden">
345
+ <div className="p-4 border-b border-gray-100 flex justify-between items-center bg-gray-50">
346
+ <h3 className="font-bold text-gray-700">学生特征列表</h3>
347
+ <div className="relative">
348
+ <input className="pl-9 pr-3 py-2 border rounded-lg text-sm w-64 focus:ring-2 focus:ring-blue-500 outline-none" placeholder="搜索姓名..." value={searchTerm} onChange={e=>setSearchTerm(e.target.value)}/>
349
+ <Search className="absolute left-3 top-2.5 text-gray-400" size={16}/>
350
+ </div>
351
+ </div>
352
+ <div className="flex-1 overflow-y-auto">
353
+ <table className="w-full text-left">
354
+ <thead className="bg-gray-100 text-gray-500 text-xs uppercase sticky top-0 z-10">
355
+ <tr>
356
+ <th className="p-4">姓名 / 学号</th>
357
+ <th className="p-4">身高 (cm)</th>
358
+ <th className="p-4">视力状况</th>
359
+ <th className="p-4">性格特征</th>
360
+ <th className="p-4 text-right">操作</th>
361
+ </tr>
362
+ </thead>
363
+ <tbody className="divide-y divide-gray-100 text-sm">
364
+ {filteredStudents.map(s => (
365
+ <tr key={s._id} className="hover:bg-blue-50/30 transition-colors">
366
+ <td className="p-4">
367
+ <div className="font-bold text-gray-800">{s.name}</div>
368
+ <div className="text-xs text-gray-400">{s.studentNo}</div>
369
+ </td>
370
+ <td className="p-4 font-mono">{s.height ? `${s.height}cm` : <span className="text-gray-300">-</span>}</td>
371
+ <td className="p-4">
372
+ <div className="flex items-center gap-2">
373
+ {getVisionIcon(s.vision)}
374
+ <span className="text-gray-600">
375
+ {s.vision === 'Near-Severe' ? '重度近视' : s.vision === 'Near-Mild' ? '轻度近视' : s.vision === 'Far' ? '远视' : '正常'}
376
+ </span>
377
+ </div>
378
+ </td>
379
+ <td className="p-4">
380
+ <div className="flex items-center gap-2">
381
+ {getCharIcon(s.character)}
382
+ <span className="text-gray-600">
383
+ {s.character === 'Active' ? '活泼多话' : s.character === 'Quiet' ? '安静沉稳' : s.character === 'Naughty' ? '调皮' : '普通'}
384
+ </span>
385
+ </div>
386
+ </td>
387
+ <td className="p-4 text-right">
388
+ <button onClick={() => handleOpenEdit(s)} className="text-blue-500 hover:bg-blue-50 p-1.5 rounded"><Edit size={16}/></button>
389
+ </td>
390
+ </tr>
391
+ ))}
392
+ </tbody>
393
+ </table>
394
+ </div>
395
+ </div>
396
+ </div>
397
+ )}
398
+
399
+ {/* TAB: SEATING */}
400
+ {activeTab === 'seating' && (
401
+ <div className="h-full flex flex-col md:flex-row bg-gray-100">
402
+ {/* Left: Tools & Unseated */}
403
+ <div className="w-full md:w-72 bg-white border-r border-gray-200 flex flex-col shadow-sm z-20">
404
+ <div className="p-4 border-b border-gray-100">
405
+ <h3 className="font-bold text-gray-800 mb-3 flex items-center"><Grid size={18} className="mr-2 text-blue-600"/> 教室布局</h3>
406
+ <div className="flex gap-2 mb-3">
407
+ <div className="flex-1">
408
+ <label className="text-xs text-gray-500 mb-1 block">行数</label>
409
+ <div className="flex items-center border rounded-lg px-2 py-1">
410
+ <button onClick={()=>setRows(Math.max(1, rows-1))} className="text-gray-400 hover:text-blue-600">-</button>
411
+ <input className="w-full text-center text-sm font-bold outline-none" value={rows} readOnly/>
412
+ <button onClick={()=>setRows(rows+1)} className="text-gray-400 hover:text-blue-600">+</button>
413
+ </div>
414
+ </div>
415
+ <div className="flex-1">
416
+ <label className="text-xs text-gray-500 mb-1 block">列数</label>
417
+ <div className="flex items-center border rounded-lg px-2 py-1">
418
+ <button onClick={()=>setCols(Math.max(1, cols-1))} className="text-gray-400 hover:text-blue-600">-</button>
419
+ <input className="w-full text-center text-sm font-bold outline-none" value={cols} readOnly/>
420
+ <button onClick={()=>setCols(cols+1)} className="text-gray-400 hover:text-blue-600">+</button>
421
+ </div>
422
+ </div>
423
+ </div>
424
+ <button onClick={autoArrange} className="w-full bg-gradient-to-r from-purple-500 to-indigo-500 text-white py-2 rounded-lg font-bold text-sm shadow-md hover:shadow-lg transition-all flex items-center justify-center gap-2">
425
+ <Wand2 size={16}/> 智能排座算法
426
+ </button>
427
+ </div>
428
+
429
+ <div className="flex-1 overflow-y-auto p-4 bg-gray-50">
430
+ <h4 className="text-xs font-bold text-gray-500 uppercase mb-3 flex justify-between">
431
+ 待排座学生
432
+ <span className="bg-red-100 text-red-600 px-2 rounded-full">{unseatedStudents.length}</span>
433
+ </h4>
434
+ <div className="grid grid-cols-2 gap-2">
435
+ {unseatedStudents.map(s => (
436
+ <div
437
+ key={s._id}
438
+ draggable
439
+ onDragStart={() => setDraggedStudentId(s._id || String(s.id))}
440
+ className="bg-white p-2 rounded border border-gray-200 shadow-sm cursor-grab active:cursor-grabbing hover:border-blue-300 transition-colors"
441
+ >
442
+ <div className="font-bold text-sm text-gray-800 truncate">{s.name}</div>
443
+ <div className="flex items-center justify-between mt-1">
444
+ <span className="text-[10px] text-gray-400 font-mono">{s.height || '?'}cm</span>
445
+ {getVisionIcon(s.vision)}
446
+ </div>
447
+ </div>
448
+ ))}
449
+ </div>
450
+ </div>
451
+ </div>
452
+
453
+ {/* Center: Grid */}
454
+ <div className="flex-1 p-8 overflow-auto flex flex-col items-center">
455
+ {/* Blackboard */}
456
+ <div className="w-[60%] h-16 bg-gray-700 rounded-b-xl mb-12 flex items-center justify-center shadow-lg text-gray-300 font-bold tracking-[1em] text-lg border-b-4 border-gray-600">
457
+ 讲台 (TEACHER)
458
+ </div>
459
+
460
+ <div
461
+ className="grid gap-4"
462
+ style={{ gridTemplateColumns: `repeat(${cols}, minmax(100px, 1fr))` }}
463
+ >
464
+ {Array.from({ length: rows * cols }).map((_, idx) => {
465
+ const r = Math.floor(idx / cols) + 1;
466
+ const c = (idx % cols) + 1;
467
+ const student = getStudentAt(r, c);
468
+
469
+ return (
470
+ <div
471
+ key={`${r}-${c}`}
472
+ onDragOver={e => e.preventDefault()}
473
+ onDrop={() => handleDrop(r, c)}
474
+ className={`
475
+ relative w-32 h-24 rounded-xl border-2 transition-all flex flex-col items-center justify-center p-2
476
+ ${student ? 'bg-white border-blue-200 shadow-sm' : 'bg-gray-50 border-dashed border-gray-300 hover:bg-blue-50'}
477
+ `}
478
+ >
479
+ {/* Seat Label */}
480
+ <div className="absolute top-1 left-1 text-[9px] text-gray-300 font-mono select-none">R{r}-C{c}</div>
481
+
482
+ {student ? (
483
+ <div
484
+ draggable
485
+ onDragStart={() => setDraggedStudentId(student._id || String(student.id))}
486
+ className="w-full h-full cursor-grab active:cursor-grabbing flex flex-col items-center justify-center"
487
+ >
488
+ <div className={`w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold text-white mb-1 ${student.gender==='Female'?'bg-pink-400':'bg-blue-400'}`}>
489
+ {student.name[0]}
490
+ </div>
491
+ <div className="font-bold text-gray-800 text-sm truncate w-full text-center">{student.name}</div>
492
+ <div className="flex gap-2 mt-1 opacity-60">
493
+ <div className="flex items-center text-[10px] text-gray-500"><Ruler size={10} className="mr-0.5"/>{student.height||'-'}</div>
494
+ <div title={student.vision}>{getVisionIcon(student.vision)}</div>
495
+ <div title={student.character}>{getCharIcon(student.character)}</div>
496
+ </div>
497
+ {/* Conflict Indicator (Simple example: bad vision in back) */}
498
+ {r > rows/2 && (student.vision === 'Near-Severe' || student.vision === 'Near-Mild') && (
499
+ <div className="absolute top-1 right-1 text-red-500 animate-pulse" title="视力不佳不宜后排"><AlertTriangle size={12}/></div>
500
+ )}
501
+ </div>
502
+ ) : (
503
+ <span className="text-xs text-gray-300 font-bold">空座</span>
504
+ )}
505
+ </div>
506
+ );
507
+ })}
508
+ </div>
509
+ </div>
510
+
511
+ {/* Floating Action */}
512
+ <div className="absolute bottom-6 right-6 flex flex-col gap-3">
513
+ <div className="bg-white p-3 rounded-lg shadow-lg border border-gray-100 text-xs text-gray-500 space-y-1">
514
+ <div className="flex items-center gap-2"><Eye size={12} className="text-green-500"/> 视力正常</div>
515
+ <div className="flex items-center gap-2"><EyeOff size={12} className="text-red-500"/> 重度近视</div>
516
+ <div className="flex items-center gap-2"><Smile size={12} className="text-orange-500"/> 活泼多话</div>
517
+ </div>
518
+ <button onClick={saveSeating} disabled={loading} className="bg-blue-600 text-white p-4 rounded-full shadow-xl hover:bg-blue-700 hover:scale-105 transition-all flex items-center justify-center">
519
+ {loading ? <Loader2 className="animate-spin" size={24}/> : <Save size={24}/>}
520
+ </button>
521
+ </div>
522
+ </div>
523
+ )}
524
+ </div>
525
+
526
+ {/* Edit Modal */}
527
+ {isEditModalOpen && (
528
+ <div className="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center p-4">
529
+ <div className="bg-white rounded-xl w-full max-w-sm p-6 shadow-2xl animate-in zoom-in-95">
530
+ <h3 className="font-bold text-lg mb-4 text-gray-800">编辑特征 - {editingStudent?.name}</h3>
531
+ <div className="space-y-4">
532
+ <div>
533
+ <label className="block text-xs font-bold text-gray-500 uppercase mb-1">身高 (cm)</label>
534
+ <input type="number" className="w-full border rounded p-2" value={editForm.height} onChange={e=>setEditForm({...editForm, height: e.target.value})}/>
535
+ </div>
536
+ <div>
537
+ <label className="block text-xs font-bold text-gray-500 uppercase mb-1">视力状况</label>
538
+ <select className="w-full border rounded p-2 bg-white" value={editForm.vision} onChange={e=>setEditForm({...editForm, vision: e.target.value})}>
539
+ <option value="Normal">正常 (Normal)</option>
540
+ <option value="Near-Mild">轻度近视 (Mild)</option>
541
+ <option value="Near-Severe">重度近视 (Severe)</option>
542
+ <option value="Far">远视 (Far)</option>
543
+ </select>
544
+ </div>
545
+ <div>
546
+ <label className="block text-xs font-bold text-gray-500 uppercase mb-1">性格特征 (用于排座参考)</label>
547
+ <select className="w-full border rounded p-2 bg-white" value={editForm.character} onChange={e=>setEditForm({...editForm, character: e.target.value})}>
548
+ <option value="Normal">普通 (Normal)</option>
549
+ <option value="Active">活泼/多话 (Active)</option>
550
+ <option value="Quiet">安静/内向 (Quiet)</option>
551
+ <option value="Naughty">调皮 (Naughty)</option>
552
+ <option value="Steady">沉稳 (Steady)</option>
553
+ </select>
554
+ </div>
555
+ <div className="flex gap-2 pt-2">
556
+ <button onClick={()=>setIsEditModalOpen(false)} className="flex-1 py-2 bg-gray-100 rounded text-gray-600">取消</button>
557
+ <button onClick={handleSaveStudentAttr} className="flex-1 py-2 bg-blue-600 text-white rounded font-bold">保存</button>
558
+ </div>
559
+ </div>
560
+ </div>
561
+ </div>
562
+ )}
563
+
564
+ {/* Import Modal */}
565
+ {isImportOpen && (
566
+ <div className="fixed inset-0 bg-black/50 z-[100] flex items-center justify-center p-4">
567
+ <div className="bg-white rounded-xl w-full max-w-md p-6 shadow-2xl animate-in zoom-in-95">
568
+ <h3 className="font-bold text-lg mb-2">批量导入特征</h3>
569
+ <p className="text-xs text-gray-500 mb-4">请上传包含以下列的 Excel: 姓名, 身高, 视力, 性格。<br/>(视力填: 正常/轻度/重度; 性格填: 活泼/安静/普通)</p>
570
+ <input type="file" accept=".xlsx, .xls" onChange={e => setImportFile(e.target.files?.[0] || null)} className="mb-4 block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"/>
571
+ <div className="flex gap-2">
572
+ <button onClick={()=>setIsImportOpen(false)} className="flex-1 py-2 bg-gray-100 rounded">取消</button>
573
+ <button onClick={handleExcelImport} disabled={!importFile || importing} className="flex-1 py-2 bg-blue-600 text-white rounded font-bold disabled:opacity-50">
574
+ {importing ? '处理中...' : '开始导入'}
575
+ </button>
576
+ </div>
577
+ </div>
578
+ </div>
579
+ )}
580
+ </div>
581
+ );
582
+ };
types.ts CHANGED
@@ -69,6 +69,12 @@ export interface Student {
69
  drawAttempts?: number;
70
  dailyDrawLog?: { date: string, count: number };
71
  flowerBalance?: number;
 
 
 
 
 
 
72
  }
73
 
74
  export interface PeriodConfig {
@@ -88,6 +94,7 @@ export interface ClassInfo {
88
  homeroomTeacherIds?: string[];
89
  studentCount?: number;
90
  periodConfig?: PeriodConfig[]; // Added class-specific period config
 
91
  }
92
 
93
  export interface Course {
@@ -398,4 +405,4 @@ export interface AIChatMessage {
398
  isAudioMessage?: boolean;
399
  isGeneratingAudio?: boolean; // New status flag for UI
400
  timestamp: number;
401
- }
 
69
  drawAttempts?: number;
70
  dailyDrawLog?: { date: string, count: number };
71
  flowerBalance?: number;
72
+ // New Seating Fields
73
+ height?: number; // cm
74
+ vision?: 'Normal' | 'Near-Mild' | 'Near-Severe' | 'Far' | 'Unknown';
75
+ character?: 'Active' | 'Quiet' | 'Naughty' | 'Steady' | 'Unknown';
76
+ seatRow?: number;
77
+ seatCol?: number;
78
  }
79
 
80
  export interface PeriodConfig {
 
94
  homeroomTeacherIds?: string[];
95
  studentCount?: number;
96
  periodConfig?: PeriodConfig[]; // Added class-specific period config
97
+ seatingConfig?: { rows: number; cols: number; }; // New layout config
98
  }
99
 
100
  export interface Course {
 
405
  isAudioMessage?: boolean;
406
  isGeneratingAudio?: boolean; // New status flag for UI
407
  timestamp: number;
408
+ }