Hwf hace 8 meses
padre
commit
07d636a2d8
Se han modificado 1 ficheros con 8 adiciones y 12 borrados
  1. 8 12
      src/utils/request.ts

+ 8 - 12
src/utils/request.ts

@@ -165,31 +165,27 @@ service.interceptors.response.use(
 );
 // 通用下载方法
 export function download2(url: string, fileName: string) {
+    downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
+    //通过文件名称的后缀判断文件类型
     return service
-        .get(
-            url,
-            {},
-            {
-                headers: { 'Content-Type': 'application/octet-stream' },
-                responseType: 'blob'
-            }
-        )
+        .get(url, { responseType: 'blob' })
         .then(async (resp: any) => {
             const isLogin = blobValidate(resp);
-            debugger
             if (isLogin) {
-                const blob = new Blob([resp]);
+                const blob = new Blob([resp], { type: 'application/octet-stream' });
                 FileSaver.saveAs(blob, fileName);
             } else {
                 const resText = await resp.data.text();
                 const rspObj = JSON.parse(resText);
                 const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
-                showFailToast(errMsg);
+                ElMessage.error(errMsg);
             }
+            downloadLoadingInstance.close();
         })
         .catch((r: any) => {
             console.error(r);
-            showFailToast('下载文件出现错误!')
+            ElMessage.error('下载文件出现错误,请联系管理员!');
+            downloadLoadingInstance.close();
         });
 }
 // 导出 axios 实例