fix: update StudentProfileContent report buttons to use /report-html, remove dead /report references

This commit is contained in:
2026-07-07 10:03:19 +08:00
parent d3437311dc
commit a7cb2865a9

View File

@@ -29,8 +29,6 @@ import {
EyeOutlined, EyeOutlined,
CloseOutlined, CloseOutlined,
FileTextOutlined, FileTextOutlined,
FilePdfOutlined,
CameraOutlined,
ReloadOutlined, ReloadOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -741,33 +739,16 @@ const StudentProfileContent: React.FC<StudentProfileContentProps> = ({
void fetchData(); void fetchData();
}, [fetchData]); }, [fetchData]);
const handleDownloadReport = useCallback(() => { const handlePreviewReport = useCallback(async () => {
const token = localStorage.getItem('token');
window.open(`/api/archive/${studentId}/report?token=${token}`, '_blank');
}, [studentId]);
const handlePreviewReport = useCallback(() => {
const token = localStorage.getItem('token');
window.open(`/api/archive/${studentId}/report?token=${token}`, '_blank');
}, [studentId]);
const handleDownloadPdf = useCallback(async () => {
const token = localStorage.getItem('token');
try { try {
const res = await fetch(`/api/archive/${studentId}/report`, { const { html } = await api.get<{ html: string }>(`/archive/${studentId}/report-html`);
headers: { Authorization: `Bearer ${token}` }, const w = window.open('', '_blank');
}); if (w) {
if (!res.ok) throw new Error('下载失败'); w.document.write(html);
const blob = await res.blob(); w.document.close();
const url = URL.createObjectURL(blob); }
const a = document.createElement('a'); } catch {
a.href = url; message.error('加载报告失败');
a.download = `学员档案_${studentId}.pdf`;
a.click();
URL.revokeObjectURL(url);
} catch (e: unknown) {
const err = e as { message?: string };
message.error(err?.message || 'PDF下载失败');
} }
}, [studentId]); }, [studentId]);
@@ -787,13 +768,7 @@ const StudentProfileContent: React.FC<StudentProfileContentProps> = ({
</Space> </Space>
<Space> <Space>
<Button icon={<FileTextOutlined />} onClick={handlePreviewReport}> <Button icon={<FileTextOutlined />} onClick={handlePreviewReport}>
</Button>
<Button icon={<FilePdfOutlined />} onClick={handleDownloadPdf}>
PDF下载
</Button>
<Button icon={<CameraOutlined />} onClick={handleDownloadReport}>
</Button> </Button>
<Button icon={<ReloadOutlined />} onClick={fetchData} loading={loading}> <Button icon={<ReloadOutlined />} onClick={fetchData} loading={loading}>