Bläddra i källkod

fix[pc-components]: 并发上传图片缩略图丢失

chenlei 1 år sedan
förälder
incheckning
ff6a8c83d1
1 ändrade filer med 7 tillägg och 7 borttagningar
  1. 7 7
      packages/pc-components/src/components/DageUpload/index.tsx

+ 7 - 7
packages/pc-components/src/components/DageUpload/index.tsx

@@ -7,7 +7,7 @@ import {
 } from "@ant-design/icons";
 import { updateFileList } from "antd/es/upload/utils";
 import { FC, useContext, useEffect, useMemo, useRef, useState } from "react";
-import { requestByPost } from "@dage/service";
+import { requestByPost, getBaseURL } from "@dage/service";
 import { RcFile, UploadFile, UploadProps } from "antd/es/upload";
 import {
   DageFileAPIResponseType,
@@ -89,7 +89,6 @@ export const DageUpload: FC<DageUploadProps> = ({
   }, [value]);
 
   const beforeUpload = (file: RcFile) => {
-    let pass = false;
     let passFileType = false;
 
     // 校验文件类型
@@ -98,19 +97,18 @@ export const DageUpload: FC<DageUploadProps> = ({
     passFileType = accept.split(",").includes(fileExtension);
     if (!passFileType) {
       message.error(tips || "选择的文件类型不正确!");
+      return Upload.LIST_IGNORE;
     }
 
     // 校验文件大小
     const isLtM = file.size / 1024 / 1024 < maxSize;
     if (!isLtM) {
       message.error(`最大支持 ${maxSize}M!`);
+      return Upload.LIST_IGNORE;
     }
 
-    pass = passFileType && isLtM;
-
-    pass && context?.handleUploadingFileNum("add");
-
-    return pass ? pass : Upload.LIST_IGNORE;
+    context?.handleUploadingFileNum("add");
+    return true;
   };
 
   const onUpload = (option: RcCustomRequestOptions) => {
@@ -163,6 +161,8 @@ export const DageUpload: FC<DageUploadProps> = ({
         try {
           // @ts-ignore
           file.imgAttrs = await getImageSize(file.originFileObj);
+          // todo: 缩略图并发上传有时候会丢失
+          file.thumbUrl = getBaseURL() + file.response.filePath;
         } catch (err) {
           // 图片加载失败
           file.status = "error";