diff --git a/src/pages/Container/Supervision/EvalReportDatabase/components/SpotCheckDetailModal.jsx b/src/pages/Container/Supervision/EvalReportDatabase/components/SpotCheckDetailModal.jsx new file mode 100644 index 0000000..0fe07a4 --- /dev/null +++ b/src/pages/Container/Supervision/EvalReportDatabase/components/SpotCheckDetailModal.jsx @@ -0,0 +1,163 @@ +import { Button, Modal, Space, message } from "antd"; +import dayjs from "dayjs"; + +/** 原型 .reg-modal-section */ +const ModalSection = ({ title, desc, children }) => ( +
+

{title}

+ {desc ?

{desc}

: null} + {children} +
+); + +/** 原型 tableHtml:字段表 / 数据表;kv=字段-内容两列表 */ +const ProtoTable = ({ headers, rows, kv = false }) => ( +
+ + + + {headers.map((h) => ( + + ))} + + + + {rows.map((row, idx) => ( + + {row.map((cell, cIdx) => ( + + ))} + + ))} + +
{h}
{cell}
+
+); + +const getFileExtLabel = (name = "") => { + const ext = String(name).split(".").pop(); + return ext && ext !== name ? ext.toUpperCase() : "PDF"; +}; + +/** 解析存储的 JSON 文件列表字符串,返回数组 */ +const parseFileList = (jsonStr) => { + if (!jsonStr) return []; + try { + const arr = JSON.parse(jsonStr); + return Array.isArray(arr) ? arr : []; + } catch { + return []; + } +}; + +/** 单文件本地下载 */ +const downloadFileByUrl = async (fileUrl, fileName) => { + const response = await fetch(fileUrl, { + headers: { token: sessionStorage.getItem("token") || "" }, + }); + if (!response.ok) throw new Error(`HTTP ${response.status}`); + const blob = await response.blob(); + const blobUrl = window.URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = blobUrl; + link.download = fileName || "报告文件"; + link.style.display = "none"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(blobUrl); +}; + +/** + * 抽检报告详情弹窗:直接用抽检接口返回的行数据展示,不调详情接口 + */ +const SpotCheckDetailModal = ({ open, record, onCancel }) => { + const detailData = record || {}; + + const handleFileDownload = (fileUrl, fileName) => { + if (!fileUrl) { + message.warning("文件地址不存在"); + return; + } + const hide = message.loading("正在下载...", 0); + downloadFileByUrl(fileUrl, fileName) + .then(() => message.success("下载已开始")) + .catch(() => message.error("下载失败,请稍后重试")) + .finally(() => hide()); + }; + + return ( + + + + } + > + + + + + + handleFileDownload( + detailData.fileUrl, + detailData.fileName || + detailData.reportName || + "正式安全评价报告.pdf", + ) + } + > + {detailData.fileName || + detailData.reportName || + "正式安全评价报告.pdf"} + , + getFileExtLabel(detailData.fileName), + "V1.0", + ], + ]} + /> + + + + ); +}; + +export default SpotCheckDetailModal; diff --git a/src/pages/Container/Supervision/EvalReportDatabase/index.js b/src/pages/Container/Supervision/EvalReportDatabase/index.js index c111cc1..c8eee5c 100644 --- a/src/pages/Container/Supervision/EvalReportDatabase/index.js +++ b/src/pages/Container/Supervision/EvalReportDatabase/index.js @@ -24,6 +24,7 @@ import { NS_REGULATOR_EVAL_REPORT, NS_ORG_INFO } from "~/enumerate/namespace"; import { Connect } from "@cqsjjb/jjb-dva-runtime"; import { tools } from "@cqsjjb/jjb-common-lib"; import { renderDocxBlob, fillDocxTemplate } from "~/utils/fillDocxTemplate"; +import SpotCheckDetailModal from "./components/SpotCheckDetailModal"; import dayjs from "dayjs"; import "./index.less"; @@ -266,6 +267,8 @@ const EvalReportDatabase = (props) => { const [orgOptions, setOrgOptions] = useState([]); const [spotCheckForm] = Form.useForm(); const [viewChecklistLoading, setViewChecklistLoading] = useState(false); + const [spotDetailVisible, setSpotDetailVisible] = useState(false); + const [spotDetailData, setSpotDetailData] = useState(null); const { regulatorEvalReportPageLoading, @@ -506,6 +509,12 @@ const EvalReportDatabase = (props) => { } }; + /** 抽检报告详情:直接用行数据展示,不调接口 */ + const handleViewSpotDetail = (record) => { + setSpotDetailData(record); + setSpotDetailVisible(true); + }; + const handleDownloadOne = async (record) => { let fileUrl = record.fileUrl; let fileName = record.fileName || record.reportName || "报告文件"; @@ -1573,7 +1582,7 @@ const EvalReportDatabase = (props) => { @@ -1587,6 +1596,11 @@ const EvalReportDatabase = (props) => { )} + setSpotDetailVisible(false)} + /> );