优化打印
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -96,6 +96,8 @@ export interface TongyishuPdfInfo {
|
||||
pdf_url: string;
|
||||
/** 组合代码 */
|
||||
combination_code?: number | null;
|
||||
/** 是否已签名 */
|
||||
is_signed?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user