Commit cc13ce4b authored by zhangwenshuai's avatar zhangwenshuai

增加编辑状态数据同步

parent e16b0b50
import React, { useEffect, useMemo, useState, useRef } from 'react'; import React, { useState, useRef } from 'react';
import { Checkbox, message, Popover } from 'antd'; import { Checkbox, message, Popover } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import _ from 'lodash'; import _ from 'lodash';
import { config } from './base/config'; import { config } from './base/config';
import { getEditComponent, getFormat, setFormat } from './base'; import { getFormat, setFormat } from './base';
import s from './Cell.less'; import s from './Cell.less';
import { CellProps, CellDataProps } from './interface'; import { CellProps, CellDataProps } from './interface';
import FormHelper from '../utils/formHelper'; import FormHelper from '../utils/formHelper';
import firstIcon from '../assets/first.png';
import secondIcon from '../assets/second.png';
import thirdIcon from '../assets/third.png';
import expandIcon from '../assets/extend.png'; import expandIcon from '../assets/extend.png';
import { transferAttr } from './base/_utils/transferAttr'; import { transferAttr } from './base/_utils/transferAttr';
import { emptyModel } from '@/submodule/components/apolloTable/component/base/_utils/setFormatter'; import { emptyModel } from '@/submodule/components/apolloTable/component/base/_utils/setFormatter';
......
...@@ -8,6 +8,7 @@ interface Props { ...@@ -8,6 +8,7 @@ interface Props {
interface State { interface State {
value: any; value: any;
option: any; option: any;
propsValue: any;
} }
export default function CellContainer<P extends Props>(Comp) { export default function CellContainer<P extends Props>(Comp) {
return class extends React.Component<P & Props, State> { return class extends React.Component<P & Props, State> {
...@@ -15,11 +16,21 @@ export default function CellContainer<P extends Props>(Comp) { ...@@ -15,11 +16,21 @@ export default function CellContainer<P extends Props>(Comp) {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
propsValue: props.value, // 组件的原值
value: props.value, // 组件的值 value: props.value, // 组件的值
option: undefined, // 选择项 option: undefined, // 选择项
}; };
this.container = React.createRef(); this.container = React.createRef();
} }
static getDerivedStateFromProps(nextProps: any, prevState: any) {
if (JSON.stringify(prevState.propsValue) !== JSON.stringify(nextProps.value)) {
return {
propsValue: nextProps.value,
value: nextProps.value,
};
}
return null;
}
componentDidMount(): void { componentDidMount(): void {
document.addEventListener('click', this.onBlur, false); document.addEventListener('click', this.onBlur, false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment