mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-12-12 11:22:56 +00:00
feat(form): text组件配置的append.hander函数添加setModel/setFormValue方法
This commit is contained in:
parent
4f52fcb122
commit
6f0498a9e7
@ -15,14 +15,14 @@ export interface ChangeRecord {
|
|||||||
|
|
||||||
export interface OnChangeHandlerData {
|
export interface OnChangeHandlerData {
|
||||||
model: FormValue;
|
model: FormValue;
|
||||||
values?: Readonly<FormValue>;
|
values?: Readonly<FormValue> | null;
|
||||||
parent?: FormValue;
|
parent?: FormValue;
|
||||||
formValue?: FormValue;
|
formValue?: FormValue;
|
||||||
config: Readonly<any>;
|
config: Readonly<any>;
|
||||||
prop: string;
|
prop: string;
|
||||||
changeRecords: ChangeRecord[];
|
changeRecords: ChangeRecord[];
|
||||||
setModel: (prop: string, value: any) => void;
|
setModel: (prop: string, value: any) => void;
|
||||||
setFromValue: (prop: string, value: any) => void;
|
setFormValue: (prop: string, value: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FormValue = Record<string | number, any>;
|
export type FormValue = Record<string | number, any>;
|
||||||
@ -361,7 +361,10 @@ export interface TextConfig extends FormItem, Input {
|
|||||||
mForm: FormState | undefined,
|
mForm: FormState | undefined,
|
||||||
data: {
|
data: {
|
||||||
model: any;
|
model: any;
|
||||||
values: any;
|
values?: Readonly<FormValue> | null;
|
||||||
|
formValue?: FormValue;
|
||||||
|
setModel: (prop: string, value: any) => void;
|
||||||
|
setFormValue: (prop: string, value: any) => void;
|
||||||
},
|
},
|
||||||
) => void;
|
) => void;
|
||||||
};
|
};
|
||||||
@ -553,7 +556,8 @@ export interface LinkConfig extends FormItem {
|
|||||||
mForm: FormState | undefined,
|
mForm: FormState | undefined,
|
||||||
data: {
|
data: {
|
||||||
model: Record<any, any>;
|
model: Record<any, any>;
|
||||||
values: Record<any, any>;
|
values?: Readonly<FormValue> | null;
|
||||||
|
formValue?: FormValue;
|
||||||
},
|
},
|
||||||
) => FormConfig);
|
) => FormConfig);
|
||||||
fullscreen?: boolean;
|
fullscreen?: boolean;
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, ref } from 'vue';
|
import { computed, inject, readonly, ref } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton } from '@tmagic/design';
|
import { TMagicButton } from '@tmagic/design';
|
||||||
|
|
||||||
@ -54,7 +54,8 @@ const formConfig = computed(() => {
|
|||||||
if (typeof props.config.form === 'function') {
|
if (typeof props.config.form === 'function') {
|
||||||
return props.config.form(mForm, {
|
return props.config.form(mForm, {
|
||||||
model: props.model || {},
|
model: props.model || {},
|
||||||
values: props.values || {},
|
values: mForm ? readonly(mForm.initValues) : null,
|
||||||
|
formValue: props.values || {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return props.config.form;
|
return props.config.form;
|
||||||
|
|||||||
@ -41,7 +41,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, ref, shallowRef, watch } from 'vue';
|
import { computed, inject, readonly, ref, shallowRef, watch } from 'vue';
|
||||||
import type { Instance } from '@popperjs/core';
|
import type { Instance } from '@popperjs/core';
|
||||||
import { createPopper } from '@popperjs/core';
|
import { createPopper } from '@popperjs/core';
|
||||||
import { debounce } from 'lodash-es';
|
import { debounce } from 'lodash-es';
|
||||||
@ -49,7 +49,7 @@ import { debounce } from 'lodash-es';
|
|||||||
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
||||||
import { isNumber } from '@tmagic/utils';
|
import { isNumber } from '@tmagic/utils';
|
||||||
|
|
||||||
import type { FieldProps, FormState, TextConfig } from '../schema';
|
import type { ChangeRecord, ContainerChangeEventData, FieldProps, FormState, TextConfig } from '../schema';
|
||||||
import { useAddField } from '../utils/useAddField';
|
import { useAddField } from '../utils/useAddField';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -59,7 +59,7 @@ defineOptions({
|
|||||||
const props = defineProps<FieldProps<TextConfig>>();
|
const props = defineProps<FieldProps<TextConfig>>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
change: [value: string];
|
change: [value: string, eventData?: ContainerChangeEventData];
|
||||||
input: [value: string];
|
input: [value: string];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@ -121,10 +121,28 @@ const inputHandler = (v: string) => {
|
|||||||
const buttonClickHandler = () => {
|
const buttonClickHandler = () => {
|
||||||
if (!appendConfig.value) return;
|
if (!appendConfig.value) return;
|
||||||
if (typeof appendConfig.value.handler === 'function') {
|
if (typeof appendConfig.value.handler === 'function') {
|
||||||
|
const newChangeRecords: ChangeRecord[] = [];
|
||||||
|
const setModel = (key: string, value: any) => {
|
||||||
|
newChangeRecords.push({ propPath: props.prop.replace(`${props.name}`, key), value });
|
||||||
|
};
|
||||||
|
|
||||||
|
const setFormValue = (key: string, value: any) => {
|
||||||
|
newChangeRecords.push({ propPath: key, value });
|
||||||
|
};
|
||||||
|
|
||||||
appendConfig.value.handler(mForm, {
|
appendConfig.value.handler(mForm, {
|
||||||
model: props.model,
|
model: props.model,
|
||||||
values: mForm?.values,
|
values: mForm ? readonly(mForm.initValues) : null,
|
||||||
|
formValue: props.values || {},
|
||||||
|
setModel,
|
||||||
|
setFormValue,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (newChangeRecords.length > 0) {
|
||||||
|
emit('change', props.model[props.name], {
|
||||||
|
changeRecords: newChangeRecords,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user