diff --git a/src/utils/request.js b/src/utils/request.js index 0466541d..692bb8ba 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -60,6 +60,7 @@ http.interceptors.response.use(response => { }else { router.replace({ name: 'login' }) } + return Promise.reject(response.data.msg) } return response diff --git a/src/views/modules/base/resi.vue b/src/views/modules/base/resi.vue index b7f6f7c6..4ebd5e49 100644 --- a/src/views/modules/base/resi.vue +++ b/src/views/modules/base/resi.vue @@ -225,6 +225,7 @@ import resiSearch from '../../components/resiSearch.vue' import resiForm from '../../components/resiForm.vue' import editResi from '../../components/editResi.vue' +import axios from 'axios' export default { components: { resiSearch, @@ -333,21 +334,21 @@ export default { } // .post('epmetuser/icresiuser/exportExcel', params) - this.$http({ - url: 'epmetuser/icresiuser/exportExcel', + axios({ + url: window.SITE_CONFIG['apiURL'] + '/epmetuser/icresiuser/exportExcel', method: 'post', data: params, - header: { - headers: { 'Content-Type': 'application/x-download' } - }, responseType: 'blob' }) - .then(({ data: res }) => { + .then(res => { + console.log('resllll', res) + let fileName = window.decodeURI(res.headers["content-disposition"].split(";")[1].split("=")[1]) + console.log('filename', fileName) // var headerData = res.headers // this.download(res, '人员数据.xlsx') - console.log('res', res) - const fileName = '人员数据.xlsx' - let blob = new Blob([res], { type: 'application/vnd.ms-excel' }) + // console.log('res', res) + // const fileName = '人员数据.xlsx' + let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) var url = window.URL.createObjectURL(blob) var aLink = document.createElement('a') aLink.style.display = 'none' @@ -357,7 +358,6 @@ export default { aLink.click() document.body.removeChild(aLink) //下载完成移除元素 window.URL.revokeObjectURL(url) //释放掉blob对象 - // window.location.href = res.data }) .catch((err) => { console.log('获取导出情失败', err) @@ -398,18 +398,27 @@ export default { this.importBtnTitle = '正在上传中...' const formData = new FormData() //FormData对象,添加参数只能通过append('key', value)的形式添加 formData.append('file', file.file) //添加文件对象 - this.$http - .post('/epmetuser/icresiuser/importExcel', formData) - .then(({ data: res }) => { - // if(res.code === 0) { - // // this.$refs.upload.submit() - // file.onSuccess() - // console.log('res-ooooo---', res) - // } + axios({ + url: window.SITE_CONFIG['apiURL'] + '/epmetuser/icresiuser/importExcel', + method: 'post', + data: formData, + responseType: 'blob' + }) + .then((res) => { this.importLoading = false this.importBtnTitle = '导入人员数据' - console.log('res-ooooo---', res) - this.download(res, 'info.xlsx') + let fileName = window.decodeURI(res.headers["content-disposition"].split(";")[1].split("=")[1]) + console.log('filename', fileName) + let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) + var url = window.URL.createObjectURL(blob) + var aLink = document.createElement('a') + aLink.style.display = 'none' + aLink.href = url + aLink.setAttribute('download', fileName) + document.body.appendChild(aLink) + aLink.click() + document.body.removeChild(aLink) //下载完成移除元素 + window.URL.revokeObjectURL(url) //释放掉blob对象 }) .catch( err => { console.log('失败', err)