From c2b0f651dc1ada8209ef1f76f81206982520ecd4 Mon Sep 17 00:00:00 2001 From: zhangwenshuai Date: Mon, 4 Jan 2021 15:29:30 +0800 Subject: [PATCH] update sub --- .../component/base/edit/date/index.tsx | 5 ++++- .../component/base/edit/input/index.tsx | 5 ++++- .../component/base/edit/number/index.tsx | 5 ++++- .../component/base/edit/search/index.tsx | 5 ++++- .../component/base/edit/select/index.tsx | 5 ++++- components/apolloTable/editFormV3/index.tsx | 20 ++++++++++++------- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/components/apolloTable/component/base/edit/date/index.tsx b/components/apolloTable/component/base/edit/date/index.tsx index fe1e9b2..f0ebd4b 100644 --- a/components/apolloTable/component/base/edit/date/index.tsx +++ b/components/apolloTable/component/base/edit/date/index.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { DatePicker } from 'antd'; import { antiAssign } from '../../../../utils/utils'; import styles from './styles.less'; @@ -23,6 +23,9 @@ export const ApolloDate = (props: any) => { selfProps.disabled = !!props.disabled; const isOpen: any = useRef(); const [curValue, setCurValue] = useState(value); + useEffect(() => { + setCurValue(value); + }, [value]); const changeValue = (date: any, dateString: string) => { setCurValue(date); if (typeof onChange === 'function') { diff --git a/components/apolloTable/component/base/edit/input/index.tsx b/components/apolloTable/component/base/edit/input/index.tsx index 09e50d5..f1c5f83 100644 --- a/components/apolloTable/component/base/edit/input/index.tsx +++ b/components/apolloTable/component/base/edit/input/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Input } from 'antd'; import styles from './styles.less'; import { antiAssign } from '../../../../utils/utils'; @@ -25,6 +25,9 @@ export const ApolloInput = (props: ApolloInputProps) => { ]); selfProps.disabled = !!props.disabled; const [curValue, setCurValue] = useState(value); + useEffect(() => { + setCurValue(value); + }, [value]); const changeValue = (value: any) => { setCurValue(value); if (typeof onChange === 'function') { diff --git a/components/apolloTable/component/base/edit/number/index.tsx b/components/apolloTable/component/base/edit/number/index.tsx index e79dfa2..138084f 100644 --- a/components/apolloTable/component/base/edit/number/index.tsx +++ b/components/apolloTable/component/base/edit/number/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { InputNumber } from 'antd'; import styles from './styles.less'; import { ApolloNumberProps } from '../editInterface'; @@ -24,6 +24,9 @@ export const ApolloNumber = (props: ApolloNumberProps) => { ]); selfProps.disabled = !!props.disabled; const [curValue, setCurValue] = useState(value); + useEffect(() => { + setCurValue(value); + }, [value]); const changeValue = (value: any) => { setCurValue(value); if (typeof onChange === 'function') { diff --git a/components/apolloTable/component/base/edit/search/index.tsx b/components/apolloTable/component/base/edit/search/index.tsx index 4b3c86c..86a5e5d 100644 --- a/components/apolloTable/component/base/edit/search/index.tsx +++ b/components/apolloTable/component/base/edit/search/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from 'react'; +import React, { useState, useRef, useEffect } from 'react'; import { message } from 'antd'; import Search from '../../extra/associationSearch'; import { ApolloSearchProps } from '../editInterface'; @@ -31,6 +31,9 @@ export const ApolloSearch = (props: ApolloSearchProps) => { selfProps.mode = 'multiple'; } const [curValue, setCurValue] = useState(value); + useEffect(() => { + setCurValue(value); + }, [value]); const isOpen: any = useRef(); const changeValue = (value: any) => { if (isMultiple && maxCount && maxCount < value.length) { diff --git a/components/apolloTable/component/base/edit/select/index.tsx b/components/apolloTable/component/base/edit/select/index.tsx index 1789c3e..019c8da 100644 --- a/components/apolloTable/component/base/edit/select/index.tsx +++ b/components/apolloTable/component/base/edit/select/index.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { Select } from 'antd'; import { ApolloSelectProps } from '../editInterface'; import { antiAssign } from '../../../../utils/utils'; @@ -31,6 +31,9 @@ export const ApolloSelect = (props: ApolloSelectProps) => { selfProps.mode = 'multiple'; } const [curValue, setCurValue] = useState(value); + useEffect(() => { + setCurValue(value); + }, [value]); const isOpen: any = useRef(); const changeValue = (value: any) => { setCurValue(value); diff --git a/components/apolloTable/editFormV3/index.tsx b/components/apolloTable/editFormV3/index.tsx index f00a3aa..f5ddf65 100644 --- a/components/apolloTable/editFormV3/index.tsx +++ b/components/apolloTable/editFormV3/index.tsx @@ -14,7 +14,7 @@ * 失去焦点:onBlurFn * */ import React, { Component } from 'react'; -import { Form, Button, message, Tooltip } from 'antd'; +import { Form, Button, Tooltip } from 'antd'; import _ from 'lodash'; import IconFont from '@/submodule/components/IconFont/IconFont'; import { emptyModel } from '../component/base/_utils/setFormatter'; @@ -35,7 +35,7 @@ class FormWrap extends Component { e.preventDefault(); e.stopPropagation(); const { - rowId, form, handleSubmit, data, rowData, detailType, + form, handleSubmit, data, rowData, detailType, } = this.props; form.validateFieldsAndScroll((err, values) => { if (!err) { @@ -44,10 +44,11 @@ class FormWrap extends Component { const item = data.find((temp: any) => { return temp.columnName === key; }); - const { columnType, columnAttrObj, renderEditForm, readOnlyFlag, dynamicCellConfigDTO } = item; - if (readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) { - return; - } + const { columnType, renderEditForm, readOnlyFlag, dynamicCellConfigDTO } = item; + /** !!此方法只在新增时使用,因此只读数据也上传,此段代码暂时注释,后有问题再看 * */ + // if (readOnlyFlag || (dynamicCellConfigDTO && dynamicCellConfigDTO.readonlyFlag)) { + // return; + // } let detailConfig: any; if (typeof renderEditForm === 'function') { detailConfig = renderEditForm({ cellData: values[key], rowData, columnConfig: item }); @@ -117,7 +118,7 @@ class FormWrap extends Component { renderEditForm = (item) => { const { getFieldDecorator } = this.props.form; - const { rowData, rowId, getInstanceDetail, onEmitChange } = this.props; + const { rowData, rowId, getInstanceDetail, onEmitChange, changeParams } = this.props; const { columnType, columnName, @@ -169,9 +170,14 @@ class FormWrap extends Component { columnCode: columnName, cellValueList: changedValue, }); + // 编辑时回调,调接口 if (typeof onEmitChange === 'function') { onEmitChange(extraData); } + // 新增时回调,不调接口 + if (typeof changeParams === 'function') { + changeParams(columnName, changedValue, optionValue); + } }; return ( -- 2.21.0