diff --git a/components/apolloTable/component/Cell.tsx b/components/apolloTable/component/Cell.tsx index bf7478971de69ef233a9127304ff24a511d3c648..4464577469332c2aa95596aa661eb09d03be9381 100644 --- a/components/apolloTable/component/Cell.tsx +++ b/components/apolloTable/component/Cell.tsx @@ -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} diff --git a/components/apolloTable/component/base/edit/container/index.tsx b/components/apolloTable/component/base/edit/container/index.tsx index e3cdcb17ba62c0974b7dc3261a2823bda0263b47..dcc6bb8baa7fb8efeefb8e88cbb73baad4454643 100644 --- a/components/apolloTable/component/base/edit/container/index.tsx +++ b/components/apolloTable/component/base/edit/container/index.tsx @@ -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
(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
(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');