diff --git a/src/App.tsx b/src/App.tsx index 3d431a8..77d3c0e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -79,6 +79,10 @@ export default function App() { const [adjustLoading, setAdjustLoading] = useState(false); // 删除未使用的 deliveryRecords 状态 const [selectedDeliveryRecordId, setSelectedDeliveryRecordId] = useState(''); + // 从货期记录读取到的record_ids(用于保存回写) + const [restoredRecordIds, setRestoredRecordIds] = useState([]); + // 原始文本格式的record_ids(不做JSON化写回) + const [restoredRecordIdsText, setRestoredRecordIdsText] = useState(''); // 批量处理相关状态 const [batchProcessing, setBatchProcessing] = useState(false); @@ -125,6 +129,8 @@ export default function App() { setTimelineResults([]); setTimelineAdjustments({}); setIsRestoringSnapshot(false); + setRestoredRecordIds([]); + setRestoredRecordIdsText(''); // 当前记录与批量信息 setCurrentBatchRecord(null); @@ -192,6 +198,27 @@ export default function App() { const deliveryTable = await bitable.base.getTable(DELIVERY_RECORD_TABLE_ID); const deliveryRecord = await deliveryTable.getRecordById(deliveryRecordId); const nodeDetailsVal = deliveryRecord?.fields?.[DELIVERY_NODE_DETAILS_FIELD_ID]; + // 读取record_ids文本字段并保留原始文本(用于原样写回) + try { + const recordIdsTextVal = deliveryRecord?.fields?.[DELIVERY_RECORD_IDS_FIELD_ID]; + const raw = extractText(recordIdsTextVal); + if (raw && raw.trim() !== '') { + setRestoredRecordIdsText(raw.trim()); + // 若需要解析为数组供内部使用,可保留解析逻辑(不影响写回原始文本) + try { + const json = JSON.parse(raw); + if (Array.isArray(json)) { + const parsedFromText = json.filter((id: any) => typeof id === 'string' && id.trim() !== ''); + if (parsedFromText.length > 0) setRestoredRecordIds(parsedFromText); + } + } catch { + const parsedFromText = raw.split(/[\,\s]+/).map(s => s.trim()).filter(Boolean); + if (parsedFromText.length > 0) setRestoredRecordIds(parsedFromText); + } + } + } catch (e) { + console.warn('解析record_ids文本字段失败,忽略:', e); + } // 优先使用货期记录表中的快照字段进行一键还原(新方案) try { @@ -311,6 +338,8 @@ export default function App() { recordIds = nodeDetailsVal.map((item: any) => item?.recordId || item?.id || item).filter(Boolean); } + // 注意:不将节点详情的recordIds写入restoredRecordIds,避免读取为空时写入非空 + if (!recordIds || recordIds.length === 0) { if (bitable.ui.showToast) { await bitable.ui.showToast({ toastType: 'warning', message: '该货期记录未包含节点详情或为空' }); @@ -833,6 +862,8 @@ export default function App() { const DELIVERY_START_TIME_FIELD_ID = 'fld727qCAv'; // 文本2字段(货期记录表新增) const DELIVERY_TEXT2_FIELD_ID = 'fldG6LZnmU'; + // 记录ID文本字段(货期记录表新增) + const DELIVERY_RECORD_IDS_FIELD_ID = 'fldq3u7h7H'; // 已移除中国法定节假日相关常量和配置 @@ -2670,6 +2701,7 @@ export default function App() { const versionField = await deliveryRecordTable.getField(DELIVERY_VERSION_FIELD_ID); const startTimeField = await deliveryRecordTable.getField(DELIVERY_START_TIME_FIELD_ID); const snapshotField = await deliveryRecordTable.getField(DELIVERY_SNAPSHOT_JSON_FIELD_ID); + const recordIdsTextField = await deliveryRecordTable.getField(DELIVERY_RECORD_IDS_FIELD_ID); console.log('成功获取所有字段对象'); // 检查标签汇总字段的类型 @@ -3054,9 +3086,14 @@ export default function App() { const adjustmentInfoCell = adjustmentInfo ? await adjustmentInfoField.createCell(adjustmentInfo) : null; // 创建版本号Cell(数字) const versionCell = await versionField.createCell(versionNumber); + // 写回保持“原始文本格式”;如果读取为空,则写入空字符串 + const recordIdsText = (restoredRecordIdsText && restoredRecordIdsText.trim() !== '') + ? restoredRecordIdsText.trim() + : ''; + const recordIdsCell = await recordIdsTextField.createCell(recordIdsText); // 组合所有Cell到一个记录中 - const recordCells = [foreignIdCell, styleCell, colorCell, text2Cell, createTimeCell, startTimeCell, versionCell, snapshotCell]; + const recordCells = [foreignIdCell, styleCell, colorCell, text2Cell, createTimeCell, startTimeCell, versionCell, snapshotCell, recordIdsCell]; // 只有当数据存在时才添加对应的Cell if (labelsCell) recordCells.push(labelsCell);