提交 c0bfe3ef authored 作者: 钟是志's avatar 钟是志

把tableCompon 中的getFieldValue 方法 全部改为了 getFieldsValue 方法

具体原因: https://github.com/ant-design/ant-design/issues/11205 可能存在不稳定性; 测试后再说
上级 cdaaffa4
...@@ -771,7 +771,7 @@ export default class ZdyTable extends Component { ...@@ -771,7 +771,7 @@ export default class ZdyTable extends Component {
const key = r.sqls[r.sqls.length - 1]; const key = r.sqls[r.sqls.length - 1];
const value = defaultValues[key]; const value = defaultValues[key];
if (value == null) { if (value === null || value === undefined) {
return ''; return '';
} }
...@@ -949,7 +949,7 @@ export default class ZdyTable extends Component { ...@@ -949,7 +949,7 @@ export default class ZdyTable extends Component {
const key = r.sqls[r.sqls.length - 1]; const key = r.sqls[r.sqls.length - 1];
const value = defaultValues[key]; const value = defaultValues[key];
if (value == null) { if (value === null || value === undefined) {
return ''; return '';
} }
......
import React from 'react'; import React from 'react';
import { Button, Row, Col, message } from 'antd'; import {Button, Row, Col, message} from 'antd';
import ZdyTable from '../Table'; import ZdyTable from '../Table';
import UUID from 'react-native-uuid'; import UUID from 'react-native-uuid';
import { Card, WingBlank } from 'antd-mobile'; import {Card, WingBlank} from 'antd-mobile';
export default class ChildForm extends React.Component { export default class ChildForm extends React.Component {
constructor(props) { constructor(props) {
...@@ -12,6 +12,7 @@ export default class ChildForm extends React.Component { ...@@ -12,6 +12,7 @@ export default class ChildForm extends React.Component {
this.state = value; this.state = value;
} }
triggerChange = changedValue => { triggerChange = changedValue => {
// Should provide an event to pass value to Form. // Should provide an event to pass value to Form.
const onChange = this.props.onChange; const onChange = this.props.onChange;
...@@ -19,6 +20,7 @@ export default class ChildForm extends React.Component { ...@@ -19,6 +20,7 @@ export default class ChildForm extends React.Component {
onChange(changedValue); onChange(changedValue);
} }
}; };
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
// Should be a controlled component. // Should be a controlled component.
if ('value' in nextProps) { if ('value' in nextProps) {
...@@ -27,6 +29,7 @@ export default class ChildForm extends React.Component { ...@@ -27,6 +29,7 @@ export default class ChildForm extends React.Component {
this.state = value; this.state = value;
} }
} }
componentDidMount = () => { componentDidMount = () => {
if (Object.keys(this.state).length == 0 && this.props.isEdit) { if (Object.keys(this.state).length == 0 && this.props.isEdit) {
if (this.props.num != null && this.props.num > 0) { if (this.props.num != null && this.props.num > 0) {
...@@ -42,16 +45,16 @@ export default class ChildForm extends React.Component { ...@@ -42,16 +45,16 @@ export default class ChildForm extends React.Component {
} }
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.setState(objs ); this.setState(objs);
} }
this.triggerChange(objs ); this.triggerChange(objs);
} }
} }
}; };
delete = uuid => { delete = uuid => {
const objs = this.state; const objs = this.state;
const { const {
json: { numCode }, json: {numCode},
form, form,
base52, base52,
} = this.props; } = this.props;
...@@ -60,26 +63,23 @@ export default class ChildForm extends React.Component { ...@@ -60,26 +63,23 @@ export default class ChildForm extends React.Component {
return; return;
} }
const x = form.getFieldsValue()[base52];
const x = form.getFieldValue(base52);
delete x[uuid]; delete x[uuid];
delete x[""]; delete x[""];
if (!('value' in this.props)) { if (!('value' in this.props)) {
this.state=x this.state = x
} }
this.triggerChange(x); this.triggerChange(x);
if (numCode != null) { if (numCode != null) {
this.props.form.setFieldsValue({ [numCode]: Object.keys(objs).length }); this.props.form.setFieldsValue({[numCode]: Object.keys(objs).length});
} }
}; };
add = () => { add = () => {
const objs = this.state; const objs = this.state;
const { const {
json: { numCode }, json: {numCode},
form, form,
base52, base52,
} = this.props; } = this.props;
...@@ -95,7 +95,7 @@ export default class ChildForm extends React.Component { ...@@ -95,7 +95,7 @@ export default class ChildForm extends React.Component {
} }
this.triggerChange(objs); this.triggerChange(objs);
if (numCode != null) { if (numCode != null) {
this.props.form.setFieldsValue({ [numCode]: Object.keys(objs).length }); this.props.form.setFieldsValue({[numCode]: Object.keys(objs).length});
} }
}; };
...@@ -134,7 +134,7 @@ export default class ChildForm extends React.Component { ...@@ -134,7 +134,7 @@ export default class ChildForm extends React.Component {
<WingBlank size="lg"> <WingBlank size="lg">
{Object.keys(objs).length > 1 || rights.includes('add') ? ( {Object.keys(objs).length > 1 || rights.includes('add') ? (
<Card> <Card>
<Card.Body style={{ minHeight: 10 }}> <Card.Body style={{minHeight: 10}}>
{Object.keys(objs).map(r => { {Object.keys(objs).map(r => {
if (r == '') { if (r == '') {
return ''; return '';
...@@ -155,7 +155,7 @@ export default class ChildForm extends React.Component { ...@@ -155,7 +155,7 @@ export default class ChildForm extends React.Component {
taskId={taskId} taskId={taskId}
modalInit={modalInit} modalInit={modalInit}
hfInstance={hfInstance} hfInstance={hfInstance}
currentFormTitle={getCurrentFormTitle?getCurrentFormTitle(json.childFormKey):null} currentFormTitle={getCurrentFormTitle ? getCurrentFormTitle(json.childFormKey) : null}
getCellValue={getCellValue} getCellValue={getCellValue}
hfInstance={hfInstance} hfInstance={hfInstance}
getCellValue={getCellValue} getCellValue={getCellValue}
...@@ -180,7 +180,7 @@ export default class ChildForm extends React.Component { ...@@ -180,7 +180,7 @@ export default class ChildForm extends React.Component {
/> />
</Col> </Col>
{rights.includes('delete') && isEdit ? ( {rights.includes('delete') && isEdit ? (
<Col style={{ textAlign: 'right' }}> <Col style={{textAlign: 'right'}}>
<Button type="danger" size="small" onClick={this.delete.bind(this, r)}> <Button type="danger" size="small" onClick={this.delete.bind(this, r)}>
{deleteName || '删除'}{' '} {deleteName || '删除'}{' '}
</Button>{' '} </Button>{' '}
...@@ -194,11 +194,11 @@ export default class ChildForm extends React.Component { ...@@ -194,11 +194,11 @@ export default class ChildForm extends React.Component {
{rights.includes('add') && isEdit ? ( {rights.includes('add') && isEdit ? (
<Row> <Row>
<Col style={{ textAlign: 'center' }}> <Col style={{textAlign: 'center'}}>
<Button <Button
type="primary" type="primary"
size="small" size="small"
style={{ margin: 'auto' }} style={{margin: 'auto'}}
onClick={this.add} onClick={this.add}
> >
{addName || '新增'} {addName || '新增'}
...@@ -222,13 +222,13 @@ export default class ChildForm extends React.Component { ...@@ -222,13 +222,13 @@ export default class ChildForm extends React.Component {
* 子表单 * 子表单
* */ * */
return ( return (
<div style={{ width: '100%' }}> <div style={{width: '100%'}}>
<Row gutter={gutter}> <Row gutter={gutter}>
{Object.keys(objs).map(r => { {Object.keys(objs).map(r => {
if (r == '') { if (r == '') {
return ''; return '';
} }
console.log('子表单', r); // console.log('子表单', r);
// console.log(form.getFieldsValue()); // console.log(form.getFieldsValue());
return ( return (
<Col span={span} key={r}> <Col span={span} key={r}>
...@@ -237,7 +237,7 @@ export default class ChildForm extends React.Component { ...@@ -237,7 +237,7 @@ export default class ChildForm extends React.Component {
setRealTimeValues={this.props.setRealTimeValues} setRealTimeValues={this.props.setRealTimeValues}
modalInit={modalInit} modalInit={modalInit}
hfInstance={hfInstance} hfInstance={hfInstance}
currentFormTitle={getCurrentFormTitle?getCurrentFormTitle(json.childFormKey):null} currentFormTitle={getCurrentFormTitle ? getCurrentFormTitle(json.childFormKey) : null}
getCellValue={getCellValue} getCellValue={getCellValue}
formConfig={datas} formConfig={datas}
key={r} key={r}
...@@ -288,8 +288,8 @@ export default class ChildForm extends React.Component { ...@@ -288,8 +288,8 @@ export default class ChildForm extends React.Component {
</Row> </Row>
{rights.includes('add') && isEdit ? ( {rights.includes('add') && isEdit ? (
<Row> <Row>
<Col span={24} style={{ textAlign: 'center' }}> <Col span={24} style={{textAlign: 'center'}}>
<Button style={{ margin: 'auto' }} type="primary" onClick={this.add} size="small"> <Button style={{margin: 'auto'}} type="primary" onClick={this.add} size="small">
{addName || '新增'} {addName || '新增'}
</Button> </Button>
</Col>{' '} </Col>{' '}
......
...@@ -16,12 +16,9 @@ import { ...@@ -16,12 +16,9 @@ import {
DatePicker, DatePicker,
Radio, Radio,
Switch, Switch,
Modal,
TimePicker,
Row, Row,
Col, Col,
Select, Select,
Upload,
Form, Form,
Table, Table,
Cascader, Cascader,
...@@ -32,17 +29,9 @@ import {EditorState, Editor} from 'draft-js'; ...@@ -32,17 +29,9 @@ import {EditorState, Editor} from 'draft-js';
import MyBlockRenderer from '../App/MyBlockRender'; import MyBlockRenderer from '../App/MyBlockRender';
import CronEditor from 'antd-cron-editor'; import CronEditor from 'antd-cron-editor';
import { import {
InputItem as MobileInputItem,
ImagePicker as MobileImagePicker,
Modal as MobileModal,
DatePicker as MobileDatePicker,
List as MobileList, List as MobileList,
Picker as MobilePicker,
Flex, Flex,
Card, Card,
Toast,
Checkbox as MobileCheckbox,
TextareaItem as MobileTextareaItem,
Switch as MobileSwitch, Switch as MobileSwitch,
} from 'antd-mobile'; } from 'antd-mobile';
import ReactEcharts from 'echarts-for-react'; import ReactEcharts from 'echarts-for-react';
...@@ -101,9 +90,7 @@ const codeMessage = { ...@@ -101,9 +90,7 @@ const codeMessage = {
}; };
const {TextArea} = Input; const {TextArea} = Input;
const {Option} = Select; const {Option} = Select;
const must = <span style={{color: '#FF5350', marginLeft: 5, marginRight: 5}}>*</span>; const { RangePicker} = DatePicker;
const {MonthPicker, RangePicker} = DatePicker;
const AgreeItem = MobileCheckbox.AgreeItem;
const errorHandler = error => { const errorHandler = error => {
const {response} = error; const {response} = error;
...@@ -128,7 +115,9 @@ const errorHandler = error => { ...@@ -128,7 +115,9 @@ const errorHandler = error => {
loading: loading.models.DataColumn || loading.models.SqlManageEntity || loading.models.formList, loading: loading.models.DataColumn || loading.models.SqlManageEntity || loading.models.formList,
})) }))
export default class tableCom extends Component { export default class tableCom extends Component {
state = { constructor(props) {
super(props);
this.state = {
options: this.props.options || [], options: this.props.options || [],
labels: [], labels: [],
url: null, url: null,
...@@ -151,7 +140,8 @@ export default class tableCom extends Component { ...@@ -151,7 +140,8 @@ export default class tableCom extends Component {
pagination: false, pagination: false,
}, },
}; };
excludeKeys = ['defaultValues', '']; this.excludeKeys = ['defaultValues', ''];
}
closeModal = (fk, callback) => { closeModal = (fk, callback) => {
const {dispatch} = this.props; const {dispatch} = this.props;
const x = this.props.DataColumn.isShowModal const x = this.props.DataColumn.isShowModal
...@@ -724,7 +714,7 @@ export default class tableCom extends Component { ...@@ -724,7 +714,7 @@ export default class tableCom extends Component {
this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => { this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => {
if (init != null && Object.keys(init).length > 0) { if (init != null && Object.keys(init).length > 0) {
let base52 = dataColumn.base52; let base52 = dataColumn.base52;
let vlu = this.props.form.getFieldValue(base52); let vlu = this.props.form.getFieldsValue()[base52];
const labs = []; const labs = [];
this.searchJson(vlu, this.state.options, 0, labs) this.searchJson(vlu, this.state.options, 0, labs)
...@@ -747,7 +737,7 @@ export default class tableCom extends Component { ...@@ -747,7 +737,7 @@ export default class tableCom extends Component {
this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => { this.getFunctionValue(json.funcs, {base52: this.props.uuid}, json, () => {
if (init != null && Object.keys(init).length > 0) { if (init != null && Object.keys(init).length > 0) {
let base52 = dataColumn.base52; let base52 = dataColumn.base52;
let vlu = this.props.form.getFieldValue(base52); let vlu = this.props.form.getFieldsValue()[base52]
const labs = []; const labs = [];
if (vlu instanceof Array) { if (vlu instanceof Array) {
for (var i = 0; i < this.state.options.length; i++) { for (var i = 0; i < this.state.options.length; i++) {
...@@ -1217,7 +1207,7 @@ export default class tableCom extends Component { ...@@ -1217,7 +1207,7 @@ export default class tableCom extends Component {
isEdit: this.props.isEdit, isEdit: this.props.isEdit,
taskAssignee: this.props.taskAssignee, taskAssignee: this.props.taskAssignee,
userId: this.props.userId, userId: this.props.userId,
taskId:this.props.taskId, taskId: this.props.taskId,
}, },
this.props.index, this.props.index,
this.props.fatherCode, this.props.fatherCode,
...@@ -1337,7 +1327,7 @@ export default class tableCom extends Component { ...@@ -1337,7 +1327,7 @@ export default class tableCom extends Component {
callback: options => { callback: options => {
const optionsx = []; const optionsx = [];
let base52 = dataColumn.base52; let base52 = dataColumn.base52;
let vl = this.props.form.getFieldValue(base52); let vl = this.props.form.getFieldsValue()[base52];
let isExist = false; let isExist = false;
for (var i = 0; i < options.length; i++) { for (var i = 0; i < options.length; i++) {
if (vl == options[i][valueName] && !isExist) { if (vl == options[i][valueName] && !isExist) {
...@@ -1376,7 +1366,7 @@ export default class tableCom extends Component { ...@@ -1376,7 +1366,7 @@ export default class tableCom extends Component {
payload: {sqlKey, allValues}, payload: {sqlKey, allValues},
callback: options => { callback: options => {
let base52 = dataColumn.base52; let base52 = dataColumn.base52;
let vl = this.props.form.getFieldValue(base52); let vl = this.props.form.getFieldsValue()[base52];
const optionsx = []; const optionsx = [];
let isExist = false; let isExist = false;
for (var i = 0; i < options.length; i++) { for (var i = 0; i < options.length; i++) {
...@@ -1557,7 +1547,7 @@ export default class tableCom extends Component { ...@@ -1557,7 +1547,7 @@ export default class tableCom extends Component {
if (json.comName == 'PartForm') { if (json.comName == 'PartForm') {
const fk = this.props.form.getFieldValue(this.props.uuid) || json.childFormKey; const fk = this.props.form.getFieldsValue()[this.props.uuid] || json.childFormKey;
if (fk == null) { if (fk == null) {
return <></>; return <></>;
} }
...@@ -1637,7 +1627,7 @@ export default class tableCom extends Component { ...@@ -1637,7 +1627,7 @@ export default class tableCom extends Component {
return ( return (
<> <>
{this.props.form.getFieldDecorator(uid, { {this.props.form.getFieldDecorator(uid, {
initialValue: this.props.form.getFieldValue(uid) || json.initialValue, initialValue: this.props.form.getFieldsValue()[uid] || json.initialValue,
})(<Input type="hidden"/>)} })(<Input type="hidden"/>)}
<span <span
style={{ style={{
...@@ -1647,7 +1637,7 @@ export default class tableCom extends Component { ...@@ -1647,7 +1637,7 @@ export default class tableCom extends Component {
}} }}
{...json.props} {...json.props}
> >
{this.props.form.getFieldValue(uid)} {this.props.form.getFieldsValue()[uid]}
</span> </span>
</> </>
); );
...@@ -1993,6 +1983,10 @@ export default class tableCom extends Component { ...@@ -1993,6 +1983,10 @@ export default class tableCom extends Component {
} }
} }
if(initValue === null || initValue === undefined){
initValue = '';
}
if (!isEdit) { if (!isEdit) {
if (this.props.fatherCode) { if (this.props.fatherCode) {
if (bindObj != null) { if (bindObj != null) {
...@@ -2510,6 +2504,7 @@ export default class tableCom extends Component { ...@@ -2510,6 +2504,7 @@ export default class tableCom extends Component {
); );
} }
} else { } else {
// console.log(JSON.stringify(this.props.form.getFieldsValue()), '----formValue----');
cm = getFieldDecorator(dataColumn.base52, { cm = getFieldDecorator(dataColumn.base52, {
initialValue: initValue, initialValue: initValue,
rules: rules:
...@@ -2529,7 +2524,7 @@ export default class tableCom extends Component { ...@@ -2529,7 +2524,7 @@ export default class tableCom extends Component {
case 'Switch': case 'Switch':
if (get === 'mobile') { if (get === 'mobile') {
if (dataColumn == null || json.formula != null) { if (dataColumn == null || json.formula != null) {
cm = this.props.form.getFieldValue(this.props.uuid); cm = this.props.form.getFieldsValue()[this.props.uuid];
break; break;
} }
cm = ( cm = (
...@@ -3135,9 +3130,12 @@ export default class tableCom extends Component { ...@@ -3135,9 +3130,12 @@ export default class tableCom extends Component {
} }
break; break;
case 'ChildForm': case 'ChildForm':
cm = getFieldDecorator(dataColumn.base52, {
initialValue: initValue || {}, // console.log(dataColumn.base52, '----key-ChildForm--'); // KUSyCzEhdCJ
})( // console.log(JSON.stringify(this.props.form.getFieldsValue()), '----formValue----');
// console.log(JSON.stringify(initValue)); // undefined
cm = getFieldDecorator(dataColumn.base52, {initialValue: initValue || {},})(
<ChildForm <ChildForm
taskId={this.props.taskId} taskId={this.props.taskId}
setRealTimeValues={this.props.setRealTimeValues} setRealTimeValues={this.props.setRealTimeValues}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论