@@ -2,14 +2,21 @@ import React, { useState } from 'react';
22import { Button , Form , Input , InputNumber , Table } from 'antd' ;
33import { Modal } from 'dt-react-component' ;
44
5- interface Data {
6- key : string ;
5+ interface FormValues {
76 name : string ;
87 age : number ;
98 address : string ;
109}
1110
12- const data : Data [ ] = [
11+ interface TableData extends FormValues {
12+ key : string ;
13+ }
14+
15+ interface CustomModalFormProps {
16+ customAttr : string ;
17+ }
18+
19+ const data : TableData [ ] = [
1320 {
1421 key : '1' ,
1522 name : 'UED' ,
@@ -24,9 +31,12 @@ const data: Data[] = [
2431 } ,
2532] ;
2633
27- const ModalForm = Modal . Form ( ( _props ) => {
34+ const ModalForm = Modal . Form < CustomModalFormProps , FormValues > ( ( props ) => {
2835 return (
2936 < >
37+ < Form . Item label = "我是自定义参数" name = { 'name' } initialValue = { props . customAttr } >
38+ < Input disabled />
39+ </ Form . Item >
3040 < Form . Item label = "name" name = { 'name' } >
3141 < Input />
3242 </ Form . Item >
@@ -43,7 +53,7 @@ const ModalForm = Modal.Form((_props) => {
4353export default ( ) => {
4454 const [ visible , setVisible ] = useState ( false ) ;
4555 const [ index , setIndex ] = useState < number > ( 0 ) ;
46- const [ dataSource , setDataSource ] = useState < Data [ ] > ( data ) ;
56+ const [ dataSource , setDataSource ] = useState < TableData [ ] > ( data ) ;
4757
4858 const columns = [
4959 {
@@ -65,7 +75,7 @@ export default () => {
6575 title : '操作' ,
6676 dataIndex : 'operate' ,
6777 key : 'operate' ,
68- render : ( _ : void , record : Data , index : number ) => {
78+ render : ( _ : void , _record : TableData , index : number ) => {
6979 return (
7080 < Button
7181 onClick = { ( ) => {
@@ -81,7 +91,7 @@ export default () => {
8191 } ,
8292 ] ;
8393
84- const onSubmit = ( values : Data ) => {
94+ const onSubmit = ( values : FormValues ) => {
8595 dataSource . splice ( index , 0 , { ...values , key : new Date ( ) + '' } ) ;
8696 setDataSource ( [ ...dataSource ] ) ;
8797
@@ -98,6 +108,7 @@ export default () => {
98108 visible = { visible }
99109 onCancel = { changeVisible }
100110 onSubmit = { onSubmit }
111+ customAttr = { 'customAttr' }
101112 />
102113 </ >
103114 ) ;
0 commit comments