This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Button, Card, Descriptions, Empty, Space, Spin, Table, Tooltip } from 'antd';
|
||||
import { Alert, Button, Card, Descriptions, Empty, Space, Spin, Table, Tag, Tooltip } from 'antd';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { ArrowLeftOutlined, EyeOutlined } from '@ant-design/icons';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
@@ -67,11 +67,14 @@ const ExamDetailPage: React.FC = () => {
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
const saveScore = async (row: ScoreRow, value: number | undefined) => {
|
||||
await api.put(`/exams/${id}/scores/${row.id}`, { score: value ?? null });
|
||||
message.success('成绩已保存');
|
||||
await load();
|
||||
};
|
||||
const saveScore = useCallback(
|
||||
async (row: ScoreRow, value: number | undefined) => {
|
||||
await api.put(`/exams/${id}/scores/${row.id}`, { score: value ?? null });
|
||||
message.success('成绩已保存');
|
||||
await load();
|
||||
},
|
||||
[id, load],
|
||||
);
|
||||
|
||||
const columns = useMemo<ColumnsType<ScoreRow>>(() => {
|
||||
if (!detail) return [];
|
||||
@@ -93,16 +96,20 @@ const ExamDetailPage: React.FC = () => {
|
||||
dataIndex: 'score',
|
||||
width: 100,
|
||||
render: (value: number | null, row: ScoreRow) => (
|
||||
<EditableCell<number | undefined>
|
||||
value={value ?? undefined}
|
||||
editor="money"
|
||||
min={0}
|
||||
max={999.99}
|
||||
permission="exam:view"
|
||||
onSave={(next) => saveScore(row, next)}
|
||||
>
|
||||
{value ?? '-'}
|
||||
</EditableCell>
|
||||
detail.status === 'archived' ? (
|
||||
value ?? '-'
|
||||
) : (
|
||||
<EditableCell<number | undefined>
|
||||
value={value ?? undefined}
|
||||
editor="money"
|
||||
min={0}
|
||||
max={999.99}
|
||||
permission="exam:view"
|
||||
onSave={(next) => saveScore(row, next)}
|
||||
>
|
||||
{value ?? '-'}
|
||||
</EditableCell>
|
||||
)
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -120,7 +127,7 @@ const ExamDetailPage: React.FC = () => {
|
||||
{ title: '考试日期', width: 110, render: () => detail.examDate },
|
||||
{ title: '关联报读(班级名)', width: 180, render: () => detail.className },
|
||||
];
|
||||
}, [detail]);
|
||||
}, [detail, saveScore]);
|
||||
|
||||
if (loading && !detail)
|
||||
return (
|
||||
@@ -139,8 +146,12 @@ const ExamDetailPage: React.FC = () => {
|
||||
返回
|
||||
</Button>
|
||||
<h2>{detail.examName}</h2>
|
||||
{detail.status === 'archived' ? <Tag>已归档</Tag> : null}
|
||||
</Space>
|
||||
</div>
|
||||
{detail.status === 'archived' ? (
|
||||
<Alert type="info" showIcon message="该考试已归档,成绩仅供查看。如需继续录入,请先在考试列表中恢复。" />
|
||||
) : null}
|
||||
<Card className="exam-summary">
|
||||
<Descriptions column={{ xs: 1, sm: 2, lg: 5 }}>
|
||||
<Descriptions.Item label="考试类型">{detail.examType}</Descriptions.Item>
|
||||
|
||||
Reference in New Issue
Block a user