/** * 体检操作记录工具函数 * 使用格式:yh_exam_actions_${today}_${examId} * 存储内容:{ idCardSignIn: boolean, consentSign: boolean, printSign: boolean, timestamp: string } */ /** * 获取今天的日期字符串(YYYY-MM-DD) */ export const getTodayString = (): string => { const today = new Date(); const year = today.getFullYear(); const month = String(today.getMonth() + 1).padStart(2, '0'); const day = String(today.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; }; /** * 获取操作记录的存储 key */ export const getExamActionKey = (examId: string | number): string => { const today = getTodayString(); return `yh_exam_actions_${today}_${examId}`; }; /** * 操作记录类型 */ export interface ExamActionRecord { /** 身份证拍照与签到 */ idCardSignIn?: boolean; /** 体检知情同意书的签字 */ consentSign?: boolean; /** 打印导检单是否签名 */ printSign?: boolean; /** 记录时间戳 */ timestamp?: string; } /** * 获取操作记录 */ export const getExamActionRecord = (examId: string | number): ExamActionRecord | null => { if (typeof window === 'undefined') return null; const key = getExamActionKey(examId); const raw = localStorage.getItem(key); if (!raw) return null; try { const parsed = JSON.parse(raw); return parsed as ExamActionRecord; } catch (err) { console.warn('操作记录解析失败', err); return null; } }; /** * 设置操作记录 */ export const setExamActionRecord = ( examId: string | number, action: keyof ExamActionRecord, value: boolean = true ): void => { if (typeof window === 'undefined') return; const key = getExamActionKey(examId); const existing = getExamActionRecord(examId) || {}; const updated: ExamActionRecord = { ...existing, [action]: value, timestamp: new Date().toISOString(), }; localStorage.setItem(key, JSON.stringify(updated)); }; /** * 检查操作是否已完成 */ export const isExamActionDone = (examId: string | number, action: keyof ExamActionRecord): boolean => { const record = getExamActionRecord(examId); return record?.[action] === true; };