解析blob响应是否登录失效

This commit is contained in:
RuoYi
2021-10-25 09:49:13 +08:00
parent d0a5c25b5d
commit 3901695a6f
3 changed files with 35 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
import { saveAs } from 'file-saver'
import axios from 'axios'
import { Message } from 'element-ui'
import { saveAs } from 'file-saver'
import { getToken } from '@/utils/auth'
import { blobValidate } from "@/utils/ruoyi";
const baseURL = process.env.VUE_APP_BASE_API
@@ -12,9 +14,14 @@ export default {
url: url,
responseType: 'blob',
headers: { 'Authorization': 'Bearer ' + getToken() }
}).then(res => {
const blob = new Blob([res.data], { type: 'application/zip' })
this.saveAs(blob, name)
}).then(async (res) => {
const isLogin = await blobValidate(res.data);
if (isLogin) {
const blob = new Blob([res.data], { type: 'application/zip' })
this.saveAs(blob, name)
} else {
Message.error('无效的会话,或者会话已过期,请重新登录。');
}
})
},
saveAs(text, name, opts) {