2
This commit is contained in:
2025-11-19 11:29:55 +08:00
parent 20eb20a518
commit de6a3a8a04

View File

@ -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<string | null>(null);
const [currentStyleText, setCurrentStyleText] = useState<string>('');
const [currentColorText, setCurrentColorText] = useState<string>('');
// 标题中的款号/颜色编辑开关:默认锁定,点击笔按钮开放编辑
const [styleColorEditable, setStyleColorEditable] = useState<boolean>(false);
const [currentText2, setCurrentText2] = useState<string>('');
const [currentVersionNumber, setCurrentVersionNumber] = useState<number | null>(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() {
{/* 时效计算结果模态框 */}
<Modal
title="预计开始和完成时间"
title={
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, flexWrap: 'wrap' }}>
<span style={{ fontSize: 16, fontWeight: 600 }}></span>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, whiteSpace: 'nowrap', overflowX: 'auto', maxWidth: '70%' }}>
<Text type="tertiary"></Text>
<Input
size="small"
style={{ width: 160 }}
placeholder="请输入款号"
value={currentStyleText}
disabled={!styleColorEditable}
onChange={(val) => setCurrentStyleText(val)}
/>
<Text type="tertiary" style={{ marginLeft: 8 }}></Text>
<Input
size="small"
style={{ width: 160 }}
placeholder="请输入颜色"
value={currentColorText}
disabled={!styleColorEditable}
onChange={(val) => setCurrentColorText(val)}
/>
<Button
size="small"
type="tertiary"
onClick={() => setStyleColorEditable(prev => !prev)}
style={{ marginLeft: 8 }}
>
<span style={{ fontSize: 14, lineHeight: 1 }}></span>
</Button>
</div>
</div>
}
visible={timelineVisible}
onCancel={() => {
setTimelineVisible(false);
@ -4381,6 +4458,7 @@ export default function App() {
setCompletionDateAdjustment(0); // 关闭时重置最后流程完成日期调整
setHasAppliedSuggestedBuffer(false); // 关闭时允许下次重新应用建议缓冲期
setLastSuggestedApplied(null); // 关闭时清空上次建议值
setStyleColorEditable(false); // 关闭弹窗后恢复为锁定状态
}}
footer={
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>