From 4730b3af31d40fcd2dfe21c0d9faf08ef8420cfa Mon Sep 17 00:00:00 2001 From: Cyrus Zhou Date: Tue, 5 Jul 2022 05:43:34 +0200 Subject: [PATCH] =?UTF-8?q?Table=20BasicColumn=20=E6=B7=BB=E5=8A=A0=20edit?= =?UTF-8?q?DynamicDisabled=20(#2018)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Table BasicColumn 添加 editDynamicDisabled Co-authored-by: Cyrus Zhou <6802207@qq.com> 使用方式同 Form FormSchema dynamicDisabled ``` export const Columns: BasicColumn[] = [ { title: 'Title', dataIndex: 'Title', editRow: true, editComponent: 'Select', editDynamicDisabled: ({ record }) => record.isDisabled, }, * editComponentProps onChange 功能恢复 Co-authored-by: Cyrus Zhou <6802207@qq.com> 说明: ...omit(compProps, 'onChange') 这会忽略 onChange ,导致 editComponentProps onChange 被取消 如下功能将不支持: ``` editComponentProps: ({ record }) => { return { options: effectTypeData, onChange: () => { }, }; }, ``` * tableData == null 报错 * ApiSelect 第一次选择触发required错误提示问题 * 恢复 虽然可以解决第一次选择提示报错问题,但是会导致 onChange: (e: any, options: any) => 无法获得 options 的值 --- .../src/components/editable/EditableCell.vue | 25 ++++++++++++++++--- .../Table/src/hooks/useTableScroll.ts | 2 +- src/components/Table/src/types/table.ts | 2 ++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/components/Table/src/components/editable/EditableCell.vue b/src/components/Table/src/components/editable/EditableCell.vue index 5a4be7ea3..377822826 100644 --- a/src/components/Table/src/components/editable/EditableCell.vue +++ b/src/components/Table/src/components/editable/EditableCell.vue @@ -82,17 +82,36 @@ if (component === 'ApiSelect') { apiSelectProps.cache = true; } - + upEditDynamicDisabled(record, column, value); return { size: 'small', getPopupContainer: () => unref(table?.wrapRef.value) ?? document.body, placeholder: createPlaceholderMessage(unref(getComponent)), ...apiSelectProps, - ...omit(compProps, 'onChange'), + ...compProps, [valueField]: value, + disabled: unref(getDisable), } as any; }); - + function upEditDynamicDisabled(record, column, value) { + if (!record) return false; + const { key, dataIndex } = column; + if (!key && !dataIndex) return; + const dataKey = (dataIndex || key) as string; + set(record, dataKey, value); + } + const getDisable = computed(() => { + const { editDynamicDisabled } = props.column; + let disabled = false; + if (isBoolean(editDynamicDisabled)) { + disabled = editDynamicDisabled; + } + if (isFunction(editDynamicDisabled)) { + const { record } = props; + disabled = editDynamicDisabled({ record }); + } + return disabled; + }); const getValues = computed(() => { const { editValueMap } = props.column; diff --git a/src/components/Table/src/hooks/useTableScroll.ts b/src/components/Table/src/hooks/useTableScroll.ts index c1922ee67..803350b28 100644 --- a/src/components/Table/src/hooks/useTableScroll.ts +++ b/src/components/Table/src/hooks/useTableScroll.ts @@ -90,7 +90,7 @@ export function useTableScroll( bodyEl!.style.height = 'unset'; - if (!unref(getCanResize) || tableData.length === 0) return; + if (!unref(getCanResize) || !unref(tableData) || tableData.length === 0) return; await nextTick(); // Add a delay to get the correct bottomIncludeBody paginationHeight footerHeight headerHeight diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index 240b80d4f..ad1624976 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -463,6 +463,8 @@ export interface BasicColumn extends ColumnProps { column: BasicColumn; index: number; }) => VNodeChild | JSX.Element; + // 动态 Disabled + editDynamicDisabled?: boolean | ((record: Recordable) => boolean); } export type ColumnChangeParam = {