|
|
@ -3,6 +3,7 @@ import type { BasicColumn } from '/@/components/Table/src/types/table'; |
|
|
import { h, Ref } from 'vue'; |
|
|
import { h, Ref } from 'vue'; |
|
|
|
|
|
|
|
|
import EditableCell from './EditableCell.vue'; |
|
|
import EditableCell from './EditableCell.vue'; |
|
|
|
|
|
import { isArray } from '/@/utils/is'; |
|
|
|
|
|
|
|
|
interface Params { |
|
|
interface Params { |
|
|
text: string; |
|
|
text: string; |
|
|
@ -12,12 +13,23 @@ interface Params { |
|
|
|
|
|
|
|
|
export function renderEditCell(column: BasicColumn) { |
|
|
export function renderEditCell(column: BasicColumn) { |
|
|
return ({ text: value, record, index }: Params) => { |
|
|
return ({ text: value, record, index }: Params) => { |
|
|
|
|
|
record.onValid = async () => { |
|
|
|
|
|
if (isArray(record?.validCbs)) { |
|
|
|
|
|
const validFns = (record?.validCbs || []).map((fn) => fn()); |
|
|
|
|
|
const res = await Promise.all(validFns); |
|
|
|
|
|
return res.every((item) => !!item); |
|
|
|
|
|
} else { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
record.onEdit = async (edit: boolean, submit = false) => { |
|
|
record.onEdit = async (edit: boolean, submit = false) => { |
|
|
if (!submit) { |
|
|
if (!submit) { |
|
|
record.editable = edit; |
|
|
record.editable = edit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!edit && submit) { |
|
|
if (!edit && submit) { |
|
|
|
|
|
if (!(await record.onValid())) return false; |
|
|
const res = await record.onSubmitEdit?.(); |
|
|
const res = await record.onSubmitEdit?.(); |
|
|
if (res) { |
|
|
if (res) { |
|
|
record.editable = false; |
|
|
record.editable = false; |
|
|
@ -44,6 +56,7 @@ export function renderEditCell(column: BasicColumn) { |
|
|
export type EditRecordRow<T = Recordable> = Partial< |
|
|
export type EditRecordRow<T = Recordable> = Partial< |
|
|
{ |
|
|
{ |
|
|
onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>; |
|
|
onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>; |
|
|
|
|
|
onValid: () => Promise<boolean>; |
|
|
editable: boolean; |
|
|
editable: boolean; |
|
|
onCancel: Fn; |
|
|
onCancel: Fn; |
|
|
onSubmit: Fn; |
|
|
onSubmit: Fn; |
|
|
|