实现Word文件下载

This commit is contained in:
Vectorune
2025-11-09 16:01:09 +08:00
parent 2984cb5c7a
commit 7440c3d980
2 changed files with 35 additions and 2 deletions

View File

@ -31,6 +31,29 @@ const CardAction = (record, messageApi, navigator) => {
});
}
const downloadWordRecord = (recordId) => {
let baseUrl = baseWebConfig.baseUrl
commonAxios.get(`${baseUrl}/api/v1/workload/certificate/downloadWord/${recordId}`, {responseType: 'blob'}).then((response) => {
if (response.data.type === 'application/json') {
messageApi.error('证明已失效 (GENERATE_CERTIFICATE_ERROR_007)');
setTimeout(() => {
window.location.reload();
}, 1000);
} else {
let fileName = `certificate-${recordId}.docx`;
const blob = new Blob([response.data], {type: 'application/octet-stream'});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
}
});
}
const reGenerateRecord = (record) => {
if (record.status === '01' || record.status === '02') {
@ -83,7 +106,17 @@ const CardAction = (record, messageApi, navigator) => {
>
<RetweetOutlined/>
</Popconfirm>] : []),
...(record.status === '02' ? [<DownloadOutlined onClick={() => downloadRecord(record.id)}/>] : []),
...(record.status === '02' ? [
<span onClick={() => downloadRecord(record.id)} style={{ marginRight: 16, cursor: 'pointer' }}>
<DownloadOutlined style={{ marginRight: 4 }} />
下载PDF
</span>,
//downloadWordRecord
<span onClick={() => downloadWordRecord(record.id)} style={{ cursor: 'pointer' }}>
<DownloadOutlined style={{ marginRight: 4 }} />
下载Word
</span>
] : []),
...(record.status === '03' || record.status === '04'
? [<Popconfirm
title="删除证明记录"

View File

@ -26,7 +26,7 @@ function PrintRecordCard(props) {
<Card
bordered={true}
bodyStyle={{
height: 200
height: 250
}}
style={{minWidth: 400}}
hoverable={true}