修复切换行政区域的报错问题
This commit is contained in:
@ -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<Record<string, any>> = () => {
|
||||
const readOnly = query?.action === 'view';
|
||||
const id = query?.id; // 文件 id
|
||||
|
||||
const [regionDictType, setRegionDictType] = useState<string>('1');
|
||||
const formRef = useRef<FormInstance>();
|
||||
const [error, setError] = useState<ErrorField[]>([]);
|
||||
const getErrorInfo = (errors: ErrorField[]) => {
|
||||
const errorCount = errors.filter((item) => item.errors.length > 0).length;
|
||||
@ -179,6 +180,7 @@ const ProjectFileCreate: FC<Record<string, any>> = () => {
|
||||
<ProForm
|
||||
layout="horizontal"
|
||||
requiredMark
|
||||
formRef={formRef}
|
||||
submitter={{
|
||||
searchConfig: {
|
||||
submitText: '建档完成',
|
||||
@ -354,10 +356,12 @@ const ProjectFileCreate: FC<Record<string, any>> = () => {
|
||||
rules={[{ required: true, message: '请选择项目所在行政区域类型' }]}
|
||||
options={regionDictTypeOptions}
|
||||
fieldProps={{
|
||||
onChange: (e) => {
|
||||
setRegionDictType(e.target.value);
|
||||
},
|
||||
disabled: readOnly,
|
||||
onChange: () => {
|
||||
formRef.current?.setFieldsValue({
|
||||
regionDict: undefined,
|
||||
});
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
@ -385,47 +389,56 @@ const ProjectFileCreate: FC<Record<string, any>> = () => {
|
||||
</ProFormDependency>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
{regionDictType === '1' ? (
|
||||
<ProForm.Item
|
||||
name="regionDict"
|
||||
label={<span>​</span>}
|
||||
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();
|
||||
}
|
||||
}
|
||||
]}
|
||||
>
|
||||
<CitySelect
|
||||
placeholder={{
|
||||
province: '请选择省份',
|
||||
city: '请选择城市',
|
||||
district: '请选择区域',
|
||||
}}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
</ProForm.Item>
|
||||
) : (
|
||||
<ProFormSelect
|
||||
name="regionDict"
|
||||
label={<span>​</span>}
|
||||
required={false}
|
||||
colon={false}
|
||||
rules={[{ required: true, message: '请选择项目所在行政区域' }]}
|
||||
options={regionOutsideOptions}
|
||||
placeholder="请选择行政区域"
|
||||
fieldProps={{
|
||||
disabled: readOnly,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<ProFormDependency name={['regionDictType']}>
|
||||
{({ regionDictType }, ...rest) => {
|
||||
console.log(rest);
|
||||
return (
|
||||
<>
|
||||
{regionDictType === '1' ? (
|
||||
<ProForm.Item
|
||||
name="regionDict"
|
||||
label={<span>​</span>}
|
||||
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();
|
||||
}
|
||||
}
|
||||
]}
|
||||
>
|
||||
<CitySelect
|
||||
placeholder={{
|
||||
province: '请选择省份',
|
||||
city: '请选择城市',
|
||||
district: '请选择区域',
|
||||
}}
|
||||
disabled={readOnly}
|
||||
/>
|
||||
</ProForm.Item>
|
||||
) : (
|
||||
<ProFormSelect
|
||||
name="regionDict"
|
||||
label={<span>​</span>}
|
||||
required={false}
|
||||
colon={false}
|
||||
rules={[{ required: true, message: '请选择项目所在行政区域' }]}
|
||||
options={regionOutsideOptions}
|
||||
placeholder="请选择行政区域"
|
||||
fieldProps={{
|
||||
disabled: readOnly,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</ProFormDependency>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
|
Reference in New Issue
Block a user