Table BasicColumn 添加 editDynamicDisabled (#2018)

* 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 的值
This commit is contained in:
Cyrus Zhou 2022-07-05 05:43:34 +02:00 committed by GitHub
parent 740d160198
commit 4730b3af31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

View File

@ -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;

View File

@ -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

View File

@ -463,6 +463,8 @@ export interface BasicColumn extends ColumnProps<Recordable> {
column: BasicColumn;
index: number;
}) => VNodeChild | JSX.Element;
// 动态 Disabled
editDynamicDisabled?: boolean | ((record: Recordable) => boolean);
}
export type ColumnChangeParam = {