fix: 修复表单初始化触发change事件缺少的自定义参数

fix: select组件以api加载时将选项回写scheme,以便change事件调用
This commit is contained in:
gaoyunqi
2024-06-04 17:13:06 +08:00
parent 6cc2639252
commit 1525fed4c8
3 changed files with 9 additions and 8 deletions

View File

@ -25,7 +25,7 @@
import { getDicDetailList } from '/@/api/system/dic';
import { getDatasourceData } from '/@/api/system/datasource';
import { apiConfigFunc, camelCaseString, isValidJSON } from '/@/utils/event/design';
import {debounce} from 'lodash-es';
import { debounce } from 'lodash-es';
type OptionsItem = { label: string; value: string; disabled?: boolean };
@ -79,7 +79,7 @@
const selectedValue = ref<string | number | undefined>(undefined);
const valChanged = ref(false);
// label分开存储时第一次懒加载会同时处罚两次fetch所以这里延迟执行
const fetch = debounce(_fetch, 200, {leading: false, trailing: true});
const fetch = debounce(_fetch, 200, { leading: false, trailing: true });
const getOptions = computed(() => {
const { labelField, valueField, numberToString } = props;
@ -180,8 +180,6 @@
selectedValue.value = ((typeof props.value === 'string' && !!props.value ? props.value?.split(',') : props.value) || undefined) as any;
});
async function _fetch() {
const { sepTextField } = props;
if (!valChanged.value && sepTextField) {
@ -202,6 +200,7 @@
}
if (props.datasourceType === 'api') {
options.value = await apiConfigFunc(props.apiConfig, isCamelCase, formModel, props.index);
props.staticOptions.splice(0, props.staticOptions.length, options.value);
}
} else {
api = props.api;

View File

@ -51,6 +51,7 @@
const formRef = ref<FormInstance>();
const formWrap = ref<HTMLElement>();
const wrapWidth = ref(960);
const formData = inject('formData', { noInject: true });
const propsRef = ref<Partial<FormProps>>({});
@ -437,8 +438,8 @@
for (const eventKey in schema.componentProps['events']) {
if (eventKey !== 'change') return;
try {
const event = new Function('schema', 'formModel', 'formActionType', `${schema.componentProps['events'][eventKey]}`);
event(schema, formModel, formApi);
const event = new Function('schema', 'formModel', 'formActionType', 'extParams', `${schema.componentProps['events'][eventKey]}`);
event(schema, formModel, formApi, { formData });
} catch (error) {
console.log('error', error);
notification.error({

View File

@ -83,6 +83,7 @@
const wrapWidth = ref(960);
const propsRef = ref<Partial<FormProps>>({});
const schemaRef = ref<Nullable<FormSchema[]>>(null);
const formData = inject('formData', { noInject: true });
const getSchemas = computed<FormSchema[]>(() => {
return (unref(getProps).schemas as any) || unref(schemaRef);
@ -438,8 +439,8 @@
for (const eventKey in schema.componentProps['events']) {
if (eventKey !== 'change') return;
try {
const event = new Function('schema', 'formModel', 'formActionType', `${schema.componentProps['events'][eventKey]}`);
event(schema, formModel, formApi);
const event = new Function('schema', 'formModel', 'formActionType', 'extParams', `${schema.componentProps['events'][eventKey]}`);
event(schema, formModel, formApi, { formData });
} catch (error) {
console.log('error', error);
notification.error({