feat(dats-source,editor,form,schema,ui): 迭代器容器支持配置子项显示条件
This commit is contained in:
@@ -49,7 +49,7 @@ const options = ref<CascaderOption[]>([]);
|
||||
const remoteData = ref<any>(null);
|
||||
|
||||
const checkStrictly = computed(() => filterFunction(mForm, props.config.checkStrictly, props));
|
||||
const valueSeparator = computed(() => filterFunction(mForm, props.config.valueSeparator, props));
|
||||
const valueSeparator = computed(() => filterFunction<string>(mForm, props.config.valueSeparator, props));
|
||||
|
||||
const value = computed({
|
||||
get() {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { computed, inject } from 'vue';
|
||||
|
||||
import { TMagicCheckbox, TMagicCheckboxGroup } from '@tmagic/design';
|
||||
|
||||
import type { CheckboxGroupConfig, FieldProps, FormState } from '../schema';
|
||||
import type { CheckboxGroupConfig, CheckboxGroupOption, FieldProps, FormState } from '../schema';
|
||||
import { filterFunction } from '../utils/form';
|
||||
import { useAddField } from '../utils/useAddField';
|
||||
|
||||
@@ -37,7 +37,8 @@ const changeHandler = (v: Array<string | number | boolean>) => {
|
||||
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);
|
||||
if (typeof props.config.options === 'function')
|
||||
return filterFunction<CheckboxGroupOption[]>(mForm, props.config.options, props) || [];
|
||||
return [];
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -170,6 +170,7 @@ export type FilterFunction<T = boolean> = (
|
||||
formValue: Record<any, any>;
|
||||
prop: string;
|
||||
config: any;
|
||||
index?: number;
|
||||
},
|
||||
) => T;
|
||||
|
||||
@@ -433,18 +434,18 @@ export interface ColorPickConfig extends FormItem {
|
||||
type: 'colorPicker';
|
||||
}
|
||||
|
||||
export interface CheckboxGroupOption {
|
||||
value: any;
|
||||
text: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多选框组
|
||||
*/
|
||||
export interface CheckboxGroupConfig extends FormItem {
|
||||
type: 'checkbox-group';
|
||||
options:
|
||||
| {
|
||||
value: any;
|
||||
text: string;
|
||||
disabled?: boolean;
|
||||
}[]
|
||||
| Function;
|
||||
options: CheckboxGroupOption[] | FilterFunction<CheckboxGroupOption[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
ChildConfig,
|
||||
ContainerCommonConfig,
|
||||
DaterangeConfig,
|
||||
FilterFunction,
|
||||
FormConfig,
|
||||
FormState,
|
||||
FormValue,
|
||||
@@ -181,20 +182,24 @@ const getDefaultValue = function (mForm: FormState | undefined, { defaultValue,
|
||||
return '';
|
||||
};
|
||||
|
||||
export const filterFunction = <T = any>(mForm: FormState | undefined, config: T, props: any) => {
|
||||
if (typeof config !== 'function') {
|
||||
return config;
|
||||
export const filterFunction = <T = any>(
|
||||
mForm: FormState | undefined,
|
||||
config: T | FilterFunction<T> | undefined,
|
||||
props: any,
|
||||
) => {
|
||||
if (typeof config === 'function') {
|
||||
return (config as FilterFunction<T>)(mForm, {
|
||||
values: mForm?.initValues || {},
|
||||
model: props.model,
|
||||
parent: mForm?.parentValues || {},
|
||||
formValue: mForm?.values || props.model,
|
||||
prop: props.prop,
|
||||
config: props.config,
|
||||
index: props.index,
|
||||
});
|
||||
}
|
||||
|
||||
return config(mForm, {
|
||||
values: mForm?.initValues || {},
|
||||
model: props.model,
|
||||
parent: mForm?.parentValues || {},
|
||||
formValue: mForm?.values || props.model,
|
||||
prop: props.prop,
|
||||
config: props.config,
|
||||
index: props.index,
|
||||
});
|
||||
return config;
|
||||
};
|
||||
|
||||
export const display = function (mForm: FormState | undefined, config: any, props: any) {
|
||||
|
||||
Reference in New Issue
Block a user