临时保存知情同意书PDF列表

This commit is contained in:
xianyi
2025-12-24 15:04:54 +08:00
parent e5ea1ab45e
commit e118538557
3 changed files with 124 additions and 7 deletions

View File

@@ -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;
}

View File

@@ -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) => {
/>
)}
</div>
<Button className='py-1.5 px-3' onClick={() => !busy && setPreviewPdf(item)} disabled={busy}>
<Button
className='py-1.5 px-3'
onClick={() => {
if (busy) return;
let target = item;
// 如果本地已保存签名后的PDF列表则优先使用签名后的PDF地址
if (examId) {
const storedList = getTongyishuPdfList(examId);
if (storedList && item.combination_code !== undefined && item.combination_code !== null) {
const code = Number(item.combination_code);
const matched = storedList.find(
(pdf) => pdf.combination_code !== null && Number(pdf.combination_code) === code,
);
if (matched && matched.pdf_url) {
target = {
...item,
pdf_url: matched.pdf_url,
};
}
}
}
setPreviewPdf(target);
}}
disabled={busy}
>
</Button>
</div>

View File

@@ -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;
}
};