提交 | 用户 | age
|
9c2f3f
|
1 |
import type { BasicColumn } from '/@/components/Table/src/types/table'; |
V |
2 |
|
|
3 |
import { h } from 'vue'; |
|
4 |
|
|
5 |
import EditableCell from './EditableCell.vue'; |
|
6 |
|
|
7 |
interface Params { |
|
8 |
text: string; |
|
9 |
record: Recordable; |
|
10 |
index: number; |
|
11 |
} |
|
12 |
|
|
13 |
export function renderEditCell(column: BasicColumn) { |
|
14 |
return ({ text: value, record, index }: Params) => { |
|
15 |
record.onEdit = async (edit: boolean, submit = false) => { |
|
16 |
if (!submit) { |
|
17 |
record.editable = edit; |
|
18 |
} |
|
19 |
|
|
20 |
if (!edit && submit) { |
|
21 |
const res = await record.onSubmitEdit?.(); |
|
22 |
if (res) { |
|
23 |
record.editable = false; |
|
24 |
return true; |
|
25 |
} |
|
26 |
return false; |
|
27 |
} |
|
28 |
// cancel |
|
29 |
if (!edit && !submit) { |
|
30 |
record.onCancelEdit?.(); |
|
31 |
} |
|
32 |
return true; |
|
33 |
}; |
|
34 |
|
|
35 |
return h(EditableCell, { |
|
36 |
value, |
|
37 |
record, |
|
38 |
column, |
|
39 |
index, |
|
40 |
}); |
|
41 |
}; |
|
42 |
} |
|
43 |
|
|
44 |
export type EditRecordRow<T = Hash<any>> = { |
|
45 |
onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>; |
|
46 |
editable: boolean; |
|
47 |
onCancel: Fn; |
|
48 |
onSubmit: Fn; |
|
49 |
submitCbs: Fn[]; |
|
50 |
cancelCbs: Fn[]; |
|
51 |
validCbs: Fn[]; |
|
52 |
} & T; |