修改下载token失效的问题
This commit is contained in:
+57
-22
@@ -1,6 +1,9 @@
|
||||
import Vue from 'vue'
|
||||
import { axios } from '@/utils/request'
|
||||
import store from '@/store'
|
||||
import JLoadingOne from '../components/jero/JLoadingOne'
|
||||
import { Modal } from 'ant-design-vue'
|
||||
import { ACCESS_TOKEN, TENANT_ID } from '@/store/mutation-types'
|
||||
|
||||
const showDrawer = {}
|
||||
|
||||
@@ -153,29 +156,61 @@ export function downloadFile(url, fileName, parameter, callback) {
|
||||
isTrue: isTrue
|
||||
})
|
||||
return downFile(url, parameter).then((data) => {
|
||||
console.log(data)
|
||||
if (!data || data.size === 0) {
|
||||
Vue.prototype['$message'].warning('文件下载失败')
|
||||
return
|
||||
let fileReader = new FileReader()
|
||||
fileReader.onload = function(event) {
|
||||
try {
|
||||
let jsonData = JSON.parse(event.target.result)
|
||||
if (jsonData.message.includes('token')) {
|
||||
index.showDrawer({
|
||||
loading: false,
|
||||
isTrue: isTrue
|
||||
})
|
||||
Modal.error({
|
||||
title: '登录已过期',
|
||||
content: '很抱歉,登录已过期,请重新登录',
|
||||
okText: '重新登录',
|
||||
mask: false,
|
||||
onOk: () => {
|
||||
store.dispatch('Logout').then(() => {
|
||||
Vue.ls.remove(ACCESS_TOKEN)
|
||||
try {
|
||||
let path = window.document.location.pathname
|
||||
if (path != '/' && path.indexOf('/user/login') == -1) {
|
||||
window.location.reload()
|
||||
}
|
||||
} catch (e) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
if (!data || data.size === 0) {
|
||||
Vue.prototype['$message'].warning('文件下载失败')
|
||||
return
|
||||
}
|
||||
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
||||
window.navigator.msSaveBlob(new Blob([data]), fileName)
|
||||
} else {
|
||||
let url = window.URL.createObjectURL(new Blob([data]))
|
||||
let link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.href = url
|
||||
link.setAttribute('download', fileName)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link) //下载完成移除元素
|
||||
window.URL.revokeObjectURL(url) //释放掉blob对象
|
||||
}
|
||||
index.showDrawer({
|
||||
loading: false,
|
||||
isTrue: isTrue
|
||||
})
|
||||
callback && callback()
|
||||
}
|
||||
}
|
||||
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
||||
window.navigator.msSaveBlob(new Blob([data]), fileName)
|
||||
} else {
|
||||
let url = window.URL.createObjectURL(new Blob([data]))
|
||||
let link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.href = url
|
||||
link.setAttribute('download', fileName)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link) //下载完成移除元素
|
||||
window.URL.revokeObjectURL(url) //释放掉blob对象
|
||||
}
|
||||
index.showDrawer({
|
||||
loading: false,
|
||||
isTrue: isTrue
|
||||
})
|
||||
callback && callback()
|
||||
fileReader.readAsText(data)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user