update 优化 下载zip方法增加遮罩层
This commit is contained in:
		| @ -34,21 +34,29 @@ export default { | |||||||
|   }, |   }, | ||||||
|   async zip(url: string, name: string) { |   async zip(url: string, name: string) { | ||||||
|     url = baseURL + url; |     url = baseURL + url; | ||||||
|     const res = await axios({ |     downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' }); | ||||||
|       method: 'get', |     try { | ||||||
|       url: url, |       const res = await axios({ | ||||||
|       responseType: 'blob', |         method: 'get', | ||||||
|       headers: { |         url: url, | ||||||
|         Authorization: 'Bearer ' + getToken(), |         responseType: 'blob', | ||||||
|         datasource: localStorage.getItem('dataName') |         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); | ||||||
|       } |       } | ||||||
|     }); |       downloadLoadingInstance.close(); | ||||||
|     const isBlob = blobValidate(res.data); |     } catch (r) { | ||||||
|     if (isBlob) { |       console.error(r) | ||||||
|       const blob = new Blob([res.data], { type: 'application/zip' }); |       ElMessage.error('下载文件出现错误,请联系管理员!') | ||||||
|       FileSaver.saveAs(blob, name); |       downloadLoadingInstance.close(); | ||||||
|     } else { |  | ||||||
|       this.printErrMsg(res.data); |  | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   async printErrMsg(data: any) { |   async printErrMsg(data: any) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 疯狂的狮子Li
					疯狂的狮子Li