From 27790399f3525f2e7d46742496df9e3bedb3d59c Mon Sep 17 00:00:00 2001 From: mairuiming Date: Thu, 26 Mar 2026 11:54:19 +0800 Subject: [PATCH] 1 1 --- src/App.tsx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d533676..bffe37c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -540,6 +540,25 @@ export default function App() { } }; + const normalizeSelectedLabelsForRestore = (raw: any): { [key: string]: string | string[] } => { + if (!raw || typeof raw !== 'object') return {}; + const out: { [key: string]: string | string[] } = { ...raw }; + const normalizeToArray = (val: any): string[] => { + if (Array.isArray(val)) return val.map(v => String(v ?? '').trim()).filter(Boolean); + if (typeof val === 'string') { + return val.split(/[,,、]+/).map(v => v.trim()).filter(Boolean); + } + return []; + }; + for (const key of ['标签7', '标签8', '标签10', '标签12']) { + if (key in out) { + const arr = normalizeToArray(out[key]); + out[key] = arr; + } + } + return out; + }; + const normalizeExcludedDatesOverride = (raw: any): string[] => { const parts: string[] = []; if (Array.isArray(raw)) { @@ -1030,7 +1049,7 @@ export default function App() { restoreExcludedDatesByNodeOverrideFromSnapshot(snapshot, snapshot?.timelineResults); // 恢复页面与全局状态 - if (snapshot.selectedLabels) setSelectedLabels(snapshot.selectedLabels); + if (snapshot.selectedLabels) setSelectedLabels(normalizeSelectedLabelsForRestore(snapshot.selectedLabels)); if (!mode && snapshot.mode) setMode(snapshot.mode); if (snapshot.foreignId) setCurrentForeignId(snapshot.foreignId); if (snapshot.styleText) setCurrentStyleText(snapshot.styleText); @@ -1178,7 +1197,7 @@ export default function App() { restoreExcludedDatesOverrideFromSnapshot(snapshot, snapshot?.timelineResults); restoreExcludedDatesByNodeOverrideFromSnapshot(snapshot, snapshot?.timelineResults); - if (snapshot.selectedLabels) setSelectedLabels(snapshot.selectedLabels); + if (snapshot.selectedLabels) setSelectedLabels(normalizeSelectedLabelsForRestore(snapshot.selectedLabels)); if (!mode && snapshot.mode) setMode(snapshot.mode); if (snapshot.foreignId) setCurrentForeignId(snapshot.foreignId); if (snapshot.styleText) setCurrentStyleText(snapshot.styleText); @@ -1317,7 +1336,7 @@ export default function App() { restoreTimelineDirectionFromSnapshot(snapshot); restoreBaseBufferDaysFromSnapshot(snapshot); // 恢复页面状态 - if (snapshot.selectedLabels) setSelectedLabels(snapshot.selectedLabels); + if (snapshot.selectedLabels) setSelectedLabels(normalizeSelectedLabelsForRestore(snapshot.selectedLabels)); // 保留当前模式,不覆写为快照的模式(避免调整模式被还原为生成模式) if (!mode && snapshot.mode) setMode(snapshot.mode); // 快照回填的foreign_id/款式/颜色/版本 @@ -4483,7 +4502,7 @@ export default function App() { } setStartTime(s.startTime || null); setExpectedDate(s.expectedDate || null); - setSelectedLabels(s.selectedLabels || {}); + setSelectedLabels(normalizeSelectedLabelsForRestore(s.selectedLabels)); const normalizedAdjustments = normalizeTimelineAdjustmentsFromSnapshot(s.timelineAdjustments || {}, s.timelineResults || []); setTimelineAdjustments(normalizedAdjustments); setBaseBufferDays(s.baseBufferDays ?? 0); @@ -5557,7 +5576,7 @@ export default function App() { const raw = f[fieldId]; const list = normalizeToStringList(raw); if (list.length > 0) { - if (i2 === 7 || i2 === 8 || i2 === 10) labels[key] = list; + if (i2 === 7 || i2 === 8 || i2 === 10 || i2 === 12) labels[key] = list; else labels[key] = list.join(','); } }