From e1185385577eab8c2d0b65419364327e71dcaeac Mon Sep 17 00:00:00 2001 From: xianyi Date: Wed, 24 Dec 2025 15:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E4=BF=9D=E5=AD=98=E7=9F=A5?= =?UTF-8?q?=E6=83=85=E5=90=8C=E6=84=8F=E4=B9=A6PDF=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 6 +-- src/components/exam/ExamSignPanel.tsx | 73 +++++++++++++++++++++++++-- src/utils/examActions.ts | 52 +++++++++++++++++++ 3 files changed, 124 insertions(+), 7 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 4cf3c8d..89e42b5 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -335,10 +335,8 @@ export interface InputTongyishuSignSubmit { * 提交体检知情同意书签名出参 */ export interface OutputTongyishuSignInfo { - /** 体检知情同意书文件组合代码 */ - combination_code?: string | null; - /** 体检知情同意书PDF地址 */ - pdf_url?: string | null; + /** 知情同意书PDF文件列表 */ + list_pdf_url?: OutputTongyishuFileInfo[] | null; /** 消息内容 */ message?: string | null; } diff --git a/src/components/exam/ExamSignPanel.tsx b/src/components/exam/ExamSignPanel.tsx index 1ec4f89..b781ebc 100644 --- a/src/components/exam/ExamSignPanel.tsx +++ b/src/components/exam/ExamSignPanel.tsx @@ -2,7 +2,12 @@ import { useEffect, useRef, useState } from 'react'; import type { OutputTongyishuFileInfo } from '../../api'; import { getTongyishuPdf, signInMedicalExamCenter, submitTongyishuSign } from '../../api'; -import { setExamActionRecord } from '../../utils/examActions'; +import { + setExamActionRecord, + setTongyishuPdfList, + getTongyishuPdfList, + type TongyishuPdfInfo, +} from '../../utils/examActions'; import type { SignaturePadHandle } from '../ui'; import { Button, SignaturePad } from '../ui'; @@ -170,6 +175,15 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => { if (examId) { setExamActionRecord(examId, 'consentSign', true); } + // 存储返回的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, + })); + setTongyishuPdfList(examId, pdfList); + } setSignedCombinationCodes((prev) => { const code = Number(previewPdf.combination_code); if (!Number.isFinite(code)) return prev || []; @@ -207,7 +221,33 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => { getTongyishuPdf({ exam_id: examId }) .then((res) => { const list = res.Data?.list_pdf_url || []; - setConsentList(list); + + // 先拉取接口返回的全部 list_pdf_url,再用本地已保存的已签名 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; + const code = Number(item.combination_code); + if (!Number.isFinite(code)) return item; + + const matched = storedList.find( + (pdf) => pdf.combination_code !== null && Number(pdf.combination_code) === code, + ); + + if (matched && matched.pdf_url) { + return { + ...item, + pdf_url: matched.pdf_url, + pdf_name: matched.pdf_name || item.pdf_name, + }; + } + + return item; + }); + } + + setConsentList(mergedList); if (!list.length) { setConsentMessage(res.Data?.message || '暂无知情同意书'); } @@ -286,7 +326,34 @@ export const ExamSignPanel = ({ examId, onBusyChange }: ExamSignPanelProps) => { /> )} - diff --git a/src/utils/examActions.ts b/src/utils/examActions.ts index d0ae63a..d12936e 100644 --- a/src/utils/examActions.ts +++ b/src/utils/examActions.ts @@ -86,3 +86,55 @@ export const isExamActionDone = (examId: string | number, action: keyof ExamActi return record?.[action] === true; }; +/** + * 知情同意书PDF信息 + */ +export interface TongyishuPdfInfo { + /** PDF文件名称 */ + pdf_name: string; + /** PDF文件地址 */ + pdf_url: string; + /** 组合代码 */ + combination_code?: number | null; +} + +/** + * 获取知情同意书PDF列表的存储 key + */ +export const getTongyishuPdfListKey = (examId: string | number): string => { + const today = getTodayString(); + return `yh_tongyishu_pdf_list_${today}_${examId}`; +}; + +/** + * 存储知情同意书PDF列表 + */ +export const setTongyishuPdfList = ( + examId: string | number, + pdfList: TongyishuPdfInfo[] +): void => { + if (typeof window === 'undefined') return; + + const key = getTongyishuPdfListKey(examId); + localStorage.setItem(key, JSON.stringify(pdfList)); +}; + +/** + * 获取知情同意书PDF列表 + */ +export const getTongyishuPdfList = (examId: string | number): TongyishuPdfInfo[] | null => { + if (typeof window === 'undefined') return null; + + const key = getTongyishuPdfListKey(examId); + const raw = localStorage.getItem(key); + if (!raw) return null; + + try { + const parsed = JSON.parse(raw); + return Array.isArray(parsed) ? parsed as TongyishuPdfInfo[] : null; + } catch (err) { + console.warn('知情同意书PDF列表解析失败', err); + return null; + } +}; +