diff --git a/src/pages/ProjectFiles/file.tsx b/src/pages/ProjectFiles/file.tsx index bf4329d..f2cafec 100644 --- a/src/pages/ProjectFiles/file.tsx +++ b/src/pages/ProjectFiles/file.tsx @@ -1,10 +1,11 @@ import { CloseCircleOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { Button, Card, Col, Form, Popover, Row, message, Divider, Select, Input, Upload } from 'antd'; +import type { FormInstance } from 'antd'; import { history, useLocation } from 'umi'; import type { Location } from 'umi'; import type { FC } from 'react'; -import React, { useState, Fragment } from 'react'; +import React, { useState, Fragment, useRef } from 'react'; import ProForm, { ProFormSelect, ProFormText, @@ -112,7 +113,7 @@ const ProjectFileCreate: FC> = () => { const readOnly = query?.action === 'view'; const id = query?.id; // 文件 id - const [regionDictType, setRegionDictType] = useState('1'); + const formRef = useRef(); const [error, setError] = useState([]); const getErrorInfo = (errors: ErrorField[]) => { const errorCount = errors.filter((item) => item.errors.length > 0).length; @@ -179,6 +180,7 @@ const ProjectFileCreate: FC> = () => { > = () => { rules={[{ required: true, message: '请选择项目所在行政区域类型' }]} options={regionDictTypeOptions} fieldProps={{ - onChange: (e) => { - setRegionDictType(e.target.value); - }, disabled: readOnly, + onChange: () => { + formRef.current?.setFieldsValue({ + regionDict: undefined, + }); + }, }} /> @@ -385,47 +389,56 @@ const ProjectFileCreate: FC> = () => { - {regionDictType === '1' ? ( - ​} - required={false} - colon={false} - rules={[ - { - required: true, - validator: (_, value) => { - if (!value || !value.province || !value.city || !value.district) { - return Promise.reject(new Error('请完整选择省市区')); - } - return Promise.resolve(); - } - } - ]} - > - - - ) : ( - ​} - required={false} - colon={false} - rules={[{ required: true, message: '请选择项目所在行政区域' }]} - options={regionOutsideOptions} - placeholder="请选择行政区域" - fieldProps={{ - disabled: readOnly, - }} - /> - )} + + {({ regionDictType }, ...rest) => { + console.log(rest); + return ( + <> + {regionDictType === '1' ? ( + ​} + required={false} + colon={false} + rules={[ + { + required: true, + validator: (_, value) => { + if (!value || !value.province || !value.city || !value.district) { + return Promise.reject(new Error('请完整选择省市区')); + } + return Promise.resolve(); + } + } + ]} + > + + + ) : ( + ​} + required={false} + colon={false} + rules={[{ required: true, message: '请选择项目所在行政区域' }]} + options={regionOutsideOptions} + placeholder="请选择行政区域" + fieldProps={{ + disabled: readOnly, + }} + /> + )} + + ); + }} +