mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-20 12:49:19 +08:00
feat(form): checkboxGroup options支持函数配置
This commit is contained in:
parent
32a24ad578
commit
6d432ba1da
@ -1,20 +1,19 @@
|
||||
<template>
|
||||
<TMagicCheckboxGroup v-model="model[name]" :size="size" :disabled="disabled" @change="changeHandler">
|
||||
<TMagicCheckbox
|
||||
v-for="option in config.options"
|
||||
:label="option.value"
|
||||
:key="option.value"
|
||||
:disabled="option.disabled"
|
||||
<TMagicCheckbox v-for="option in options" :label="option.value" :key="option.value" :disabled="option.disabled"
|
||||
>{{ option.text }}
|
||||
</TMagicCheckbox>
|
||||
</TMagicCheckboxGroup>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, inject } from 'vue';
|
||||
|
||||
import { TMagicCheckbox, TMagicCheckboxGroup } from '@tmagic/design';
|
||||
|
||||
import { CheckboxGroupConfig } from '../schema';
|
||||
import { CheckboxGroupConfig, FormState } from '../schema';
|
||||
import { useAddField } from '../utils/useAddField';
|
||||
import { filterFunction } from '..';
|
||||
|
||||
const props = defineProps<{
|
||||
config: CheckboxGroupConfig;
|
||||
@ -39,4 +38,11 @@ if (props.model && !props.model[props.name]) {
|
||||
const changeHandler = (v: Array<string | number | boolean>) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
const options = computed(() => {
|
||||
if (Array.isArray(props.config.options)) return props.config.options;
|
||||
if (typeof props.config.options === 'function') return filterFunction(mForm, props.config.options, props);
|
||||
return [];
|
||||
});
|
||||
</script>
|
||||
|
@ -408,11 +408,13 @@ export interface ColorPickConfig extends FormItem {
|
||||
*/
|
||||
export interface CheckboxGroupConfig extends FormItem {
|
||||
type: 'checkbox-group';
|
||||
options: {
|
||||
value: any;
|
||||
text: string;
|
||||
disabled?: boolean;
|
||||
}[];
|
||||
options:
|
||||
| {
|
||||
value: any;
|
||||
text: string;
|
||||
disabled?: boolean;
|
||||
}[]
|
||||
| Function;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user