[修复] 时间字段联动:默认中文日期格式、固定时间自动填充、12/24h动态切换

This commit is contained in:
2026-04-17 22:47:18 +08:00
parent ac6b619549
commit 8ea0a9a69e
2 changed files with 47 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ export default function ReportEditor() {
patientAge: '',
department: '',
bedNumber: '',
surgeryDate: new Date().toISOString().split('T')[0],
surgeryDate: '',
startHour: '',
startMinute: '',
endHour: '',
@@ -774,7 +774,7 @@ export default function ReportEditor() {
if (tpl) {
editorRef.current.innerHTML = tpl.content;
contentRef.current = tpl.content;
const nextReportData = {
const nextReportData: any = {
title: tpl.name || '腹腔镜胆囊切除术报告',
patientName: '',
hospitalId: '',
@@ -782,7 +782,7 @@ export default function ReportEditor() {
patientAge: '',
department: '',
bedNumber: '',
surgeryDate: new Date().toISOString().split('T')[0],
surgeryDate: '',
startHour: '',
startMinute: '',
endHour: '',
@@ -793,6 +793,46 @@ export default function ReportEditor() {
anesthesiaType: '',
status: 'draft'
};
formFields.forEach(field => {
if (field.category === '时间') {
if (field.timeDefault === 'specific' && field.fixedTimeValue) {
if (field.type === 'date') {
nextReportData[field.key] = field.fixedTimeValue;
} else if (field.type === 'time') {
const [hh, mm] = field.fixedTimeValue.split(':');
if (field.key === 'startTime') {
nextReportData.startHour = hh || '';
nextReportData.startMinute = mm || '';
} else if (field.key === 'endTime') {
nextReportData.endHour = hh || '';
nextReportData.endMinute = mm || '';
} else {
nextReportData[field.key] = field.fixedTimeValue;
}
}
} else if (field.timeDefault === 'current') {
if (field.type === 'date') {
nextReportData[field.key] = new Date().toISOString().split('T')[0];
} else if (field.type === 'time') {
const now = new Date();
const hh = String(now.getHours()).padStart(2, '0');
const mm = String(now.getMinutes()).padStart(2, '0');
if (field.key === 'startTime') {
nextReportData.startHour = hh;
nextReportData.startMinute = mm;
} else if (field.key === 'endTime') {
nextReportData.endHour = hh;
nextReportData.endMinute = mm;
} else {
nextReportData[field.key] = `${hh}:${mm}`;
}
}
}
}
});
if (!nextReportData.surgeryDate) {
nextReportData.surgeryDate = new Date().toISOString().split('T')[0];
}
setLoadedTemplateId(tpl.id);
setReportData(nextReportData);
setVideos([]);
@@ -1559,7 +1599,7 @@ export default function ReportEditor() {
}
if (field.type === 'time') {
const is12h = field.timeFormat === '12h';
const is12h = field.timeFormat ? (field.timeFormat.includes('hh') || field.timeFormat.includes('A')) : false;
if (field.key === 'startTime' || field.key === 'endTime') {
const hourKey = field.key === 'startTime' ? 'startHour' : 'endHour';

View File

@@ -34,7 +34,7 @@ export default function TemplateManage() {
const [editFieldTimeFormat, setEditFieldTimeFormat] = useState('');
const [editFieldTimeDefault, setEditFieldTimeDefault] = useState<'current' | 'specific'>('specific');
const [editFieldFixedTimeValue, setEditFieldFixedTimeValue] = useState('');
const [newFieldTimeFormat, setNewFieldTimeFormat] = useState('YYYY-MM-DD');
const [newFieldTimeFormat, setNewFieldTimeFormat] = useState('YYYYMMDD');
const [newFieldTimeDefault, setNewFieldTimeDefault] = useState<'current' | 'specific'>('specific');
const [newFieldFixedTimeValue, setNewFieldFixedTimeValue] = useState('');
const [customTimeFormats, setCustomTimeFormats] = useState<string[]>([]);
@@ -469,7 +469,7 @@ export default function TemplateManage() {
storage.set('formFieldsConfig', updated);
setNewFieldForm({ label: '', category: '填空', type: 'text' });
setNewFieldOptions('');
setNewFieldTimeFormat('YYYY-MM-DD');
setNewFieldTimeFormat('YYYYMMDD');
setNewFieldTimeDefault('specific');
setNewFieldFixedTimeValue('');
};
@@ -1059,7 +1059,7 @@ export default function TemplateManage() {
const t = e.target.value as FieldType;
setNewFieldForm({ ...newFieldForm, type: t });
if (newFieldForm.category === '时间') {
setNewFieldTimeFormat(t === 'date' ? 'YYYY-MM-DD' : '24h');
setNewFieldTimeFormat(t === 'date' ? 'YYYYMMDD' : 'HH:mm');
}
}}
className="flex-1 px-2 py-1.5 text-xs border border-border rounded focus:outline-hidden focus:border-accent bg-white"