/** * Created by Administrator on 2017/8/8. */ /// import * as React from "react" import {addType, addTypeWithWrapper, getComponentProps} from "../field"; import {FieldArray, WrappedFieldArrayProps} from "redux-form" import { AutoComplete, Radio ,Checkbox, InputNumber, Tooltip, Upload, Button, Icon} from 'antd'; const RadioGroup = Radio.Group; import {Input,Select,DatePicker} from "antd"; const {TextArea} =Input; const {RangePicker} = DatePicker; const Option = Select.Option; import {WidgetProps} from "../field"; import {Options} from "../form"; import {RuntimeAsyncOptions} from "../form"; import {renderFields} from "../render-fields"; import { setButton } from "../buttons"; const PropTypes = require('prop-types') const RCSelect = require("rc-select").default import * as moment from "moment" import { ResolveMaybePromise } from '../resolve-maybe-promise'; import { isArray } from 'util'; RCSelect.propTypes['value'] = PropTypes.any Option.propTypes['value'] = PropTypes.any Select.propTypes['value'] = PropTypes.any const emptyArray:any[] = [] // const convertValueToString = Comp=>(props)=>{ // let onChange=!props.onChange?undefined:(value)=>{ // props.onChange() // } // return // } const errorStyle={color:"red"}; function TextInput(props:WidgetProps){ const componentProps = getComponentProps(props.fieldSchema) return
{props.fieldSchema.label}
{props.meta.error}
} function SelectInput (props:WidgetProps){ const {fieldSchema,input,meta} = props const componentProps:any = getComponentProps(props.fieldSchema) return
{(options)=>{ if(options == undefined) options = emptyArray const value = fieldSchema.multiple||componentProps.mode==="multiple"?(isArray(input.value)?input.value:[]):input.value return }}
{meta.error}
} function CheckboxInput (props:WidgetProps){ const componentProps = getComponentProps(props.fieldSchema) return
props.input.onChange((e.target as HTMLInputElement).checked)} checked={Boolean(props.input.value)} {...componentProps} />
} function DateTimeInput(props:WidgetProps){ const value=props.input.value?moment(props.input.value):undefined; const componentProps = getComponentProps(props.fieldSchema) return
props.input.onChange(dateString)} {...componentProps} />
{props.meta.error}
} function DateInput(props:WidgetProps){ let value= null; if(props.input.value){ if(!(props.input.value instanceof moment)) value= moment(props.input.value); } const componentProps = getComponentProps(props.fieldSchema) return
{props.input.onChange(dateString)}} {...componentProps} />
{props.meta.error}
} function DateTimeRangeInput (props:WidgetProps){ let value =props.input.value const componentProps = getComponentProps(props.fieldSchema) return
{ props.input.onChange(dataStrings); }} {...componentProps} />
{props.meta.error}
} function NumberInput(props:WidgetProps){ let required={ required:props.required }; const componentProps = getComponentProps(props.fieldSchema) return
{if(isNaN(parseFloat(value as any))){ props.input.onChange(0) }else{ props.input.onChange(parseFloat(value as any) ) } }} {...componentProps} />
{props.meta.error}
} const AutoCompleteSelect = function(props:WidgetProps){ const {meta,input,fieldSchema} = props; const componentProps = getComponentProps(props.fieldSchema) return
{options=>{ return ({value:itm.value,text:itm.name})):emptyArray} style={{ width:"100%" }} value={input.value} onSelect={(value)=>input.onChange(value)} {...componentProps} /> }}
{meta.error}
} class FileInput extends React.Component{ onChange=(info:any)=>{ this.props.input.onChange((info.fileList as any[]).map(file=>{ if(file.response && file.response.url){ file.url = file.response.url; } return { ...file } }).filter(file=>{ if(file.response && file.response.url){ return file.status==="done"; } return true; })) }; customRequest=(customRequestParams:any)=>{ const {onSuccess,onError,onProgress,file,filename} = customRequestParams if(!this.props.fieldSchema.onFileChange){ setTimeout(()=>{ onProgress({percent:100}); onSuccess(filename,null); },1) }else{ this.props.fieldSchema.onFileChange(file).then(previewUrl=>{ onProgress({percent:100}); onSuccess(previewUrl,null); },(err)=>onError(err)) } }; render(){ const componentProps = getComponentProps(this.props.fieldSchema) return
} } function SelectRadio (props:WidgetProps){ const componentProps = getComponentProps(props.fieldSchema) return
{options=>props.input.onChange(v)} {...componentProps} > { options?options.map((option) => ( {option.name} )):null } }

{props.meta.error}

} function DateRangeInput (props:WidgetProps){ const dateFormat = props.fieldSchema.dateFormat || 'YYYY-MM-DD'; const value=props.input.value const from =value?value[0]:undefined; const to =value?value[1]:undefined; const componentProps = getComponentProps(props.fieldSchema) return
{props.input.onChange(dateStrings)}} {...componentProps} />
} function TextareaInput (props:WidgetProps){ const componentProps = getComponentProps(props.fieldSchema) return