(null);
const [showApiKey, setShowApiKey] = useState(false);
+ const [initialValues, setInitialValues] = useState<{ token: string }>({ token: '' });
+ const formValues = Form.useWatch([], form);
const handleClose = () => {
setVisible(false);
@@ -44,16 +46,29 @@ const MarketConfigModal = forwardRef
{
+ console.log('Modal 接收到的数据:', source);
setCurrentSource(source);
- form.setFieldsValue({
- token: source.token || '',
- });
+ setInitialValues({ token: source.token || '' });
setVisible(true);
};
+ const handleAfterOpenChange = (open: boolean) => {
+ if (open && currentSource) {
+ // Modal 完全打开后再设置表单值,使用 setTimeout 确保在下一个事件循环
+ setTimeout(() => {
+ form.setFieldsValue({
+ token: currentSource.token || '',
+ });
+ console.log('Modal 打开后设置表单值:', { token: currentSource.token || '' });
+ console.log('当前表单所有值:', form.getFieldsValue());
+ }, 100);
+ }
+ };
+
const handleSave = () => {
form
.validateFields()
@@ -101,6 +116,9 @@ const MarketConfigModal = forwardRef 0;
+
useImperativeHandle(ref, () => ({
handleOpen,
handleClose
@@ -113,9 +131,11 @@ const MarketConfigModal = forwardRef
@@ -147,8 +167,10 @@ const MarketConfigModal = forwardRef