shaogen1995 2 tygodni temu
rodzic
commit
563dbec112

+ 9 - 21
后台管理/src/components/Z3upFiles/index.tsx

@@ -142,15 +142,11 @@ function Z3upFiles(
 
       const files = Array.from(e.target.files)
 
-      const uploadedFiles: FileImgListType[] = []
-      let hasError = false
-
       // 逐个上传文件
       for (const file of files) {
         // 校验大小
         if (size && file.size > size * 1024 * 1024) {
           MessageFu.warning(`文件"${file.name}"超过${size}M限制!`)
-          hasError = true
           continue
         }
 
@@ -167,32 +163,24 @@ function Z3upFiles(
             if (fromData[k]) fd.append(k, fromData[k])
           }
         }
+        // 清空input值
+        e.target.value = ''
 
         try {
           const res = await API_upFile(fd, myUrl)
           if (res.code === 0) {
-            uploadedFiles.push(res.data)
+            MessageFu.success(
+              `上传成功${files.length > 1 ? `(${files.indexOf(file) + 1}/${files.length})` : ''}`
+            )
+            setFileList(prev => [...prev, res.data])
+            fileDomInitialFu()
           } else {
-            MessageFu.error(`文件"${file.name}"上传失败`)
-            hasError = true
+            fileDomInitialFu()
           }
         } catch (error) {
-          MessageFu.error(`文件"${file.name}"上传失败`)
-          hasError = true
+          fileDomInitialFu()
         }
       }
-
-      // 清空input值
-      e.target.value = ''
-
-      if (uploadedFiles.length > 0) {
-        setFileList(prev => [...prev, ...uploadedFiles])
-        MessageFu.success(`成功上传${uploadedFiles.length}个文件`)
-      }
-
-      if (!hasError && uploadedFiles.length === files.length) {
-        fileDomInitialFu()
-      }
     },
     [dirCode, fromData, myUrl, size, type]
   )

+ 0 - 1
后台管理/src/store/action/layout.ts

@@ -40,7 +40,6 @@ export const API_upFile = (data: any, url: string) => {
     },
     // 取消上传
     cancelToken: new CancelToken(function executor(c) {
-      domShowFu('#UpAsyncLoding', false)
       store.dispatch({
         type: 'layout/closeUpFile',
         payload: { fu: c, state: true }

+ 18 - 18
后台管理/src/utils/domShow.ts

@@ -1,35 +1,35 @@
-import store from "@/store";
+import store from '@/store'
 
 // 加载和上传的盒子的显示隐藏
 export const domShowFu = (ele: string, val: boolean) => {
-  const dom: HTMLDivElement = document.querySelector(ele)!;
+  const dom: HTMLDivElement = document.querySelector(ele)!
   if (val) {
-    dom.style.opacity = "1";
-    dom.style.pointerEvents = "auto";
+    dom.style.opacity = '1'
+    dom.style.pointerEvents = 'auto'
   } else {
-    dom.style.opacity = "0";
-    dom.style.pointerEvents = "none";
+    dom.style.opacity = '0'
+    dom.style.pointerEvents = 'none'
   }
-};
+}
 
 // 上传附件的进度条
-let progressDom: HTMLDivElement = document.querySelector("#progress")!;
+let progressDom: HTMLDivElement = document.querySelector('#progress')!
 export const progressDomFu = (val: string) => {
-  if (!progressDom) progressDom = document.querySelector("#progress")!;
-  progressDom.style.width = val;
-};
+  if (!progressDom) progressDom = document.querySelector('#progress')!
+  progressDom.style.width = val
+}
 
 // 上传附件的dom操作
 export const fileDomInitialFu = () => {
   // 隐藏进度条的dom
-  domShowFu("#UpAsyncLoding", false);
-  progressDomFu("0%");
+  domShowFu('#UpAsyncLoding', false)
+  progressDomFu('0%')
   // 初始化 上传附件 的状态
   setTimeout(() => {
     if (store.getState().A0Layout.closeUpFile.state)
       store.dispatch({
-        type: "layout/closeUpFile",
-        payload: { fu: () => {}, state: false },
-      });
-  }, 200);
-};
+        type: 'layout/closeUpFile',
+        payload: { fu: () => {}, state: false }
+      })
+  }, 200)
+}

+ 3 - 2
后台管理/src/utils/http.ts

@@ -55,7 +55,8 @@ let timeId = -1
 http.interceptors.response.use(
   function (response) {
     // 请求回来的关闭加载提示
-    axajInd--
+    if (axajInd >= 1) axajInd--
+
     if (axajInd === 0) {
       domShowFu('#AsyncSpinLoding', false)
     }
@@ -74,8 +75,8 @@ http.interceptors.response.use(
   },
   async function (err) {
     clearTimeout(timeId)
+    if (axajInd >= 1) axajInd--
     timeId = window.setTimeout(() => {
-      axajInd = 0
       domShowFu('#AsyncSpinLoding', false)
       // 如果因为网络原因,response没有,给提示消息
       if (!err.response) {