Commit 98f42885 authored by zhangwenshuai's avatar zhangwenshuai

增加编辑单元格重置兼容

parent 5c0d3fbe
......@@ -68,7 +68,17 @@ const Cell = (props: CellProps) => {
};
const changeCellData = (changedValue: any, option?: any) => {};
const emitChangeCellData = (changedValue: any, optionValue: any) => {
/**
*
* @param changedValue 修改的值
* @param optionValue 修改的原始数据
* @param reset 是否重置编辑状态
*/
const emitChangeCellData = (changedValue: any, optionValue: any, reset?: boolean) => {
if (reset) {
resetEditStatus();
return;
}
let temp: CellDataProps[] = [];
cellData.map((item: CellDataProps) => {
temp.push({ text: item.text, value: item.value });
......@@ -349,9 +359,9 @@ const Cell = (props: CellProps) => {
columnConfig={columnConfig}
onChange={changeCellData}
rowData={record}
onEmitChange={(changedValue: any, optionValue: any) => {
onEmitChange={(changedValue: any, optionValue: any, reset?: boolean) => {
const value = setFormat(editConfig, columnConfig, changedValue, optionValue);
emitChangeCellData(value, optionValue);
emitChangeCellData(value, optionValue, reset);
}}
tableId={tableId}
cellRenderProps={cellRenderProps}
......
......@@ -4,7 +4,7 @@ import { antiAssign } from '../../../../utils/utils';
interface Props {
onEmitChange: Function;
tableId:string|number;
tableId: string | number;
}
interface State {
value: any;
......@@ -43,6 +43,26 @@ export default function CellContainer<P extends Props>(Comp) {
this.setState({ value, option });
};
onBlur = (e: any) => {
const { tableId, onEmitChange } = this.props;
const { value, option } = this.state;
const doms = document.querySelectorAll(`.cellUnit.table_${tableId}`);
let editing = false;
if (doms) {
for (let i = 0; i < doms.length; i++) {
// 检测当前是否有编辑中的组件,没有则重置编辑框(因业务需求,可能直接删除掉当前编辑单元格的编辑状态)
if (doms[i].getAttribute('data-editing-cell') === '1') {
editing = true;
break;
}
}
}
if (!editing) {
if (typeof onEmitChange === 'function') {
onEmitChange(value, option, 1);
}
return;
}
let currTarget = e.target;
while (currTarget && currTarget != document) {
let editing = currTarget.getAttribute('data-editing-cell');
......@@ -52,12 +72,9 @@ export default function CellContainer<P extends Props>(Comp) {
}
currTarget = currTarget.parentNode;
}
const { onEmitChange, tableId } = this.props;
const { value, option } = this.state;
if (typeof onEmitChange === 'function') {
onEmitChange(value, option);
// 清除所有dom的编辑状态
const doms = document.querySelectorAll(`.cellUnit.table_${tableId}`);
if (doms) {
doms.forEach((item) => {
item.setAttribute('data-editing-cell', '0');
......
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