diff --git a/src/api/safetyEvalBusiness/index.js b/src/api/safetyEvalBusiness/index.js index a259c2e..c6cb027 100644 --- a/src/api/safetyEvalBusiness/index.js +++ b/src/api/safetyEvalBusiness/index.js @@ -24,6 +24,27 @@ export const getDocByProjectId = declareRequest( 'wpsDoc: {} | res.data || {}', ); +/** + * 上传已有 Word 文件并创建 WPS 文档,返回可打开的 WPS 文档信息 + * multipart/form-data,declareRequest 仅支持 json,故手动 fetch + * @param {File} file Word 文件(.doc/.docx) + * @param {String} projectId 项目 ID + */ +export async function uploadWpsDoc(file, projectId) { + const formData = new FormData(); + formData.append("file", file); + formData.append("projectId", projectId); + const res = await fetch( + `${window.process.env.app.API_HOST}/safetyEval-h5/wsp/doc/upload`, + { + method: "POST", + headers: { token: sessionStorage.getItem("token") }, + body: formData, + }, + ); + return res.json(); +} + export const downloadWpsDoc = declareRequest( "downloadDocLoading", "Get > /safetyEval-h5/wsp/v3/3rd/files/{fileId}/download", @@ -339,6 +360,11 @@ export const evalReportSubmit = declareRequest( "Post > @/safetyEval/institution/eval-report/submit", ); +export const evalReportCompletePreparation = declareRequest( + "evalReportCompletePreparationLoading", + "Post > @/safetyEval/institution/eval-report/preparation/complete", +); + /** * 机构端报告库-批量报送监管端 * diff --git a/src/pages/Container/WpsEditor/index.js b/src/pages/Container/WpsEditor/index.js index 0120afe..e67ae74 100644 --- a/src/pages/Container/WpsEditor/index.js +++ b/src/pages/Container/WpsEditor/index.js @@ -8,9 +8,11 @@ import { Tag, Progress, Typography, + Upload, message, } from "antd"; import { ArrowLeftOutlined } from "@ant-design/icons"; +import { uploadWpsDoc } from "~/api/safetyEvalBusiness"; import WebOfficeSDK from "~/web-office-sdk-solution-v2.0.7/web-office-sdk-solution-v2.0.7.es.js"; import { createPortal } from "react-dom"; import { tools } from "@cqsjjb/jjb-common-lib"; @@ -23,10 +25,12 @@ const { router } = tools; const App = (props) => { const { onCancel, safetyEvalBusiness, readOnly } = props; - const { createDocLoading } = safetyEvalBusiness; + const { createDocLoading, evalReportCompletePreparationLoading } = + safetyEvalBusiness; const [expandedMap, setExpandedMap] = useState({}); const [fileId, setFileId] = useState(props.fileId); const [templateMap, setTemplateMap] = useState([]); + const [uploading, setUploading] = useState(false); const sdkRef = useRef(null); useEffect(() => { @@ -48,7 +52,36 @@ const App = (props) => { } await sdkRef.current.save(); - message.success("保存成功"); + // 完成报告编制:将 REPORT_PREPARATION 节点置为已完成,提交内审 + const res = await props.evalReportCompletePreparation({ + data: { projectId: router.query.id }, + }); + if (res?.success !== false) { + message.success("报告编制已完成,已提交内审"); + } + }; + + const beforeUploadWord = (file) => { + if (!/\.(docx?|pdf)$/i.test(file.name)) { + message.error("仅支持上传 Word / PDF 文件(.doc / .docx / .pdf)"); + return Upload.LIST_IGNORE; + } + setUploading(true); + uploadWpsDoc(file, router.query.id) + .then((res) => { + const newFileId = res?.data?.fileId; + if (!newFileId) { + throw new Error(res?.errMessage || res?.message || "上传失败"); + } + setFileId(newFileId); + message.success("Word 文件上传成功,已在编辑器中打开"); + }) + .catch((e) => { + message.error(e?.message || "上传失败,请重试"); + }) + .finally(() => setUploading(false)); + // 阻止 antd 自动上传,由手动 fetch 提交 + return false; }; const handleDownload = async () => { @@ -162,9 +195,26 @@ const App = (props) => { } extra={ - {!readOnly && } + {!readOnly && ( + + + + )} + {!readOnly && ( + + )} - + } >