From d183fc5274306b157e0a69c0e3c5052fbc168036 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Thu, 25 Apr 2024 16:29:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90issues/1165=E3=80=91=E8=A7=A3=E5=86=B3?= =?UTF-8?q?canResize=E4=B8=BAtrue=E6=97=B6=E7=AC=AC=E4=B8=80=E8=A1=8C?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=B8=8D=E8=BF=87=20---?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/editable/EditableCell.vue | 30 +++++++++++++++++-- .../Table/src/components/editable/index.ts | 18 ++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/components/Table/src/components/editable/EditableCell.vue b/src/components/Table/src/components/editable/EditableCell.vue index d334c25..023785d 100644 --- a/src/components/Table/src/components/editable/EditableCell.vue +++ b/src/components/Table/src/components/editable/EditableCell.vue @@ -336,7 +336,20 @@ function initCbs(cbs: 'submitCbs' | 'validCbs' | 'cancelCbs', handle: Fn) { if (props.record) { /* eslint-disable */ - isArray(props.record[cbs]) ? props.record[cbs]?.push(handle) : (props.record[cbs] = [handle]); + // update-begin--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 + const { dataIndex, key } = props.column; + const field: any = dataIndex || key; + if (isArray(props.record[cbs])) { + const findItem = props.record[cbs]?.find((item) => item[field]); + if (findItem) { + findItem[field] = handle; + } else { + props.record[cbs]?.push({ [field]: handle }); + } + } else { + props.record[cbs] = [{ [field]: handle }]; + } + // update-end--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 } } @@ -351,14 +364,25 @@ } /* eslint-disable */ props.record.onCancelEdit = () => { - isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn()); + // update-begin--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 + isArray(props.record?.cancelCbs) && + props.record?.cancelCbs.forEach((item) => { + const [fn] = Object.values(item); + fn(); + }); + // update-end--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 }; /* eslint-disable */ props.record.onSubmitEdit = async () => { if (isArray(props.record?.submitCbs)) { if (!props.record?.onValid?.()) return; const submitFns = props.record?.submitCbs || []; - submitFns.forEach((fn) => fn(false, false)); + // update-begin--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 + submitFns.forEach((item) => { + const [fn] = Object.values(item); + fn(false, false); + }); + // update-end--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 table.emit?.('edit-row-end'); return true; } diff --git a/src/components/Table/src/components/editable/index.ts b/src/components/Table/src/components/editable/index.ts index 548c9e4..4191473 100644 --- a/src/components/Table/src/components/editable/index.ts +++ b/src/components/Table/src/components/editable/index.ts @@ -15,7 +15,13 @@ export function renderEditCell(column: BasicColumn) { return ({ text: value, record, index }: Params) => { toRaw(record).onValid = async () => { if (isArray(record?.validCbs)) { - const validFns = (record?.validCbs || []).map((fn) => fn()); + // update-begin--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 + const validFns = (record?.validCbs || []).map((item) => { + const [fn] = Object.values(item); + // @ts-ignore + return fn(); + }); + // update-end--author:liaozhiyang---date:20240424---for:【issues/1165】解决canResize为true时第一行校验不过 const res = await Promise.all(validFns); return res.every((item) => !!item); } else { @@ -53,6 +59,10 @@ export function renderEditCell(column: BasicColumn) { }; } +interface Cbs { + [key: string]: Fn; +} + export type EditRecordRow<T = Recordable> = Partial< { onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>; @@ -60,9 +70,9 @@ export type EditRecordRow<T = Recordable> = Partial< editable: boolean; onCancel: Fn; onSubmit: Fn; - submitCbs: Fn[]; - cancelCbs: Fn[]; - validCbs: Fn[]; + submitCbs: Cbs[]; + cancelCbs: Cbs[]; + validCbs: Cbs[]; editValueRefs: Recordable<Ref>; } & T >;