From bdd3ab3724d000d6870f00c0e3c3d10f0cbc600b Mon Sep 17 00:00:00 2001 From: NanGua-QWQ Date: Wed, 4 Feb 2026 14:54:35 +0800 Subject: [PATCH] =?UTF-8?q?NEW=EF=BC=9ANow=20can=20select=20many=20many=20?= =?UTF-8?q?students!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/AutoScoreManager.tsx | 78 +++++++++++++------ src/renderer/src/components/ScoreManager.tsx | 55 ++++++++----- 2 files changed, 90 insertions(+), 43 deletions(-) diff --git a/src/renderer/src/components/AutoScoreManager.tsx b/src/renderer/src/components/AutoScoreManager.tsx index c82255f..75664df 100644 --- a/src/renderer/src/components/AutoScoreManager.tsx +++ b/src/renderer/src/components/AutoScoreManager.tsx @@ -13,6 +13,8 @@ import { Switch, Popconfirm, Radio, + Select, + TooltipLite } from 'tdesign-react' interface AutoScoreRule { @@ -36,6 +38,7 @@ interface AutoScoreRuleFormValues { export const AutoScoreManager: React.FC = () => { const [rules, setRules] = useState([]) + const [students, setStudents] = useState<{ id: number; name: string }[]>([]) const [loading, setLoading] = useState(false) const [form] = Form.useForm() const [editingRuleId, setEditingRuleId] = useState(null) @@ -58,11 +61,17 @@ export const AutoScoreManager: React.FC = () => { console.warn('Auth check failed', e) } - const res = await (window as any).api.invoke('auto-score:getRules', {}) - if (res.success) { - setRules(res.data) + const [rulesRes, studentsRes] = await Promise.all([ + (window as any).api.invoke('auto-score:getRules', {}), + (window as any).api.queryStudents({}) + ]) + if (rulesRes.success) { + setRules(rulesRes.data) } else { - MessagePlugin.error(res.message || '获取规则失败') + MessagePlugin.error(rulesRes.message || '获取规则失败') + } + if (studentsRes.success) { + setStudents(studentsRes.data) } } catch (error) { console.error('Failed to fetch auto score rules:', error) @@ -77,29 +86,29 @@ export const AutoScoreManager: React.FC = () => { }, []) const handleSubmit = async () => { - if (!(window as any).api) return - - // 修复类型转换错误,使用更安全的方式获取表单值 - const values = form.getFieldsValue(true) as unknown as AutoScoreRuleFormValues - + if (!(window as any).api) return; + + const values = form.getFieldsValue(true) as unknown as AutoScoreRuleFormValues & { timeUnit: string }; + if (!values.name || values.intervalMinutes == null || values.scoreValue == null) { - MessagePlugin.warning('请填写完整信息') - return + MessagePlugin.warning('请填写完整信息'); + return; } - // 解析学生姓名列表(以逗号分隔) - const studentNames = values.studentNames - ? values.studentNames.split(',').map(name => name.trim()).filter(name => name) - : [] + // 根据单位转换间隔时间 + const intervalMinutes = values.timeUnit === 'days' ? values.intervalMinutes * 1440 : values.intervalMinutes; + + // 确保 studentNames 是数组类型 + const studentNames = Array.isArray(values.studentNames) ? values.studentNames : []; const ruleData = { - enabled: true, // 默认启用新规则 + enabled: true, name: values.name, - intervalMinutes: values.intervalMinutes, + intervalMinutes, studentNames, scoreValue: values.scoreValue, - reason: values.reason || `自动化加分 - ${values.name}` - } + reason: values.reason || `自动化加分 - ${values.name}`, + }; // 权限检查:仅管理员可创建/更新规则 try { @@ -133,7 +142,8 @@ export const AutoScoreManager: React.FC = () => { intervalMinutes: undefined, studentNames: '', scoreValue: undefined, - reason: '' + reason: '', + timeUnit: 'minutes' }) setEditingRuleId(null) fetchRules() // 刷新规则列表 @@ -240,7 +250,12 @@ export const AutoScoreManager: React.FC = () => { colKey: 'intervalMinutes', title: '间隔', width: 100, - cell: ({ row }) => `${row.intervalMinutes} 分钟` + cell: ({ row }) => { + const isDays = row.intervalMinutes >= 1440 + const value = isDays ? row.intervalMinutes / 1440 : row.intervalMinutes + const unit = isDays ? '天' : '分钟' + return `${value} ${unit}` + } }, { colKey: 'scoreValue', @@ -260,7 +275,17 @@ export const AutoScoreManager: React.FC = () => { if (row.studentNames.length === 0) { return 所有学生 } - return {row.studentNames.length} 名学生 + const studentList = row.studentNames.join(',\n') + return ( + + {row.studentNames.length} 名学生 + + ) } }, { colKey: 'reason', title: '理由', ellipsis: true }, @@ -336,7 +361,7 @@ export const AutoScoreManager: React.FC = () => { > - + 分钟 @@ -357,7 +382,12 @@ export const AutoScoreManager: React.FC = () => { label="适用学生" name="studentNames" > - + matchStudentName(getOptionLabel(option), filterWords)