yylib-quick-mobile
Version:
yylib-quick-mobile
89 lines (87 loc) • 3.09 kB
JavaScript
import React, {Component} from 'react';
import {createForm} from 'rc-form';
import {List} from 'antd-mobile'
import {forEach} from '../../utils/FunctionUtil';
class YYFormDev extends Component {
_getCloneProps(target) {
var props = {
form: this.props.form
};
if(!this.props.visible){
props.visible=false;
}
if (this.props.disabled) {
props.disabled = this.props.disabled;
}
else {
if (target.props.disabled != undefined) {
props.disabled = target.props.disabled;
}
}
if(this.props.billType&&this.props.billType.code&&target.props.field=="billType"){
//如果单据类型存在 且当前组件的类型为billtype 则自动为改组件的默认值赋值
Object.assign(props,{value:this.props.billType.code})
}
return props;
}
_renderChildren = (children) => {
let _this = this;
children = (children&&children.constructor==Array)?children:[children];
let colViews = [];//需要输出的表单数组
var doCloneElement = function doCloneElement(target) {
var props = _this._getCloneProps(target);
return React.cloneElement(target, props);
};
forEach(children, function (child, rowIndex) {
if (!React.isValidElement(child)) {
console.warn('FormWidget无法解析非React对象元素', child);
} else {
colViews.push(React.createElement(
'div',
{ key: "fromwidget_col_" + child.props.nid},
doCloneElement(child)
));
}
});
return <div>{colViews}</div>;
}
componentDidMount(){
if(this.props.onViewDidMount){
this.props.onViewDidMount(this);
}
}
render() {
let {visible,autoSave,findUI, offline,parentType, uiorigin, RunInDesign, uititle, uitype, uikey, nid,...restProps} = this.props;
return (
<form {...restProps} className='yy-form'>
<List>
{this._renderChildren(this.props.children)}
</List>
</form>);
}
}
YYFormDev.defaultProps = {
visible: true,
autoSave:true,//自动保存数据,
findUI:'',
offline:false,
parentType:'',
uiorigin:'',
RunInDesign:false,
uititle:'',
uitype:'',
uikey:'',
nid:'',
}
YYFormDev.create = createForm;
module.exports = YYFormDev.create({
onFieldsChange:function(formControl,valueOption){
let values={};
Object.keys(valueOption).map(key=>{
values[valueOption[key].name]=valueOption[key].value;
})
if(formControl&&formControl.listDataChange&&formControl.autoSave&&typeof formControl.listDataChange=="function"){
formControl.listDataChange.call(formControl._parent_obj,formControl.sys_front_id,values)
}
}
})(YYFormDev);