提交 | 用户 | 时间
|
314507
|
1 |
import { FormSchema } from '@/types/form' |
H |
2 |
import { ElCheckbox, ElCheckboxButton } from 'element-plus' |
|
3 |
import { defineComponent } from 'vue' |
|
4 |
|
|
5 |
export const useRenderCheckbox = () => { |
|
6 |
const renderCheckboxOptions = (item: FormSchema) => { |
|
7 |
// 如果有别名,就取别名 |
|
8 |
const labelAlias = item?.componentProps?.optionsAlias?.labelField |
|
9 |
const valueAlias = item?.componentProps?.optionsAlias?.valueField |
|
10 |
const Com = (item.component === 'Checkbox' ? ElCheckbox : ElCheckboxButton) as ReturnType< |
|
11 |
typeof defineComponent |
|
12 |
> |
|
13 |
return item?.componentProps?.options?.map((option) => { |
|
14 |
const { ...other } = option |
|
15 |
return ( |
|
16 |
<Com {...other} label={option[valueAlias || 'value']}> |
|
17 |
{option[labelAlias || 'label']} |
|
18 |
</Com> |
|
19 |
) |
|
20 |
}) |
|
21 |
} |
|
22 |
|
|
23 |
return { |
|
24 |
renderCheckboxOptions |
|
25 |
} |
|
26 |
} |