From 83de372980262b2d97c2f3d95447ccdf325216c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Mon, 12 Oct 2020 13:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20performance:=20use=20profr?= =?UTF-8?q?om=20(#7442)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⚡️ performance: use profrom * up version --- package.json | 3 +- .../ListTableList/components/UpdateForm.tsx | 269 +++++++----------- 2 files changed, 106 insertions(+), 166 deletions(-) diff --git a/package.json b/package.json index 60a24e43..a44c52bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ant-design-pro", - "version": "4.2.1", + "version": "4.2.2", "private": true, "description": "An out-of-box UI solution for enterprise applications", "scripts": { @@ -55,6 +55,7 @@ "dependencies": { "@ant-design/icons": "^4.0.0", "@ant-design/pro-descriptions": "^1.0.19", + "@ant-design/pro-form": "^1.0.1", "@ant-design/pro-layout": "^6.4.19", "@ant-design/pro-table": "^2.8.1", "@umijs/route-utils": "^1.0.33", diff --git a/src/pages/ListTableList/components/UpdateForm.tsx b/src/pages/ListTableList/components/UpdateForm.tsx index 3de404bc..704eff25 100644 --- a/src/pages/ListTableList/components/UpdateForm.tsx +++ b/src/pages/ListTableList/components/UpdateForm.tsx @@ -1,5 +1,13 @@ import React, { useState } from 'react'; -import { Form, Button, DatePicker, Input, Modal, Radio, Select, Steps } from 'antd'; +import { Modal } from 'antd'; +import { + ProFormSelect, + ProFormText, + ProFormTextArea, + StepsForm, + ProFormRadio, + ProFormDateTimePicker, +} from '@ant-design/pro-form'; import { TableListItem } from '../data.d'; @@ -13,28 +21,18 @@ export interface FormValueType extends Partial { export interface UpdateFormProps { onCancel: (flag?: boolean, formVals?: FormValueType) => void; - onSubmit: (values: FormValueType) => void; + onSubmit: (values: FormValueType) => Promise; updateModalVisible: boolean; values: Partial; } -const FormItem = Form.Item; -const { Step } = Steps; -const { TextArea } = Input; -const { Option } = Select; -const RadioGroup = Radio.Group; export interface UpdateFormState { formVals: FormValueType; currentStep: number; } -const formLayout = { - labelCol: { span: 7 }, - wrapperCol: { span: 13 }, -}; - const UpdateForm: React.FC = (props) => { - const [formVals, setFormVals] = useState({ + const [formValues] = useState({ name: props.values.name, desc: props.values.desc, key: props.values.key, @@ -45,169 +43,110 @@ const UpdateForm: React.FC = (props) => { frequency: 'month', }); - const [currentStep, setCurrentStep] = useState(0); - - const [form] = Form.useForm(); - - const { - onSubmit: handleUpdate, - onCancel: handleUpdateModalVisible, - updateModalVisible, - values, - } = props; - - const forward = () => setCurrentStep(currentStep + 1); - - const backward = () => setCurrentStep(currentStep - 1); + const { onCancel: handleUpdateModalVisible, updateModalVisible } = props; - const handleNext = async () => { - const fieldsValue = await form.validateFields(); - - setFormVals({ ...formVals, ...fieldsValue }); - - if (currentStep < 2) { - forward(); - } else { - handleUpdate({ ...formVals, ...fieldsValue }); - } - }; - - const renderContent = () => { - if (currentStep === 1) { - return ( - <> - - - - - - - - - - - - - - ); - } - if (currentStep === 2) { - return ( - <> - { + return ( + handleUpdateModalVisible()} > - - - - - - - ); - } - return ( - <> - + ); + }} + onFinish={props.onSubmit} + > + + - - - + -