Przeglądaj źródła

Perf: 优化antd upload组件参数获取 (#7114)

* perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用

* perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用

* perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用

* perf(antd upload params): 优化组件参数取值 确保不同调用场景配置参数可用
JyQAQ 4 miesięcy temu
rodzic
commit
6c8c49966a

+ 9 - 3
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 type { Recordable } from '@vben/types';
 
 
 import {
 import {
+  computed,
   defineAsyncComponent,
   defineAsyncComponent,
   defineComponent,
   defineComponent,
   h,
   h,
@@ -383,12 +384,17 @@ const withPreviewUpload = () => {
         attrs?.fileList || attrs?.['file-list'] || [],
         attrs?.fileList || attrs?.['file-list'] || [],
       );
       );
 
 
+      const maxSize = computed(() => attrs?.maxSize ?? attrs?.['max-size']);
+      const aspectRatio = computed(
+        () => attrs?.aspectRatio ?? attrs?.['aspect-ratio'],
+      );
+
       const handleBeforeUpload = async (
       const handleBeforeUpload = async (
         file: UploadFile,
         file: UploadFile,
         originFileList: Array<File>,
         originFileList: Array<File>,
       ) => {
       ) => {
-        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';
           file.status = 'removed';
           return false;
           return false;
         }
         }
@@ -401,7 +407,7 @@ const withPreviewUpload = () => {
         ) {
         ) {
           file.status = 'removed';
           file.status = 'removed';
           // antd Upload组件问题 file参数获取的是UploadFile类型对象无法取到File类型 所以通过originFileList[0]获取
           // 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) => {
           return new Promise((resolve, reject) => {
             if (!blob) {
             if (!blob) {
               return reject(new Error($t('ui.crop.errorTip')));
               return reject(new Error($t('ui.crop.errorTip')));

+ 9 - 3
playground/src/adapter/component/index.ts

@@ -17,6 +17,7 @@ import type { BaseFormComponentType } from '@vben/common-ui';
 import type { Recordable } from '@vben/types';
 import type { Recordable } from '@vben/types';
 
 
 import {
 import {
+  computed,
   defineAsyncComponent,
   defineAsyncComponent,
   defineComponent,
   defineComponent,
   h,
   h,
@@ -383,12 +384,17 @@ const withPreviewUpload = () => {
         attrs?.fileList || attrs?.['file-list'] || [],
         attrs?.fileList || attrs?.['file-list'] || [],
       );
       );
 
 
+      const maxSize = computed(() => attrs?.maxSize ?? attrs?.['max-size']);
+      const aspectRatio = computed(
+        () => attrs?.aspectRatio ?? attrs?.['aspect-ratio'],
+      );
+
       const handleBeforeUpload = async (
       const handleBeforeUpload = async (
         file: UploadFile,
         file: UploadFile,
         originFileList: Array<File>,
         originFileList: Array<File>,
       ) => {
       ) => {
-        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';
           file.status = 'removed';
           return false;
           return false;
         }
         }
@@ -401,7 +407,7 @@ const withPreviewUpload = () => {
         ) {
         ) {
           file.status = 'removed';
           file.status = 'removed';
           // antd Upload组件问题 file参数获取的是UploadFile类型对象无法取到File类型 所以通过originFileList[0]获取
           // 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) => {
           return new Promise((resolve, reject) => {
             if (!blob) {
             if (!blob) {
               return reject(new Error($t('ui.crop.errorTip')));
               return reject(new Error($t('ui.crop.errorTip')));