mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-26 12:48:48 +08:00
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:
parent
740d160198
commit
4730b3af31
@ -82,17 +82,36 @@
|
|||||||
if (component === 'ApiSelect') {
|
if (component === 'ApiSelect') {
|
||||||
apiSelectProps.cache = true;
|
apiSelectProps.cache = true;
|
||||||
}
|
}
|
||||||
|
upEditDynamicDisabled(record, column, value);
|
||||||
return {
|
return {
|
||||||
size: 'small',
|
size: 'small',
|
||||||
getPopupContainer: () => unref(table?.wrapRef.value) ?? document.body,
|
getPopupContainer: () => unref(table?.wrapRef.value) ?? document.body,
|
||||||
placeholder: createPlaceholderMessage(unref(getComponent)),
|
placeholder: createPlaceholderMessage(unref(getComponent)),
|
||||||
...apiSelectProps,
|
...apiSelectProps,
|
||||||
...omit(compProps, 'onChange'),
|
...compProps,
|
||||||
[valueField]: value,
|
[valueField]: value,
|
||||||
|
disabled: unref(getDisable),
|
||||||
} as any;
|
} 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 getValues = computed(() => {
|
||||||
const { editValueMap } = props.column;
|
const { editValueMap } = props.column;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ export function useTableScroll(
|
|||||||
|
|
||||||
bodyEl!.style.height = 'unset';
|
bodyEl!.style.height = 'unset';
|
||||||
|
|
||||||
if (!unref(getCanResize) || tableData.length === 0) return;
|
if (!unref(getCanResize) || !unref(tableData) || tableData.length === 0) return;
|
||||||
|
|
||||||
await nextTick();
|
await nextTick();
|
||||||
// Add a delay to get the correct bottomIncludeBody paginationHeight footerHeight headerHeight
|
// Add a delay to get the correct bottomIncludeBody paginationHeight footerHeight headerHeight
|
||||||
|
@ -463,6 +463,8 @@ export interface BasicColumn extends ColumnProps<Recordable> {
|
|||||||
column: BasicColumn;
|
column: BasicColumn;
|
||||||
index: number;
|
index: number;
|
||||||
}) => VNodeChild | JSX.Element;
|
}) => VNodeChild | JSX.Element;
|
||||||
|
// 动态 Disabled
|
||||||
|
editDynamicDisabled?: boolean | ((record: Recordable) => boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ColumnChangeParam = {
|
export type ColumnChangeParam = {
|
||||||
|
Loading…
Reference in New Issue
Block a user