diff --git a/src/api/safetyEvalBusiness/index.js b/src/api/safetyEvalBusiness/index.js index 3cf2c81..ce7ae9b 100644 --- a/src/api/safetyEvalBusiness/index.js +++ b/src/api/safetyEvalBusiness/index.js @@ -18,6 +18,11 @@ export const createWpsDoc = declareRequest( 'wpsDoc: {} | res.data || {}', ); +export const downloadWpsDoc = declareRequest( + "downloadDocLoading", + "Get > /safetyEval-h5/wsp/v3/3rd/files/:fileId/download", +); + export const customerPage = declareRequest( "customerLoading", "Get > /safetyEval/institution/eval-customer/page", diff --git a/src/pages/Container/WpsEditor/index.js b/src/pages/Container/WpsEditor/index.js index 7ad7418..ef6ec71 100644 --- a/src/pages/Container/WpsEditor/index.js +++ b/src/pages/Container/WpsEditor/index.js @@ -47,6 +47,34 @@ const App = (props) => { message.success("保存成功"); }; + const handleDownload = async () => { + if (!sdkRef.current) { + message.warning("文档尚未加载完成"); + return; + } + try { + // 先保存最新内容 + await sdkRef.current.save(); + // 调用后端下载接口获取下载地址 + const res = await props.downloadWpsDoc({ fileId }); + const url = res?.data?.url || res?.url; + if (!url) throw new Error("下载地址获取失败"); + // 跨域场景下 a.download 无效,通过 fetch 转 blob 再下载 + const blobRes = await fetch(url); + if (!blobRes.ok) throw new Error("文件下载失败"); + const blob = await blobRes.blob(); + const blobUrl = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = blobUrl; + a.download = `安全评价报告_${fileId}.docx`; + a.click(); + URL.revokeObjectURL(blobUrl); + message.success("下载成功"); + } catch { + message.error("下载失败,请重试"); + } + }; + const toggleExpand = (index) => { setExpandedMap((prev) => ({ ...prev, [index]: !prev[index] })); }; @@ -83,7 +111,7 @@ const App = (props) => { extra={ - + }