From e460f44d0d7e61dfdf97a08e0d267cc51ff4b366 Mon Sep 17 00:00:00 2001 From: cc Date: Tue, 26 Mar 2024 08:22:51 +0000 Subject: [PATCH] download --- src/api/api.js | 2 +- src/views/Room.vue | 68 ++++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/api/api.js b/src/api/api.js index d41008a..ba292de 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -47,7 +47,7 @@ export function downloadRequest(url, params) { data: params, responseType: 'blob', headers: { - "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "Content-Type": "application/json", }, }); } diff --git a/src/views/Room.vue b/src/views/Room.vue index 9692542..c6801bf 100644 --- a/src/views/Room.vue +++ b/src/views/Room.vue @@ -343,43 +343,41 @@ const save_room = async () => { }; const exc = async () => { - const param = { - action: 90001, - data: project, - }; - try { + const param = { + action: 90001, + data: project, + }; + const res = await myApi.download(param); console.log(res); - if (1) { - // 文件下载成功 - const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); - const url = window.URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.download = 'xx.xlsx'; // 设置下载的文件名 - document.body.appendChild(link); - link.click(); - link.remove(); - window.URL.revokeObjectURL(url); - ElMessage({ - message: "保存成功", - type: "success", - }); - } else { - // 下载失败,显示错误信息 - ElMessage({ - message: res.message + "[" + res.data + "]", - type: "warning", - }); - } - } catch (error) { - // 捕获并处理可能的错误 - console.error("Error downloading file:", error); - ElMessage({ - message: "下载文件时发生错误", - type: "error", - }); - } + const url = window.URL.createObjectURL(new Blob([res])); + const link = document.createElement('a'); + link.href = url; + link.download = 'xx.xlsx'; + document.body.appendChild(link); + link.click(); + link.remove(); + window.URL.revokeObjectURL(url); + // + // ElMessage({ + // message: "保存成功", + // type: "success", + // }); + // } else { + // // 下载失败,显示错误信息 + // ElMessage({ + // message: res.message + "[" + res.data + "]", + // type: "warning", + // }); + // } + // } catch (error) { + // // 捕获并处理可能的错误 + // console.error("Error downloading file:", error); + // ElMessage({ + // message: "下载文件时发生错误", + // type: "error", + // }); + // // } }; function generateShortUUID() {