@@ -11,8 +11,11 @@ import FormDatePicker from './comps/datePicker';
1111import Stepper from '../Stepper' ;
1212import TextArea from '../TextArea' ;
1313import Slider from '../Slider' ;
14- import Flex from '../Flex' ;
15- import { View , Text , SafeAreaView , StyleSheet , TextInput } from 'react-native' ;
14+ import Label from './comps/label' ;
15+ import Tip from './comps/tip' ;
16+ import FormList from './formList' ;
17+ import { View , SafeAreaView , StyleSheet , TextInput } from 'react-native' ;
18+ import styles from './styles' ;
1619
1720const FormItems : FC < any > = ( { formDatas = [ ] } ) => {
1821 const {
@@ -153,11 +156,15 @@ const FormItems: FC<any> = ({ formDatas = [] }) => {
153156 />
154157 ) ;
155158 }
159+ if ( v . type === 'cardList' ) {
160+ return < FormList formListValue = { v } /> ;
161+ }
156162 // 自定义组件
157163 if ( ! isObjectEmpty ( customComponentList ) && Object . keys ( customComponentList ) . includes ( v . type ) ) {
158164 return React . isValidElement ( customComponentList [ v . type ] )
159165 ? React . cloneElement ( customComponentList [ v . type ] , {
160166 ...v . attr ,
167+ value : store [ v . field ] ,
161168 onChange : ( value : unknown ) => {
162169 change ( v . field , value ) ;
163170 innerValidate ( ) ;
@@ -168,32 +175,17 @@ const FormItems: FC<any> = ({ formDatas = [] }) => {
168175 return null ;
169176 } ;
170177
171- const Label = ( v : FormItemsProps ) => {
172- return (
173- < Flex >
174- { v . required && < Text style = { { color : 'red' , marginRight : 5 } } > *</ Text > }
175- < Text style = { styles . label } { ...v . attr } >
176- { v . name }
177- </ Text >
178- </ Flex >
179- ) ;
180- } ;
181-
182- const Tip = ( v : FormItemsProps ) => {
183- const content = validator . message ( v . field , store [ v . field ] , {
184- validate : v ?. validate ,
185- } ) ;
186- return < Text style = { { color : 'red' , marginBottom : content && 10 , marginTop : content && 10 } } > { content } </ Text > ;
187- } ;
188-
189178 const _render = ( ) => {
190179 return formDatas . map ( ( v : FormItemsProps , i : number ) => {
180+ if ( v . hide ) {
181+ return null ;
182+ }
191183 return (
192184 < View key = { i } style = { styles . form_items_container } >
193185 < View style = { styles . form_items } >
194- { Label ( v ) }
186+ < Label v = { v } />
195187 { _renderComponent ( v ) }
196- { Tip ( v ) }
188+ < Tip v = { v } />
197189 </ View >
198190 </ View >
199191 ) ;
@@ -203,26 +195,4 @@ const FormItems: FC<any> = ({ formDatas = [] }) => {
203195 return < SafeAreaView style = { styles . warpper } > { _render ( ) } </ SafeAreaView > ;
204196} ;
205197
206- const styles = StyleSheet . create ( {
207- warpper : {
208- backgroundColor : '#fff' ,
209- } ,
210- form_items_container : {
211- flex : 1 ,
212- } ,
213- form_items : {
214- textAlign : 'center' ,
215- margin : 10 ,
216- borderBottomWidth : 0.5 ,
217- borderBottomColor : '#eee' ,
218- } ,
219- label : {
220- width : 110 ,
221- fontSize : 16 ,
222- color : '#434343' ,
223- fontWeight : '500' ,
224- marginBottom : 10 ,
225- } ,
226- } ) ;
227-
228198export default FormItems ;
0 commit comments