报告编制支持pdf

dev-tmp1
tangjie 2026-08-26 16:16:54 +08:00
parent c116b4aed8
commit ad35026c7f
4 changed files with 21 additions and 7 deletions

View File

@ -13,8 +13,8 @@ module.exports = {
//API_HOST: "http://localhost:80", //API_HOST: "http://localhost:80",
// API_HOST: "http://192.168.0.134", // API_HOST: "http://192.168.0.134",
API_HOST: "http://192.168.0.150", //太浅 //API_HOST: "http://192.168.0.150", //太浅
// API_HOST: "https://gbs-gateway.qhdsafety.com", API_HOST: "https://gbs-gateway.qhdsafety.com",
// API_HOST: "http://192.168.0.103", //huwei // API_HOST: "http://192.168.0.103", //huwei
}, },
production: { production: {

View File

@ -523,6 +523,7 @@ const EvalProjectMonitorDetail = (props) => {
<WpsEditor <WpsEditor
onCancel={() => setWpsVisible(false)} onCancel={() => setWpsVisible(false)}
fileId={wpsDoc?.fileId} fileId={wpsDoc?.fileId}
fileName={wpsDoc?.name}
readOnly readOnly
/> />
)} )}

View File

@ -271,7 +271,7 @@ const ProjectFlow = (props) => {
destroyOnHidden destroyOnHidden
/> />
{visible && ( {visible && (
<WpsEditor onCancel={() => setVisible(false)} fileId={wpsDoc?.fileId} readOnly={readOnly || evalProjectDetailData?.archiveFlag === 1} /> <WpsEditor onCancel={() => setVisible(false)} fileId={wpsDoc?.fileId} fileName={wpsDoc?.name} readOnly={readOnly || evalProjectDetailData?.archiveFlag === 1} />
)} )}
</PageLayout> </PageLayout>
); );

View File

@ -24,11 +24,16 @@ import ErrorBoundary from "./ErrorBoundary";
const { router } = tools; const { router } = tools;
const App = (props) => { const App = (props) => {
const { onCancel, safetyEvalBusiness, readOnly } = props; const { onCancel, safetyEvalBusiness, readOnly, fileName } = props;
const { createDocLoading, evalReportCompletePreparationLoading } = const { createDocLoading, evalReportCompletePreparationLoading } =
safetyEvalBusiness; safetyEvalBusiness;
const [expandedMap, setExpandedMap] = useState({}); const [expandedMap, setExpandedMap] = useState({});
const [fileId, setFileId] = useState(props.fileId); const [fileId, setFileId] = useState(props.fileId);
// 当前文档类型word / pdf决定 SDK 初始化时使用的 officeType
// 初始类型通过初始报告文件名fileName推断
const [fileType, setFileType] = useState(() =>
/\.pdf$/i.test(props.fileName || "") ? "pdf" : "word"
);
const [templateMap, setTemplateMap] = useState([]); const [templateMap, setTemplateMap] = useState([]);
const [uploading, setUploading] = useState(false); const [uploading, setUploading] = useState(false);
const sdkRef = useRef(null); const sdkRef = useRef(null);
@ -73,12 +78,14 @@ const App = (props) => {
if (!newFileId) { if (!newFileId) {
throw new Error(res?.errMessage || res?.message || "上传失败"); throw new Error(res?.errMessage || res?.message || "上传失败");
} }
setFileType(/\.pdf$/i.test(file.name) ? "pdf" : "word");
setFileId(newFileId); setFileId(newFileId);
props.queryMyOrCreateDoc({ props.queryMyOrCreateDoc({
docxUrl: "", docxUrl: "",
projectId:router.query.id, projectId:router.query.id,
}); });
message.success("Word 文件上传成功,已在编辑器中打开"); message.success("文件上传成功,已在编辑器中打开");
}) })
.catch((e) => { .catch((e) => {
message.error(e?.message || "上传失败,请重试"); message.error(e?.message || "上传失败,请重试");
@ -107,7 +114,7 @@ const App = (props) => {
const blobUrl = URL.createObjectURL(blob); const blobUrl = URL.createObjectURL(blob);
const a = document.createElement("a"); const a = document.createElement("a");
a.href = blobUrl; a.href = blobUrl;
a.download = `安全评价报告_${fileId}.docx`; a.download = `安全评价报告_${fileId}.${fileType === "pdf" ? "pdf" : "docx"}`;
a.click(); a.click();
URL.revokeObjectURL(blobUrl); URL.revokeObjectURL(blobUrl);
message.success("下载成功"); message.success("下载成功");
@ -151,7 +158,10 @@ const App = (props) => {
try { try {
const instance = WebOfficeSDK.init({ const instance = WebOfficeSDK.init({
// 必填项 // 必填项
officeType: WebOfficeSDK.OfficeType.Writer, officeType:
fileType === "pdf"
? WebOfficeSDK.OfficeType.Pdf
: WebOfficeSDK.OfficeType.Writer,
appId: "AK20260805KPWYZJ", appId: "AK20260805KPWYZJ",
mount: document.getElementById("app-wps"), mount: document.getElementById("app-wps"),
fileId: fileId, fileId: fileId,
@ -177,6 +187,7 @@ const App = (props) => {
} }
})(); })();
return () => { return () => {
console.log(sdkRef.current)
sdkRef.current?.destroy(); sdkRef.current?.destroy();
window.removeEventListener("error", onWindowError, { capture: true }); window.removeEventListener("error", onWindowError, { capture: true });
window.removeEventListener("unhandledrejection", onWindowError, { capture: true }); window.removeEventListener("unhandledrejection", onWindowError, { capture: true });
@ -364,6 +375,8 @@ const App = (props) => {
return; return;
} }
setFileId(fileId); setFileId(fileId);
// 模板为 docx 文档,重置为 Word 类型
setFileType("word");
}); });
}} }}
> >