diff --git a/components/apolloTable/component/Cell.tsx b/components/apolloTable/component/Cell.tsx index 3ca4c302694992a683fa30cf4407c864992c4944..bcc96c55dc9c8f0ed335078aa9ee2e6258542969 100644 --- a/components/apolloTable/component/Cell.tsx +++ b/components/apolloTable/component/Cell.tsx @@ -56,6 +56,19 @@ const Cell = (props: CellProps) => { // useEffect(() => { // setStatus('detail'); // }, [cellData]); + const resetEditStatus = () => { + setStatus('detail'); + if (typeof onEmitMsg === 'function') { + onEmitMsg({ status: EDIT_STATUS.FREE }); + } + }; + + const turnIntoEditStatus = (data) => { + setStatus('edit'); + if (typeof onEmitMsg === 'function') { + onEmitMsg({ ...data, status: EDIT_STATUS.EDITING }); + } + }; const changeCellData = (changedValue: any, option?: any) => {}; const emitChangeCellData = (changedValue: any, optionValue: any) => { @@ -68,10 +81,7 @@ const Cell = (props: CellProps) => { } if (_.isEqual(temp, changedValue)) { - setStatus('detail'); - if (typeof onEmitMsg === 'function') { - onEmitMsg({ status: EDIT_STATUS.FREE }); - } + resetEditStatus(); return; } changeValue(changedValue, optionValue); @@ -82,14 +92,14 @@ const Cell = (props: CellProps) => { if (requiredFlag) { if (!changedValue || changedValue.length === 0) { message.error('该字段为必填项'); - setStatus('detail'); + resetEditStatus(); return; } if (changedValue.length === 1) { const data = changedValue[0]; if (!data.value && !data.text) { message.error('该字段为必填项'); - setStatus('detail'); + resetEditStatus(); return; } } @@ -110,10 +120,7 @@ const Cell = (props: CellProps) => { value: extraData, }); } - setStatus('detail'); - if (typeof onEmitMsg === 'function') { - onEmitMsg({ status: EDIT_STATUS.FREE }); - } + resetEditStatus(); }; // 添加行hover样式 const onMouseEnter = () => { @@ -246,10 +253,7 @@ const Cell = (props: CellProps) => { } if (selected) { // 当前已选中,则进入编辑状态 - setStatus('edit'); - if (typeof onEmitMsg === 'function') { - onEmitMsg({ rowId: record.id, columnCode: columnName, status: EDIT_STATUS.EDITING }); - } + turnIntoEditStatus({ rowId: record.id, columnCode: columnName }); if (dom) { // 给当前dom添加编辑状态 dom.setAttribute('data-editing-cell', '1'); @@ -366,7 +370,13 @@ const Cell = (props: CellProps) => { return (