From 40175c150cc962401824a132da07233293d0e094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 4 Jul 2023 16:39:05 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E4=B8=8B?= =?UTF-8?q?=E8=BD=BDzip=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0=E9=81=AE?= =?UTF-8?q?=E7=BD=A9=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/download.ts | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/plugins/download.ts b/src/plugins/download.ts index e1c4414..c6c8521 100644 --- a/src/plugins/download.ts +++ b/src/plugins/download.ts @@ -34,21 +34,29 @@ export default { }, async zip(url: string, name: string) { url = baseURL + url; - const res = await axios({ - method: 'get', - url: url, - responseType: 'blob', - headers: { - Authorization: 'Bearer ' + getToken(), - datasource: localStorage.getItem('dataName') + downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' }); + try { + const res = await axios({ + method: 'get', + url: url, + responseType: 'blob', + headers: { + Authorization: 'Bearer ' + getToken(), + datasource: localStorage.getItem('dataName') + } + }); + const isBlob = blobValidate(res.data); + if (isBlob) { + const blob = new Blob([res.data], { type: 'application/zip' }); + FileSaver.saveAs(blob, name); + } else { + this.printErrMsg(res.data); } - }); - const isBlob = blobValidate(res.data); - if (isBlob) { - const blob = new Blob([res.data], { type: 'application/zip' }); - FileSaver.saveAs(blob, name); - } else { - this.printErrMsg(res.data); + downloadLoadingInstance.close(); + } catch (r) { + console.error(r) + ElMessage.error('下载文件出现错误,请联系管理员!') + downloadLoadingInstance.close(); } }, async printErrMsg(data: any) {