From fab903c39c1692cd07e98c7305bb6c407cabdd8e Mon Sep 17 00:00:00 2001 From: leon Date: Tue, 20 Apr 2021 13:31:19 +0800 Subject: [PATCH] :bug: fix: catch download error bug --- ruoyi-ui/src/utils/zipdownload.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ruoyi-ui/src/utils/zipdownload.js b/ruoyi-ui/src/utils/zipdownload.js index ac2745bca..7449f9b95 100644 --- a/ruoyi-ui/src/utils/zipdownload.js +++ b/ruoyi-ui/src/utils/zipdownload.js @@ -1,4 +1,5 @@ import axios from 'axios' +import { Message } from 'element-ui' import { getToken } from '@/utils/auth' const mimeMap = { @@ -15,7 +16,16 @@ export function downLoadZip(str, filename) { responseType: 'blob', headers: { 'Authorization': 'Bearer ' + getToken() } }).then(res => { - resolveBlob(res, mimeMap.zip) + let fileReader = new FileReader(); + fileReader.onload = () => { + try { + let { code, msg } = JSON.parse(fileReader.result); + if (code !== 200) Message.error(msg || '下载失败') + } catch (err) { + resolveBlob(res, mimeMap.zip) + } + }; + fileReader.readAsText(res.data); }) } /**