From a258d31a61815e597d35779e24f6b448e01fa62a Mon Sep 17 00:00:00 2001 From: xianyi Date: Tue, 6 Jan 2026 10:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/exam/ExamSignPanel.tsx | 29 ++++++++++++++++++++++----- src/utils/examActions.ts | 2 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/components/exam/ExamSignPanel.tsx b/src/components/exam/ExamSignPanel.tsx index b3b899f..6185d84 100644 --- a/src/components/exam/ExamSignPanel.tsx +++ b/src/components/exam/ExamSignPanel.tsx @@ -231,12 +231,13 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => { if (examId) { setExamActionRecord(examId, 'consentSign', true); } - // 存储返回的PDF列表 + // 存储返回的PDF列表(标记为已签名) if (res.Data?.list_pdf_url && Array.isArray(res.Data.list_pdf_url) && examId) { const pdfList: TongyishuPdfInfo[] = res.Data.list_pdf_url.map((item) => ({ pdf_name: item.pdf_name || '', pdf_url: item.pdf_url || '', combination_code: item.combination_code ?? null, + is_signed: true, })); setTongyishuPdfList(examId, pdfList); } @@ -274,13 +275,30 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => { } setConsentLoading(true); setConsentMessage(null); + + // 先检查 localStorage 中是否有已签名的知情同意书 + const storedList = getTongyishuPdfList(examId); + const allSigned = storedList && storedList.length > 0 && storedList.every((pdf) => pdf.is_signed === true); + + // 如果所有知情同意书都已签名,直接使用 localStorage 中的数据,不请求接口 + if (allSigned && storedList) { + const mergedList = storedList.map((pdf) => ({ + pdf_name: pdf.pdf_name, + pdf_url: pdf.pdf_url, + combination_code: pdf.combination_code ?? null, + })); + setConsentList(mergedList); + setConsentLoading(false); + return; + } + + // 如果有未签名的,请求接口获取最新列表 getTongyishuPdf({ exam_id: examId }) .then((res) => { const list = res.Data?.list_pdf_url || []; - // 先拉取接口返回的全部 list_pdf_url,再用本地已保存的已签名 PDF 覆盖 + // 合并接口返回的数据和本地已保存的已签名 PDF let mergedList = list; - const storedList = getTongyishuPdfList(examId); if (storedList && storedList.length > 0) { mergedList = list.map((item) => { if (item.combination_code === undefined || item.combination_code === null) return item; @@ -288,10 +306,11 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => { if (!Number.isFinite(code)) return item; const matched = storedList.find( - (pdf) => pdf.combination_code !== null && Number(pdf.combination_code) === code, + (pdf) => pdf.combination_code !== null && Number(pdf.combination_code) === code && pdf.is_signed === true, ); - if (matched && matched.pdf_url) { + // 如果本地有已签名的版本,优先使用 + if (matched && matched.pdf_url && matched.is_signed === true) { return { ...item, pdf_url: matched.pdf_url, diff --git a/src/utils/examActions.ts b/src/utils/examActions.ts index f11eef5..ec710bd 100644 --- a/src/utils/examActions.ts +++ b/src/utils/examActions.ts @@ -96,6 +96,8 @@ export interface TongyishuPdfInfo { pdf_url: string; /** 组合代码 */ combination_code?: number | null; + /** 是否已签名 */ + is_signed?: boolean; } /**