From 404a4720b016abb6da93cb0b03271ebea6cca976 Mon Sep 17 00:00:00 2001
From: xachary <179740385@qq.com>
Date: Fri, 15 Dec 2023 16:12:43 +0800
Subject: [PATCH] fix: EditableCell about checked/unChecked Value, getDisable,
rowKey missing for updating (#3418). resolve #3419
---
.../src/components/editable/EditableCell.vue | 30 ++++++++++++++-----
src/components/Table/src/types/table.ts | 1 +
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/components/Table/src/components/editable/EditableCell.vue b/src/components/Table/src/components/editable/EditableCell.vue
index 72bca4b6d..62fa6bb43 100644
--- a/src/components/Table/src/components/editable/EditableCell.vue
+++ b/src/components/Table/src/components/editable/EditableCell.vue
@@ -66,13 +66,23 @@
const getComponentProps = computed(() => {
const isCheckValue = unref(getIsCheckComp);
+ let compProps = props.column?.editComponentProps ?? ({} as any);
+ const { checkedValue, unCheckedValue } = compProps;
const valueField = isCheckValue ? 'checked' : 'value';
const val = unref(currentValueRef);
- const value = isCheckValue ? (isNumber(val) || isBoolean(val) ? val : !!val) : val;
+ let value = val;
+ if (isCheckValue) {
+ if (typeof checkedValue !== 'undefined') {
+ value = val === checkedValue ? checkedValue : unCheckedValue;
+ } else if (typeof unCheckedValue !== 'undefined') {
+ value = val === unCheckedValue ? unCheckedValue : checkedValue;
+ } else {
+ value = isNumber(val) || isBoolean(val) ? val : !!val;
+ }
+ }
- let compProps = props.column?.editComponentProps ?? ({} as any);
const { record, column, index } = props;
if (isFunction(compProps)) {
@@ -114,7 +124,7 @@
}
if (isFunction(editDynamicDisabled)) {
const { record } = props;
- disabled = editDynamicDisabled({ record });
+ disabled = editDynamicDisabled({ record, currentValue: currentValueRef.value });
}
return disabled;
});
@@ -170,7 +180,7 @@
});
function handleEdit() {
- if (unref(getRowEditable) || unref(props.column?.editRow)) return;
+ if (unref(getRowEditable) || unref(props.column?.editRow) || unref(getDisable)) return;
ruleMessage.value = '';
isEdit.value = true;
nextTick(() => {
@@ -248,17 +258,19 @@
if (!record.editable) {
const { getBindValues } = table;
- const { beforeEditSubmit, columns } = unref(getBindValues);
+ const { beforeEditSubmit, columns, rowKey } = unref(getBindValues);
+ const rowKeyValue = typeof rowKey === 'string' ? rowKey : rowKey ? rowKey(record) : '';
if (beforeEditSubmit && isFunction(beforeEditSubmit)) {
spinning.value = true;
const keys: string[] = columns
.map((_column) => _column.dataIndex)
.filter((field) => !!field) as string[];
+
let result: any = true;
try {
result = await beforeEditSubmit({
- record: pick(record, keys),
+ record: pick(record, [rowKeyValue, ...keys]),
index,
key: dataKey as string,
value,
@@ -391,6 +403,7 @@
handleEnter,
handleSubmitClick,
spinning,
+ getDisable,
};
},
render() {
@@ -408,10 +421,13 @@
record: this.record as Recordable,
column: this.column,
index: this.index,
+ currentValue: this.currentValueRef,
})
: this.getValues ?? '\u00A0'}
- {!this.column.editRow && }
+ {!this.column.editRow && !this.getDisable && (
+
+ )}
{this.isEdit && (
diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts
index a53370af7..9a8ae9d42 100644
--- a/src/components/Table/src/types/table.ts
+++ b/src/components/Table/src/types/table.ts
@@ -472,6 +472,7 @@ export interface BasicColumn extends ColumnProps {
record: Recordable;
column: BasicColumn;
index: number;
+ currentValue: string | number | boolean | Recordable;
}) => VNodeChild | JSX.Element;
// 动态 Disabled
editDynamicDisabled?: boolean | ((record: Recordable) => boolean);