forked from wangziqi/gongxue-base
fix: update StudentProfileContent report buttons to use /report-html, remove dead /report references
This commit is contained in:
@@ -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}>
|
||||||
刷新
|
刷新
|
||||||
|
|||||||
Reference in New Issue
Block a user