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