diff --git a/src/App.tsx b/src/App.tsx index d912aa0..37f1acf 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { bitable, FieldType } from '@lark-base-open/js-sdk'; -import { Button, Typography, List, Card, Space, Divider, Spin, Table, Select, Modal, DatePicker, InputNumber } from '@douyinfe/semi-ui'; +import { Button, Typography, List, Card, Space, Divider, Spin, Table, Select, Modal, DatePicker, InputNumber, Input } from '@douyinfe/semi-ui'; import { useState, useEffect, useRef } from 'react'; import { addDays, format } from 'date-fns'; import { zhCN } from 'date-fns/locale'; @@ -71,6 +71,8 @@ export default function App() { const [currentForeignId, setCurrentForeignId] = useState(null); const [currentStyleText, setCurrentStyleText] = useState(''); const [currentColorText, setCurrentColorText] = useState(''); + // 标题中的款号/颜色编辑开关:默认锁定,点击笔按钮开放编辑 + const [styleColorEditable, setStyleColorEditable] = useState(false); const [currentText2, setCurrentText2] = useState(''); const [currentVersionNumber, setCurrentVersionNumber] = useState(null); // 功能入口模式与调整相关状态 @@ -138,6 +140,49 @@ export default function App() { // 指定的数据表ID和视图ID const TABLE_ID = 'tblPIJ7unndydSMu'; + + // 当弹窗打开时,默认从记录/选择数据预填款号与颜色(不覆盖已有值) + const ensureStyleColorDefaults = async () => { + try { + const needStyle = !currentStyleText || currentStyleText.trim() === ''; + const needColor = !currentColorText || currentColorText.trim() === ''; + if (!needStyle && !needColor) return; + + // 优先使用已读取的记录详情 + const currentRecordDetails = recordDetails; + if (currentRecordDetails && currentRecordDetails.length > 0) { + const first = currentRecordDetails[0]; + const styleVal = needStyle ? extractText(first?.fields?.['fld6Uw95kt']) || '' : currentStyleText; + const colorVal = needColor ? extractText(first?.fields?.['flde85ni4O']) || '' : currentColorText; + if (needStyle && styleVal) setCurrentStyleText(styleVal); + if (needColor && colorVal) setCurrentColorText(colorVal); + return; + } + + // 其次使用当前选择记录,做一次读取 + if (selectedRecords && selectedRecords.length > 0) { + try { + const table = await bitable.base.getTable(TABLE_ID); + const firstRecord = await table.getRecordById(selectedRecords[0]); + const styleVal2 = needStyle ? extractText(firstRecord?.fields?.['fld6Uw95kt']) || '' : currentStyleText; + const colorVal2 = needColor ? extractText(firstRecord?.fields?.['flde85ni4O']) || '' : currentColorText; + if (needStyle && styleVal2) setCurrentStyleText(styleVal2); + if (needColor && colorVal2) setCurrentColorText(colorVal2); + } catch (e) { + console.warn('读取所选记录的款号/颜色失败,保持现有值', e); + } + } + } catch (e) { + console.warn('预填款号/颜色失败', e); + } + }; + + useEffect(() => { + if (timelineVisible) { + // 打开弹窗时进行一次预填,避免手动输入 + ensureStyleColorDefaults(); + } + }, [timelineVisible]); const VIEW_ID = 'vewb28sjuX'; // 标签表ID @@ -4372,7 +4417,39 @@ export default function App() { {/* 时效计算结果模态框 */} + 预计开始和完成时间 +
+ 款号 + setCurrentStyleText(val)} + /> + 颜色 + setCurrentColorText(val)} + /> + +
+ + } visible={timelineVisible} onCancel={() => { setTimelineVisible(false); @@ -4381,6 +4458,7 @@ export default function App() { setCompletionDateAdjustment(0); // 关闭时重置最后流程完成日期调整 setHasAppliedSuggestedBuffer(false); // 关闭时允许下次重新应用建议缓冲期 setLastSuggestedApplied(null); // 关闭时清空上次建议值 + setStyleColorEditable(false); // 关闭弹窗后恢复为锁定状态 }} footer={