1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| const exportContent = (url, data, fileName) => { let token = localStorage.getItem("token"); axios .post(import.meta.env.VITE_ENV + url, data, { responseType: "blob", headers: { Authorization: `Bearer ${token}`, }, }) .then((res) => { const link = document.createElement("a"); res.data.text().then((res1) => { try { let temp = JSON.parse(res1); ElMessage.error(temp.Message); allLoading.value = false; } catch (error) { console.log(error); try { let blob = new Blob([res.data], { type: "application/vnd.ms-excel", }); console.log(res.headers); let _fileName = fileName; link.style.display = "none"; const url = window.URL || window.webkitURL || window.moxURL; link.href = url.createObjectURL(blob); link.setAttribute( "download", _fileName.substring(_fileName.lastIndexOf("_") + 1) ); link.click(); document.body.removeChild(link); url.revokeObjectURL(link.href); allLoading.value = false; } catch (e) { console.log("下载的文件出错", e); } } }); }) .catch((err) => { console.log("请求出错", err.response.data.error); }); };
|