From 075b3d11b853380b79dc953503524c81d70f640e Mon Sep 17 00:00:00 2001 From: 13176889840 <13176889840@163.com> Date: Tue, 9 Nov 2021 16:50:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=90=8E=E7=AB=AF=E8=BF=94=E5=9B=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B5=81=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 1 + src/views/modules/base/resi.vue | 49 +++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 20 deletions(-) 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)