fix(editor): itemsFunction中补全value

feat(form): export createValues方法
This commit is contained in:
parisma 2022-11-24 17:08:58 +08:00 committed by roymondchen
parent d46d61184b
commit e497ab0008
2 changed files with 15 additions and 7 deletions

View File

@ -17,11 +17,12 @@
import { computed, defineEmits, defineProps, inject, watch } from 'vue';
import { isEmpty, map } from 'lodash-es';
import { FormItem, TableConfig } from '@tmagic/form';
import { createValues, FormItem, FormState, TableConfig } from '@tmagic/form';
import { HookType, Id } from '@tmagic/schema';
import { CodeParamStatement, HookData, Services } from '../type';
const services = inject<Services>('services');
const mForm = inject<FormState>('mForm');
const emit = defineEmits(['change']);
const props = defineProps<{
@ -65,7 +66,14 @@ const tableConfig = computed<FormItem>(() => {
name: 'params',
label: '参数',
defaultValue: {},
itemsFunction: (row: HookData) => getParamsConfig(row.codeId),
itemsFunction: (row: HookData) => {
const paramsConfig = getParamsConfig(row.codeId);
if (!row.params) row.params = {};
if (isEmpty(row.params)) {
createValues(mForm, paramsConfig, {}, row.params);
}
return paramsConfig;
},
},
],
};

View File

@ -62,9 +62,9 @@ const initItemsValue = (
{ items, name, extensible }: any,
) => {
if (Array.isArray(initValue[name])) {
value[name] = initValue[name].map((v: any, index: number) => init(mForm, items, v, value[name]?.[index]));
value[name] = initValue[name].map((v: any, index: number) => createValues(mForm, items, v, value[name]?.[index]));
} else {
value[name] = init(mForm, items, initValue[name], value[name]);
value[name] = createValues(mForm, items, initValue[name], value[name]);
if (extensible) {
value[name] = Object.assign({}, initValue[name], value[name]);
}
@ -129,7 +129,7 @@ const initValueItem = function (
if (!name) {
// 没有配置name直接跳过
return init(mForm, items, initValue, value);
return createValues(mForm, items, initValue, value);
}
setValue(mForm, value, initValue, item);
@ -137,7 +137,7 @@ const initValueItem = function (
return value;
};
const init = function (
export const createValues = function (
mForm: FormState | undefined,
config: FormConfig | TabPaneConfig[] = [],
initValue: FormValue = {},
@ -253,7 +253,7 @@ export const initValue = async (
) => {
if (!Array.isArray(config)) throw new Error('config应该为数组');
let valuesTmp = init(mForm, config, toRaw(initValues), {});
let valuesTmp = createValues(mForm, config, toRaw(initValues), {});
const [firstForm] = config as [ContainerCommonConfig];
if (firstForm && typeof firstForm.onInitValue === 'function') {