fix(table): fix unsuccessful saving of row edit table (#117)

Co-authored-by: heresy <Heresy@chxian.com>
This commit is contained in:
Heresy 2020-12-07 22:37:33 +08:00 committed by GitHub
parent 59ad82442b
commit 404db2fb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ import { RenderEditableCellParams } from '../types/table';
import { ComponentType } from '../types/componentType';
import { componentMap } from '../componentMap';
import { isString, isBoolean } from '/@/utils/is';
import { isString, isBoolean, isArray } from '/@/utils/is';
import { FormOutlined, CloseOutlined, CheckOutlined } from '@ant-design/icons-vue';
const prefixCls = 'editable-cell';
@ -50,6 +50,7 @@ const EditableCell = defineComponent({
},
placeholder: {
type: String as PropType<string>,
default: '',
},
},
emits: ['submit', 'cancel'],
@ -92,9 +93,22 @@ const EditableCell = defineComponent({
if (props.record) {
/* eslint-disable */
props.record.onCancel = handleCancel;
isArray(props.record.submitCbs)
? props.record.submitCbs.push(handleSubmit)
: (props.record.submitCbs = [handleSubmit]);
/* eslint-disable */
isArray(props.record.cancelCbs)
? props.record.cancelCbs.push(handleCancel)
: (props.record.cancelCbs = [handleCancel]);
/* eslint-disable */
props.record.onCancel = () => {
isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn());
};
/* eslint-disable */
props.record.onSubmit = handleSubmit;
props.record.onSubmit = () => {
isArray(props.record?.submitCbs) && props.record?.submitCbs.forEach((fn) => fn());
};
}
function handleSubmit() {
@ -222,4 +236,6 @@ export type EditRecordRow<T = { [key: string]: any }> = {
editable: boolean;
onCancel: Fn;
onSubmit: Fn;
submitCbs: Fn[];
cancelCbs: Fn[];
} & T;