From 0cf2271667ac32f8f8e14ddc4bcab3f28d946d1a Mon Sep 17 00:00:00 2001 From: lijian3828940 <403383580@qq.com> Date: Tue, 3 Sep 2024 13:02:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8DshowAdvancedButton?= =?UTF-8?q?=E4=B8=BAtrue=E6=97=B6=EF=BC=8CFormSchema=E4=B8=ADifshow?= =?UTF-8?q?=E6=98=AF=E4=B8=8Emodel=E6=9C=89=E5=85=B3=E7=9A=84=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=97=B6=E5=80=99=EF=BC=8C=E6=9F=A5=E8=AF=A2=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E4=BD=8D=E7=BD=AE=E4=B8=8D=E9=87=8D=E6=96=B0=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=20(#4304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Form/src/BasicForm.vue | 13 ++++++++++++- src/components/Form/src/hooks/useAdvanced.ts | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index 63e942c9..c02f3536 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -124,7 +124,9 @@ const getBindValue = computed(() => ({ ...attrs, ...props, ...unref(getProps) }) as AntFormProps); 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) { const { defaultValue, @@ -134,7 +136,16 @@ field, isHandleDefaultValue = true, valueFormat, + ifShow, } = schema; + + //fix:修复showAdvancedButton为true时,FormSchema中ifshow是与model有关的函数时候,查询按钮位置不重新计算的问题。 + if (unref(getProps).showAdvancedButton) { + schema.ifshow2 = isFunction(ifShow) + ? ifShow({ schema, values: formModel, model: formModel, field }) + : ifShow; + } + // handle date type if ( isHandleDateDefaultValue && diff --git a/src/components/Form/src/hooks/useAdvanced.ts b/src/components/Form/src/hooks/useAdvanced.ts index 342b10dd..0d264075 100644 --- a/src/components/Form/src/hooks/useAdvanced.ts +++ b/src/components/Form/src/hooks/useAdvanced.ts @@ -1,6 +1,15 @@ import type { ColEx } from '../types'; 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 { isBoolean, isFunction, isNumber, isObject } from '@/utils/is'; import { useBreakpoint } from '@/hooks/event/useBreakpoint'; @@ -49,14 +58,17 @@ export default function ({ return 0; }); - const debounceUpdateAdvanced = useDebounceFn(updateAdvanced, 30); + // const debounceUpdateAdvanced = useDebounceFn(updateAdvanced, 30); watch( [() => unref(getSchema), () => advanceState.isAdvanced, () => unref(realWidthRef)], () => { const { showAdvancedButton } = unref(getProps); if (showAdvancedButton) { - debounceUpdateAdvanced(); + // debounceUpdateAdvanced(); + nextTick(() => { + updateAdvanced(); + }); } }, { immediate: true },