paper
parent
f258d6676a
commit
33c72f66c2
|
|
@ -12,8 +12,8 @@ module.exports = {
|
|||
// 可通过环境变量覆盖: SAFETY_EVAL_API_HOST=http://192.168.x.x:8095
|
||||
//API_HOST: "http://localhost:80",
|
||||
|
||||
API_HOST: "http://192.168.0.134",
|
||||
// API_HOST: "http://192.168.0.150", //太浅
|
||||
// API_HOST: "http://192.168.0.134",
|
||||
API_HOST: "http://192.168.0.150", //太浅
|
||||
// API_HOST: "https://gbs-gateway.qhdsafety.com",
|
||||
// API_HOST: "http://192.168.0.103", //huwei
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
@ -27,6 +29,7 @@ const App = (props) => {
|
|||
const [expandedMap, setExpandedMap] = useState({});
|
||||
const [fileId, setFileId] = useState(props.fileId);
|
||||
const [templateMap, setTemplateMap] = useState([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const sdkRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -51,6 +54,29 @@ const App = (props) => {
|
|||
message.success("保存成功");
|
||||
};
|
||||
|
||||
const beforeUploadWord = (file) => {
|
||||
if (!/\.(docx?)$/i.test(file.name)) {
|
||||
message.error("仅支持上传 Word 文件(.doc / .docx)");
|
||||
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 () => {
|
||||
if (!sdkRef.current) {
|
||||
message.warning("文档尚未加载完成");
|
||||
|
|
@ -162,9 +188,19 @@ const App = (props) => {
|
|||
}
|
||||
extra={
|
||||
<Flex gap={12}>
|
||||
{!readOnly && (
|
||||
<Upload
|
||||
accept=".doc,.docx"
|
||||
showUploadList={false}
|
||||
beforeUpload={beforeUploadWord}
|
||||
disabled={uploading}
|
||||
>
|
||||
<Button loading={uploading}>上传Word文件</Button>
|
||||
</Upload>
|
||||
)}
|
||||
{!readOnly && <Button onClick={handleSave}>保存</Button>}
|
||||
<Button onClick={handleDownload}>下载报告</Button>
|
||||
|
||||
|
||||
</Flex>
|
||||
}
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in New Issue