fix(form): 函数配置中添加config参数

This commit is contained in:
roymondchen 2022-06-15 19:34:41 +08:00 committed by jia000
parent 7c5c4cb4ae
commit eae9725ccb
5 changed files with 25 additions and 3 deletions

View File

@ -217,6 +217,7 @@ export default defineComponent({
values: mForm?.initValues, values: mForm?.initValues,
formValue: mForm?.values, formValue: mForm?.values,
prop: itemProp.value, prop: itemProp.value,
config: props.config,
}); });
} }
@ -234,6 +235,7 @@ export default defineComponent({
values: mForm?.initValues, values: mForm?.initValues,
formValue: mForm?.values, formValue: mForm?.values,
prop: itemProp.value, prop: itemProp.value,
config: props.config,
}); });
} }
}; };

View File

@ -136,7 +136,11 @@ const Tab = defineComponent({
if (!props.config.name) throw new Error('dynamic tab 必须配置name'); if (!props.config.name) throw new Error('dynamic tab 必须配置name');
if (typeof props.config.onTabAdd === 'function') { if (typeof props.config.onTabAdd === 'function') {
props.config.onTabAdd(mForm, { model: props.model }); props.config.onTabAdd(mForm, {
model: props.model,
prop: props.prop,
config: props.config,
});
} else if (tabs.value.length > 0) { } else if (tabs.value.length > 0) {
const newObj = cloneDeep(tabs.value[0]); const newObj = cloneDeep(tabs.value[0]);
newObj.title = `标签${tabs.value.length + 1}`; newObj.title = `标签${tabs.value.length + 1}`;
@ -150,7 +154,11 @@ const Tab = defineComponent({
if (!props.config.name) throw new Error('dynamic tab 必须配置name'); if (!props.config.name) throw new Error('dynamic tab 必须配置name');
if (typeof props.config.onTabRemove === 'function') { if (typeof props.config.onTabRemove === 'function') {
props.config.onTabRemove(mForm, tabName, { model: props.model }); props.config.onTabRemove(mForm, tabName, {
model: props.model,
prop: props.prop,
config: props.config,
});
} else { } else {
props.model[props.config.name].splice(+tabName, 1); props.model[props.config.name].splice(+tabName, 1);
@ -169,7 +177,7 @@ const Tab = defineComponent({
changeHandler: () => { changeHandler: () => {
emit('change', props.model); emit('change', props.model);
if (typeof props.config.onChange === 'function') { if (typeof props.config.onChange === 'function') {
props.config.onChange(mForm, { model: props.model }); props.config.onChange(mForm, { model: props.model, prop: props.prop, config: props.config });
} }
}, },
}; };

View File

@ -134,6 +134,7 @@ export default defineComponent({
model: props.model, model: props.model,
formValue: mForm?.values, formValue: mForm?.values,
formValues: mForm?.values, formValues: mForm?.values,
config: props.config,
}) as Record<string, any>; }) as Record<string, any>;
} }
@ -163,6 +164,7 @@ export default defineComponent({
model: props.model, model: props.model,
formValue: mForm?.values, formValue: mForm?.values,
formValues: mForm?.values, formValues: mForm?.values,
config: props.config,
}); });
} }
@ -287,6 +289,7 @@ export default defineComponent({
prop: props.prop, prop: props.prop,
formValues: mForm?.values, formValues: mForm?.values,
formValue: mForm?.values, formValue: mForm?.values,
config: props.config,
}), }),
).then((data) => { ).then((data) => {
options.value = data; options.value = data;

View File

@ -120,6 +120,7 @@ export interface Rule {
/** 整个表单的值 */ /** 整个表单的值 */
formValue: FormValue; formValue: FormValue;
prop: string; prop: string;
config: any;
}, },
mForm: FormState | undefined, mForm: FormState | undefined,
) => void; ) => void;
@ -145,6 +146,7 @@ type FilterFunction = (
parent?: Record<any, any>; parent?: Record<any, any>;
formValue: Record<any, any>; formValue: Record<any, any>;
prop: string; prop: string;
config: any;
}, },
) => boolean; ) => boolean;
@ -156,6 +158,7 @@ type OnChangeHandler = (
values: Record<any, any>; values: Record<any, any>;
parent?: Record<any, any>; parent?: Record<any, any>;
formValue: Record<any, any>; formValue: Record<any, any>;
config: any;
}, },
) => any; ) => any;
@ -191,6 +194,7 @@ type SelectOptionFunction = (
prop?: string; prop?: string;
formValues: any; formValues: any;
formValue: any; formValue: any;
config: any;
}, },
) => SelectOption[] | SelectGroupOption[]; ) => SelectOption[] | SelectGroupOption[];
@ -200,6 +204,7 @@ type RemoteSelectOptionBodyFunction = (
model: any; model: any;
formValue: any; formValue: any;
formValues: any; formValues: any;
config: any;
}, },
) => Record<string, any>; ) => Record<string, any>;
@ -210,6 +215,7 @@ type RemoteSelectOptionRequestFunction = (
model: any; model: any;
formValue: any; formValue: any;
formValues: any; formValues: any;
config: any;
}, },
) => any; ) => any;
@ -500,6 +506,7 @@ export interface TabPaneConfig {
lazy?: boolean; lazy?: boolean;
labelWidth?: string; labelWidth?: string;
items: FormConfig; items: FormConfig;
[key: string]: any;
} }
export interface TabConfig extends FormItem, ContainerCommonConfig { export interface TabConfig extends FormItem, ContainerCommonConfig {
type: 'tab' | 'dynamic-tab'; type: 'tab' | 'dynamic-tab';

View File

@ -201,6 +201,7 @@ export const filterFunction = (mForm: FormState | undefined, config: any, props:
parent: mForm?.parentValues || {}, parent: mForm?.parentValues || {},
formValue: mForm?.values || props.model, formValue: mForm?.values || props.model,
prop: props.prop, prop: props.prop,
config: props.config,
}); });
}; };
@ -242,6 +243,7 @@ export const getRules = function (mForm: FormState | undefined, rules: Rule[] |
parent: mForm?.parentValues || {}, parent: mForm?.parentValues || {},
formValue: mForm?.values || props.model, formValue: mForm?.values || props.model,
prop: props.prop, prop: props.prop,
config: props.config,
}, },
mForm, mForm,
); );