|
@@ -38,7 +38,7 @@ axiosservice.interceptors.request.use(
|
|
|
if (config.url.includes('/data/file/uploadExcel')) {
|
|
|
config.headers['Content-Type'] = 'multipart/form-data'
|
|
|
config.transformRequest = [
|
|
|
- function(data, headers) {
|
|
|
+ function (data, headers) {
|
|
|
return data
|
|
|
},
|
|
|
]
|
|
@@ -52,7 +52,7 @@ axiosservice.interceptors.request.use(
|
|
|
)
|
|
|
|
|
|
axiosservice.interceptors.response.use(
|
|
|
- function(res) {
|
|
|
+ function (res) {
|
|
|
//在这里对返回的数据进行处理
|
|
|
let resp = res.data
|
|
|
if (resp.result === 'unauthc') {
|
|
@@ -76,7 +76,7 @@ axiosservice.interceptors.response.use(
|
|
|
}
|
|
|
return res
|
|
|
},
|
|
|
- function(err) {
|
|
|
+ function (err) {
|
|
|
if (err.response.status == 401) {
|
|
|
store.commit('SETISREQUESTtAUTH', 'err')
|
|
|
router.push({
|
|
@@ -171,33 +171,38 @@ export default {
|
|
|
throw err
|
|
|
}
|
|
|
},
|
|
|
- download(url, params) {
|
|
|
+ async download(url, params) {
|
|
|
// 响应类型:arraybuffer, blob
|
|
|
- axiosservice
|
|
|
- .get(url, {
|
|
|
- params,
|
|
|
- responseType: 'blob',
|
|
|
- })
|
|
|
- .then((resp) => {
|
|
|
- let headers = resp.headers
|
|
|
- let contentType = headers['content-type']
|
|
|
- if (!resp.data) {
|
|
|
- console.error('响应异常:', resp)
|
|
|
- return false
|
|
|
- } else {
|
|
|
- //console.log("下载文件:", resp)
|
|
|
- const blob = new Blob([resp.data], {
|
|
|
- type: contentType,
|
|
|
- })
|
|
|
- const contentDisposition = resp.headers['content-disposition']
|
|
|
- let fileName = 'unknown'
|
|
|
- if (contentDisposition) {
|
|
|
- fileName = window.decodeURI(resp.headers['content-disposition'].split('=')[1])
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ axiosservice
|
|
|
+ .get(url, {
|
|
|
+ params,
|
|
|
+ responseType: 'blob',
|
|
|
+ })
|
|
|
+ .then((resp) => {
|
|
|
+ let headers = resp.headers
|
|
|
+ let contentType = headers['content-type']
|
|
|
+ if (!resp.data?.size) {
|
|
|
+ console.error('响应异常:', resp)
|
|
|
+ resolve({ msg: '文件不存在,下载失败!' })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ //console.log("下载文件:", resp)
|
|
|
+ const blob = new Blob([resp.data], {
|
|
|
+ type: contentType,
|
|
|
+ })
|
|
|
+ const contentDisposition = resp.headers['content-disposition']
|
|
|
+ let fileName = 'unknown'
|
|
|
+ if (contentDisposition) {
|
|
|
+ fileName = window.decodeURI(resp.headers['content-disposition'].split('=')[1])
|
|
|
+ }
|
|
|
+ downFile(blob, fileName)
|
|
|
+ resolve()
|
|
|
}
|
|
|
- downFile(blob, fileName)
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(function(error) {})
|
|
|
+ })
|
|
|
+ .catch(function (error) { })
|
|
|
+ })
|
|
|
+
|
|
|
},
|
|
|
axios: axiosservice,
|
|
|
}
|