Sfoglia il codice sorgente

🐛-后端上传格式不支持的时候校验弹窗

shaogen1995 1 anno fa
parent
commit
f9541ce53a

+ 2 - 1
src/pages/A1Project/A1Inner/A1ILack.tsx

@@ -76,7 +76,8 @@ function A1ILack({ closeFu, addSuFu, projectId }: Props) {
     const res = await A1_APIIsaveLack(projectId, arr2);
 
     if (res.code === 0) {
-      MessageFu.success("登记成功!");
+      if (arr.length > 0) MessageFu.success("登记成功!");
+
       addSuFu();
       closeFu();
     }

+ 9 - 11
src/pages/A1Project/A1Inner/A1IupFile/index.tsx

@@ -168,16 +168,18 @@ function A1IupFile({
       setFileList([...info.fileList]);
 
       const { status } = info.file;
-      if (status !== "uploading") {
-        // 检查请求状态
-        const response = info.file.response || {};
 
+      // 检查请求状态
+      const response = info.file.response || {};
+
+      if (status !== "uploading") {
         if (response.code !== 0) {
+          setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
           clearTimeout(timeRef.current);
 
           timeRef.current = window.setTimeout(() => {
-            setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
-          }, 100);
+            MessageFu.warning(response.msg);
+          }, 200);
         }
         if (response.code === 5001 || response.code === 5002) {
           message.warning("登录失效!");
@@ -187,7 +189,7 @@ function A1IupFile({
 
         // console.log(info.file, info.fileList);
       }
-      if (status === "done") {
+      if (status === "done" && response.code === 0) {
         // console.log("-----", info);
         setFileList(
           info.fileList.map((v) => ({
@@ -209,11 +211,7 @@ function A1IupFile({
       } else if (status === "error") {
         message.error(`${info.file.fileName} 上传失败.`);
         // 去掉列表中的失败状态文件
-        clearTimeout(timeRef.current);
-
-        timeRef.current = window.setTimeout(() => {
-          setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
-        }, 100);
+        setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
       }
     },
     // onDrop(e) {

+ 4 - 7
src/pages/A1Project/A1Outer/A1OupFile/index.tsx

@@ -69,11 +69,12 @@ function A1OupFile({ myUrl, fromData, nowLoc, closeFu, upFileFu }: props) {
         const response = info.file.response || {};
 
         if (response.code !== 0) {
+          setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
           clearTimeout(timeRef.current);
 
           timeRef.current = window.setTimeout(() => {
-            setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
-          }, 100);
+            MessageFu.warning(response.msg);
+          }, 200);
         }
         if (response.code === 5001 || response.code === 5002) {
           message.warning("登录失效!");
@@ -88,11 +89,7 @@ function A1OupFile({ myUrl, fromData, nowLoc, closeFu, upFileFu }: props) {
       } else if (status === "error") {
         message.error(`${info.file.name} 上传失败.`);
         // 去掉列表中的失败状态文件
-        clearTimeout(timeRef.current);
-
-        timeRef.current = window.setTimeout(() => {
-          setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
-        }, 100);
+        setFileList(info.fileList.filter((v) => v.uid !== info.file.uid));
       }
     },
     // onDrop(e) {

+ 6 - 4
src/utils/authFilesLook.ts

@@ -67,14 +67,16 @@ export const urlChangeFu = (
 export const authFilesLookFu = (name: string, url?: string) => {
   let flag = false;
 
-  if (name.toLowerCase().endsWith(".pdf")) {
+  const nameRes = name ? name : "";
+
+  if (nameRes.toLowerCase().endsWith(".pdf")) {
     if (url) urlChangeFu(url, false, "pdf");
     flag = true;
   }
 
   const arr1 = [".png", ".jpg", ".jpeg", ".gif"];
   arr1.forEach((v) => {
-    if (name.toLowerCase().endsWith(v)) {
+    if (nameRes.toLowerCase().endsWith(v)) {
       if (url) urlChangeFu(url, false, "img");
 
       flag = true;
@@ -86,13 +88,13 @@ export const authFilesLookFu = (name: string, url?: string) => {
   const arr2 = [".mp3", ".wav"];
 
   arr2.forEach((v) => {
-    if (name.toLowerCase().endsWith(v)) {
+    if (nameRes.toLowerCase().endsWith(v)) {
       type = "audio";
       flag = true;
     }
   });
 
-  if (name.toLowerCase().endsWith(".mp4")) {
+  if (nameRes.toLowerCase().endsWith(".mp4")) {
     type = "video";
     flag = true;
   }

+ 6 - 4
src/utils/filesLook.ts

@@ -4,14 +4,16 @@ import { baseURL } from "./http";
 const filesLookFu = (name: string, url?: string) => {
   let flag = false;
 
-  if (name.toLowerCase().endsWith(".pdf")) {
+  const nameRes = name ? name : "";
+
+  if (nameRes.toLowerCase().endsWith(".pdf")) {
     if (url) window.open(baseURL + url);
     flag = true;
   }
 
   const arr1 = [".png", ".jpg", ".jpeg", ".gif"];
   arr1.forEach((v) => {
-    if (name.toLowerCase().endsWith(v)) {
+    if (nameRes.toLowerCase().endsWith(v)) {
       if (url) {
         store.dispatch({
           type: "layout/lookBigImg",
@@ -31,13 +33,13 @@ const filesLookFu = (name: string, url?: string) => {
   const arr2 = [".mp3", ".wav"];
 
   arr2.forEach((v) => {
-    if (name.toLowerCase().endsWith(v)) {
+    if (nameRes.toLowerCase().endsWith(v)) {
       type = "audio";
       flag = true;
     }
   });
 
-  if (name.toLowerCase().endsWith(".mp4")) {
+  if (nameRes.toLowerCase().endsWith(".mp4")) {
     type = "video";
     flag = true;
   }