mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-29 21:50:02 +08:00
fix(editor): itemsFunction中补全value
feat(form): export createValues方法
This commit is contained in:
parent
d46d61184b
commit
e497ab0008
@ -17,11 +17,12 @@
|
|||||||
import { computed, defineEmits, defineProps, inject, watch } from 'vue';
|
import { computed, defineEmits, defineProps, inject, watch } from 'vue';
|
||||||
import { isEmpty, map } from 'lodash-es';
|
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 { HookType, Id } from '@tmagic/schema';
|
||||||
|
|
||||||
import { CodeParamStatement, HookData, Services } from '../type';
|
import { CodeParamStatement, HookData, Services } from '../type';
|
||||||
const services = inject<Services>('services');
|
const services = inject<Services>('services');
|
||||||
|
const mForm = inject<FormState>('mForm');
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@ -65,7 +66,14 @@ const tableConfig = computed<FormItem>(() => {
|
|||||||
name: 'params',
|
name: 'params',
|
||||||
label: '参数',
|
label: '参数',
|
||||||
defaultValue: {},
|
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;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -62,9 +62,9 @@ const initItemsValue = (
|
|||||||
{ items, name, extensible }: any,
|
{ items, name, extensible }: any,
|
||||||
) => {
|
) => {
|
||||||
if (Array.isArray(initValue[name])) {
|
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 {
|
} else {
|
||||||
value[name] = init(mForm, items, initValue[name], value[name]);
|
value[name] = createValues(mForm, items, initValue[name], value[name]);
|
||||||
if (extensible) {
|
if (extensible) {
|
||||||
value[name] = Object.assign({}, initValue[name], value[name]);
|
value[name] = Object.assign({}, initValue[name], value[name]);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ const initValueItem = function (
|
|||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
// 没有配置name,直接跳过
|
// 没有配置name,直接跳过
|
||||||
return init(mForm, items, initValue, value);
|
return createValues(mForm, items, initValue, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(mForm, value, initValue, item);
|
setValue(mForm, value, initValue, item);
|
||||||
@ -137,7 +137,7 @@ const initValueItem = function (
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = function (
|
export const createValues = function (
|
||||||
mForm: FormState | undefined,
|
mForm: FormState | undefined,
|
||||||
config: FormConfig | TabPaneConfig[] = [],
|
config: FormConfig | TabPaneConfig[] = [],
|
||||||
initValue: FormValue = {},
|
initValue: FormValue = {},
|
||||||
@ -253,7 +253,7 @@ export const initValue = async (
|
|||||||
) => {
|
) => {
|
||||||
if (!Array.isArray(config)) throw new Error('config应该为数组');
|
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];
|
const [firstForm] = config as [ContainerCommonConfig];
|
||||||
if (firstForm && typeof firstForm.onInitValue === 'function') {
|
if (firstForm && typeof firstForm.onInitValue === 'function') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user