From c78ef20b1031f2d2207b1f5772f309e578b12e79 Mon Sep 17 00:00:00 2001 From: mairuiming Date: Thu, 8 Jan 2026 17:32:33 +0800 Subject: [PATCH] 2 2 --- src/App.tsx | 74 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9b5b1b4..eac93a6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -586,19 +586,16 @@ export default function App() { // 新增:在读取新单据前重置关键状态,避免跨单据串值(缓冲期/实际完成日期/起始日期等) // 保留当前模式不变 resetGlobalState({ resetMode: false }); - setTimelineLoading(true); + setTimelineLoading(true); try { const deliveryTable = await bitable.base.getTable(DELIVERY_RECORD_TABLE_ID); - const nodeDetailsField: any = await deliveryTable.getField(DELIVERY_NODE_DETAILS_FIELD_ID); - const recordIdsField: any = await deliveryTable.getField(DELIVERY_RECORD_IDS_FIELD_ID); - const snapshotField: any = await deliveryTable.getField(DELIVERY_SNAPSHOT_JSON_FIELD_ID); - const startTimeField: any = await deliveryTable.getField(DELIVERY_START_TIME_FIELD_ID); - const expectedDeliveryDateField: any = await deliveryTable.getField(DELIVERY_EXPECTED_DATE_FIELD_ID); + const deliveryRecord: any = await deliveryTable.getRecordById(deliveryRecordId); + const deliveryFields: any = deliveryRecord?.fields || {}; - const nodeDetailsVal = await nodeDetailsField.getValue(deliveryRecordId); + const nodeDetailsVal = deliveryFields?.[DELIVERY_NODE_DETAILS_FIELD_ID]; let expectedDeliveryTsFromField: number | null = null; try { - const expectedDeliveryVal = await expectedDeliveryDateField.getValue(deliveryRecordId); + const expectedDeliveryVal = deliveryFields?.[DELIVERY_EXPECTED_DATE_FIELD_ID]; let ts: number | null = null; if (typeof expectedDeliveryVal === 'number') { ts = expectedDeliveryVal; @@ -615,7 +612,7 @@ export default function App() { } catch {} // 读取record_ids文本字段并保留原始文本(用于原样写回) try { - const recordIdsTextVal = await recordIdsField.getValue(deliveryRecordId); + const recordIdsTextVal = deliveryFields?.[DELIVERY_RECORD_IDS_FIELD_ID]; const raw = extractText(recordIdsTextVal); if (raw && raw.trim() !== '') { setRestoredRecordIdsText(raw.trim()); @@ -637,7 +634,7 @@ export default function App() { // 优先使用货期记录表中的快照字段进行一键还原(新方案) try { - const deliverySnapVal = await snapshotField.getValue(deliveryRecordId); + const deliverySnapVal = deliveryFields?.[DELIVERY_SNAPSHOT_JSON_FIELD_ID]; let deliverySnapStr: string | null = null; if (typeof deliverySnapVal === 'string') { deliverySnapStr = deliverySnapVal; @@ -736,7 +733,7 @@ export default function App() { } if (!startTimeRestored) { - const startTimeValue = await startTimeField.getValue(deliveryRecordId); + const startTimeValue = deliveryFields?.[DELIVERY_START_TIME_FIELD_ID]; if (startTimeValue) { let extractedStartTime: Date | null = null; if (typeof startTimeValue === 'number') { @@ -889,7 +886,7 @@ export default function App() { } } if (!startTimeRestored) { - const startTimeValue = await startTimeField.getValue(deliveryRecordId); + const startTimeValue = deliveryFields?.[DELIVERY_START_TIME_FIELD_ID]; if (startTimeValue) { let extractedStartTime: Date | null = null; if (typeof startTimeValue === 'number') { @@ -1036,7 +1033,7 @@ export default function App() { // 如果快照中没有起始时间信息,则从当前选中的货期记录中获取 if (!startTimeRestored) { - const startTimeValue = await startTimeField.getValue(deliveryRecordId); + const startTimeValue = deliveryFields?.[DELIVERY_START_TIME_FIELD_ID]; if (startTimeValue) { let extractedStartTime: Date | null = null; if (typeof startTimeValue === 'number') { @@ -1430,7 +1427,7 @@ export default function App() { }); // 如果没有快照恢复起始时间,则从当前货期记录中获取起始时间 - const startTimeValue = await startTimeField.getValue(deliveryRecordId); + const startTimeValue = deliveryFields?.[DELIVERY_START_TIME_FIELD_ID]; if (startTimeValue) { let extractedStartTime: Date | null = null; if (typeof startTimeValue === 'number') { @@ -1502,6 +1499,7 @@ export default function App() { const OMS_BOARD_TABLE_ID = 'tbl7j8bCpUbFmGuk'; // OMS看板表ID const OMS_PLAN_TEXT_FIELD_ID = 'fldH0jPZE0'; // OMS看板:货期计划(文本结构) const OMS_PLAN_VERSION_FIELD_ID = 'fldwlIUf4z'; // OMS看板:计划版本(公式数字) + const OMS_DELIVERY_RECORD_ID_FIELD_ID = 'fldjEIP9yC'; // OMS看板:货期记录表record_id // 已移除中国法定节假日相关常量和配置 @@ -2044,6 +2042,15 @@ export default function App() { initializeData(); }, []); + const getDeliveryRecordIdFromOmsRecord = async (omsRecordId: string): Promise => { + if (!omsRecordId) return null; + const omsTable = await bitable.base.getTable(OMS_BOARD_TABLE_ID); + const omsRecord = await omsTable.getRecordById(omsRecordId); + const raw = omsRecord?.fields?.[OMS_DELIVERY_RECORD_ID_FIELD_ID]; + const text = extractText(raw)?.trim(); + return text ? text : null; + }; + // 初始化起始时间:从货期记录表获取,新记录则使用当前时间 const initializeStartTime = async () => { try { @@ -2074,8 +2081,30 @@ export default function App() { } } } else if (recordId && tableId === OMS_BOARD_TABLE_ID) { - // 从OMS看板匹配对应的货期记录后,尝试获取其起始时间 + // 从OMS看板读取货期记录ID后,尝试获取其起始时间 try { + const deliveryRecordId = await getDeliveryRecordIdFromOmsRecord(recordId); + if (deliveryRecordId) { + const deliveryTable = await bitable.base.getTable(DELIVERY_RECORD_TABLE_ID); + const deliveryRecord: any = await deliveryTable.getRecordById(deliveryRecordId); + const startTimeValue = deliveryRecord?.fields?.[DELIVERY_START_TIME_FIELD_ID]; + if (startTimeValue) { + let extractedStartTime: Date | null = null; + if (typeof startTimeValue === 'number') { + extractedStartTime = new Date(startTimeValue); + } else if (Array.isArray(startTimeValue) && startTimeValue.length > 0) { + const timestamp = startTimeValue[0]; + if (typeof timestamp === 'number') extractedStartTime = new Date(timestamp); + } + if (extractedStartTime && !isNaN(extractedStartTime.getTime())) { + setStartTime(extractedStartTime); + return; + } + } + } + + /* + // 原始逻辑:从OMS看板用“货期计划 + 计划版本”匹配货期记录(已停用) const omsTable = await bitable.base.getTable(OMS_BOARD_TABLE_ID); const planTextField: any = await omsTable.getField(OMS_PLAN_TEXT_FIELD_ID); const planVersionField: any = await omsTable.getField(OMS_PLAN_VERSION_FIELD_ID); @@ -2118,6 +2147,7 @@ export default function App() { } } } + */ } catch (e) { console.warn('从OMS看板匹配起始时间失败,使用当前时间:', e); } @@ -5725,7 +5755,18 @@ export default function App() { setSelectedDeliveryRecordId(recordId); await loadProcessDataFromDeliveryRecord(recordId); } else if (tableId === OMS_BOARD_TABLE_ID) { - // 支持在OMS看板选中记录后读取:通过货期计划 + 计划版本匹配货期记录 + const matchedDeliveryRecordId = await getDeliveryRecordIdFromOmsRecord(recordId); + if (!matchedDeliveryRecordId) { + if (bitable.ui.showToast) { + await bitable.ui.showToast({ toastType: ToastType.warning, message: 'OMS看板记录缺少货期记录ID(fldjEIP9yC)' }); + } + return; + } + setSelectedDeliveryRecordId(matchedDeliveryRecordId); + await loadProcessDataFromDeliveryRecord(matchedDeliveryRecordId); + + /* + // 原始逻辑:从OMS看板用“货期计划 + 计划版本”匹配货期记录(已停用) const omsTable = await bitable.base.getTable(OMS_BOARD_TABLE_ID); const omsRecord = await omsTable.getRecordById(recordId); const planTextRaw = omsRecord?.fields?.[OMS_PLAN_TEXT_FIELD_ID]; @@ -5762,6 +5803,7 @@ export default function App() { } setSelectedDeliveryRecordId(matchedDeliveryRecordId); await loadProcessDataFromDeliveryRecord(matchedDeliveryRecordId); + */ } else { if (bitable.ui.showToast) { await bitable.ui.showToast({ toastType: ToastType.warning, message: '请在货期记录或OMS看板表中选择记录' });