Skip to content

Commit

Permalink
fix: EditableCell about checked/unChecked Value, getDisable, rowKey m…
Browse files Browse the repository at this point in the history
…issing for updating (vbenjs#3418). resolve vbenjs#3419
  • Loading branch information
xachary authored and WitMiao committed Dec 17, 2023
1 parent 5806e85 commit 0a3bcf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/components/Table/src/components/editable/EditableCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -114,7 +124,7 @@
}
if (isFunction(editDynamicDisabled)) {
const { record } = props;
disabled = editDynamicDisabled({ record });
disabled = editDynamicDisabled({ record, currentValue: currentValueRef.value });
}
return disabled;
});
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -391,6 +403,7 @@
handleEnter,
handleSubmitClick,
spinning,
getDisable,
};
},
render() {
Expand All @@ -408,10 +421,13 @@
record: this.record as Recordable,
column: this.column,
index: this.index,
currentValue: this.currentValueRef,
})
: this.getValues ?? '\u00A0'}
</div>
{!this.column.editRow && <FormOutlined class={`${this.prefixCls}__normal-icon`} />}
{!this.column.editRow && !this.getDisable && (
<FormOutlined class={`${this.prefixCls}__normal-icon`} />
)}
</div>
{this.isEdit && (
<Spin spinning={this.spinning}>
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export interface BasicColumn extends ColumnProps<Recordable> {
record: Recordable;
column: BasicColumn;
index: number;
currentValue: string | number | boolean | Recordable;
}) => VNodeChild | JSX.Element;
// 动态 Disabled
editDynamicDisabled?: boolean | ((record: Recordable) => boolean);
Expand Down

0 comments on commit 0a3bcf1

Please sign in to comment.