From 17f3b4cf40baceba0cef002ca1ec18c17f280408 Mon Sep 17 00:00:00 2001 From: xingyu Date: Mon, 30 Oct 2023 17:47:57 +0800 Subject: [PATCH] perf: If args of setFieldsValue is empty, it will not be executed --- .../Form/src/components/ImageUpload.vue | 21 +++++-------------- .../Form/src/hooks/useFormEvents.ts | 3 +++ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/components/Form/src/components/ImageUpload.vue b/src/components/Form/src/components/ImageUpload.vue index fdce04c0..ea0c8382 100644 --- a/src/components/Form/src/components/ImageUpload.vue +++ b/src/components/Form/src/components/ImageUpload.vue @@ -7,6 +7,7 @@ import type { UploadFile } from 'ant-design-vue/lib/upload/interface' import { join } from 'lodash-es' import { PlusOutlined } from '@ant-design/icons-vue' import { useI18n } from '@/hooks/web/useI18n' +import { propTypes } from '@/utils/propTypes' import { buildShortUUID } from '@/utils/uuid' import { getAccessToken, getTenantId } from '@/utils/auth' import { isArray, isNotEmpty, isUrl } from '@/utils/is' @@ -32,25 +33,13 @@ const props = defineProps({ type: Array, default: () => ['image/png', 'image/jpeg'], }, - multiple: { - type: Boolean, - default: () => false, - }, + multiple: propTypes.bool.def(false), // 最大数量的文件 - maxCount: { - type: Number, - default: () => 1, - }, + maxCount: propTypes.number.def(1), // 最小数量的文件 - minCount: { - type: Number, - default: () => 0, - }, + minCount: propTypes.number.def(0), // 文件最大多少MB - maxSize: { - type: Number, - default: () => 2, - }, + maxSize: propTypes.number.def(5), }) const emit = defineEmits(['change', 'update:value']) diff --git a/src/components/Form/src/hooks/useFormEvents.ts b/src/components/Form/src/hooks/useFormEvents.ts index 5258b511..6582795a 100644 --- a/src/components/Form/src/hooks/useFormEvents.ts +++ b/src/components/Form/src/hooks/useFormEvents.ts @@ -113,6 +113,9 @@ export function useFormEvents({ * @description: Set form value */ async function setFieldsValue(values: Recordable): Promise { + if (Object.keys(values).length === 0) + return + const fields = getAllFields() // key 支持 a.b.c 的嵌套写法