From 6c8c49966a9d0b7751ab1cbf1b51dc72225d75e8 Mon Sep 17 00:00:00 2001 From: JyQAQ <45193678+jyqwq@users.noreply.github.com> Date: Wed, 21 Jan 2026 17:20:53 +0800 Subject: [PATCH] =?UTF-8?q?Perf:=20=E4=BC=98=E5=8C=96antd=20upload?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=20(#7114?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用 * perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用 * perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用 * perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用 --- apps/web-antd/src/adapter/component/index.ts | 12 +++++++++--- playground/src/adapter/component/index.ts | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/web-antd/src/adapter/component/index.ts b/apps/web-antd/src/adapter/component/index.ts index 7fdb1434a..80d990b76 100644 --- a/apps/web-antd/src/adapter/component/index.ts +++ b/apps/web-antd/src/adapter/component/index.ts @@ -17,6 +17,7 @@ import type { BaseFormComponentType } from '@vben/common-ui'; import type { Recordable } from '@vben/types'; import { + computed, defineAsyncComponent, defineComponent, h, @@ -383,12 +384,17 @@ const withPreviewUpload = () => { attrs?.fileList || attrs?.['file-list'] || [], ); + const maxSize = computed(() => attrs?.maxSize ?? attrs?.['max-size']); + const aspectRatio = computed( + () => attrs?.aspectRatio ?? attrs?.['aspect-ratio'], + ); + const handleBeforeUpload = async ( file: UploadFile, originFileList: Array, ) => { - if (attrs.maxSize && (file.size || 0) / 1024 / 1024 > attrs.maxSize) { - message.error($t('ui.formRules.sizeLimit', [attrs.maxSize])); + if (maxSize.value && (file.size || 0) / 1024 / 1024 > maxSize.value) { + message.error($t('ui.formRules.sizeLimit', [maxSize.value])); file.status = 'removed'; return false; } @@ -401,7 +407,7 @@ const withPreviewUpload = () => { ) { file.status = 'removed'; // antd Upload组件问题 file参数获取的是UploadFile类型对象无法取到File类型 所以通过originFileList[0]获取 - const blob = await cropImage(originFileList[0], attrs.aspectRatio); + const blob = await cropImage(originFileList[0], aspectRatio.value); return new Promise((resolve, reject) => { if (!blob) { return reject(new Error($t('ui.crop.errorTip'))); diff --git a/playground/src/adapter/component/index.ts b/playground/src/adapter/component/index.ts index 7fdb1434a..80d990b76 100644 --- a/playground/src/adapter/component/index.ts +++ b/playground/src/adapter/component/index.ts @@ -17,6 +17,7 @@ import type { BaseFormComponentType } from '@vben/common-ui'; import type { Recordable } from '@vben/types'; import { + computed, defineAsyncComponent, defineComponent, h, @@ -383,12 +384,17 @@ const withPreviewUpload = () => { attrs?.fileList || attrs?.['file-list'] || [], ); + const maxSize = computed(() => attrs?.maxSize ?? attrs?.['max-size']); + const aspectRatio = computed( + () => attrs?.aspectRatio ?? attrs?.['aspect-ratio'], + ); + const handleBeforeUpload = async ( file: UploadFile, originFileList: Array, ) => { - if (attrs.maxSize && (file.size || 0) / 1024 / 1024 > attrs.maxSize) { - message.error($t('ui.formRules.sizeLimit', [attrs.maxSize])); + if (maxSize.value && (file.size || 0) / 1024 / 1024 > maxSize.value) { + message.error($t('ui.formRules.sizeLimit', [maxSize.value])); file.status = 'removed'; return false; } @@ -401,7 +407,7 @@ const withPreviewUpload = () => { ) { file.status = 'removed'; // antd Upload组件问题 file参数获取的是UploadFile类型对象无法取到File类型 所以通过originFileList[0]获取 - const blob = await cropImage(originFileList[0], attrs.aspectRatio); + const blob = await cropImage(originFileList[0], aspectRatio.value); return new Promise((resolve, reject) => { if (!blob) { return reject(new Error($t('ui.crop.errorTip')));