fix:修复showAdvancedButton为true时,FormSchema中ifshow是与model有关的函数时候,查询按钮位置不重新计算的问题。 (#4304)

This commit is contained in:
lijian3828940 2024-09-03 13:02:49 +08:00 committed by GitHub
parent 6d2de002ef
commit 0cf2271667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 4 deletions

View File

@ -124,7 +124,9 @@
const getBindValue = computed(() => ({ ...attrs, ...props, ...unref(getProps) }) as AntFormProps); const getBindValue = computed(() => ({ ...attrs, ...props, ...unref(getProps) }) as AntFormProps);
const getSchema = computed((): FormSchema[] => { const getSchema = computed((): FormSchema[] => {
const schemas: FormSchema[] = cloneDeep(unref(schemaRef) || (unref(getProps).schemas as any)); const schemas: (FormSchema & { ifshow2?: boolean })[] = cloneDeep(
unref(schemaRef) || (unref(getProps).schemas as any),
);
for (const schema of schemas) { for (const schema of schemas) {
const { const {
defaultValue, defaultValue,
@ -134,7 +136,16 @@
field, field,
isHandleDefaultValue = true, isHandleDefaultValue = true,
valueFormat, valueFormat,
ifShow,
} = schema; } = schema;
//fix:showAdvancedButtontrueFormSchemaifshowmodel
if (unref(getProps).showAdvancedButton) {
schema.ifshow2 = isFunction(ifShow)
? ifShow({ schema, values: formModel, model: formModel, field })
: ifShow;
}
// handle date type // handle date type
if ( if (
isHandleDateDefaultValue && isHandleDateDefaultValue &&

View File

@ -1,6 +1,15 @@
import type { ColEx } from '../types'; import type { ColEx } from '../types';
import type { AdvanceState } from '../types/hooks'; import type { AdvanceState } from '../types/hooks';
import { ComputedRef, getCurrentInstance, Ref, shallowReactive, computed, unref, watch } from 'vue'; import {
ComputedRef,
getCurrentInstance,
Ref,
shallowReactive,
computed,
unref,
watch,
nextTick,
} from 'vue';
import type { FormProps, FormSchemaInner as FormSchema } from '../types/form'; import type { FormProps, FormSchemaInner as FormSchema } from '../types/form';
import { isBoolean, isFunction, isNumber, isObject } from '@/utils/is'; import { isBoolean, isFunction, isNumber, isObject } from '@/utils/is';
import { useBreakpoint } from '@/hooks/event/useBreakpoint'; import { useBreakpoint } from '@/hooks/event/useBreakpoint';
@ -49,14 +58,17 @@ export default function ({
return 0; return 0;
}); });
const debounceUpdateAdvanced = useDebounceFn(updateAdvanced, 30); // const debounceUpdateAdvanced = useDebounceFn(updateAdvanced, 30);
watch( watch(
[() => unref(getSchema), () => advanceState.isAdvanced, () => unref(realWidthRef)], [() => unref(getSchema), () => advanceState.isAdvanced, () => unref(realWidthRef)],
() => { () => {
const { showAdvancedButton } = unref(getProps); const { showAdvancedButton } = unref(getProps);
if (showAdvancedButton) { if (showAdvancedButton) {
debounceUpdateAdvanced(); // debounceUpdateAdvanced();
nextTick(() => {
updateAdvanced();
});
} }
}, },
{ immediate: true }, { immediate: true },