import { exportExcel } from '@/utils/export'exportExcel({ url: that.$http.defaults.baseURL +'crm/clue/listInProcess/export', method: 'post', headers: { 'Content-Type': 'application/json; charset=UTF-8', 'systemUserId': sessionStorage.getItem("pcsystemUserId"), 'menuId':"15", }, data: JSON.stringify(that.formSearch)})
import Vue from 'vue';// 导出表格export function exportExcel(baseRequest) { Vue.prototype.$http({ ...baseRequest, responseType: 'blob', }).then(response=>{ let fileReader = new FileReader(); fileReader.onload = function() { try { let jsonData = JSON.parse(this.result); // 说明是普通对象数据,后台转换失败 if(jsonData.resultCode){ return Vue.prototype.$message({ type: "error", message: jsonData.resultMessage }); } } catch (err) { //解析成对象失败,说明是正常的文件流 let name = response.headers['content-disposition']; name = decodeURIComponent(name); let fileName = name.substring(20, name.length); let blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); if ('download' in document.createElement('a')) { const link = document.createElement('a'); link.download = fileName; link.style.display = 'none'; link.href = URL.createObjectURL(blob); document.body.appendChild(link); link.click(); URL.revokeObjectURL(link.href); document.body.removeChild(link); } else { navigator.msSaveBlob(blob); } } }; fileReader.readAsText(response.data) }).catch((res) => { console.error("请求失败", res); });}