main
cc 2024-03-26 08:22:51 +00:00
parent 4762eeab6d
commit e460f44d0d
2 changed files with 34 additions and 36 deletions

View File

@ -47,7 +47,7 @@ export function downloadRequest(url, params) {
data: params, data: params,
responseType: 'blob', responseType: 'blob',
headers: { headers: {
"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Content-Type": "application/json",
}, },
}); });
} }

View File

@ -347,39 +347,37 @@ const exc = async () => {
action: 90001, action: 90001,
data: project, data: project,
}; };
try {
const res = await myApi.download(param); const res = await myApi.download(param);
console.log(res); console.log(res);
if (1) { const url = window.URL.createObjectURL(new Blob([res]));
// const link = document.createElement('a');
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.href = url;
link.download = 'xx.xlsx'; // link.download = 'xx.xlsx';
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
link.remove(); link.remove();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
ElMessage({ //
message: "保存成功", // ElMessage({
type: "success", // message: "",
}); // type: "success",
} else { // });
// // } else {
ElMessage({ // //
message: res.message + "[" + res.data + "]", // ElMessage({
type: "warning", // message: res.message + "[" + res.data + "]",
}); // type: "warning",
} // });
} catch (error) { // }
// // } catch (error) {
console.error("Error downloading file:", error); // //
ElMessage({ // console.error("Error downloading file:", error);
message: "下载文件时发生错误", // ElMessage({
type: "error", // message: "",
}); // type: "error",
} // });
// // }
}; };
function generateShortUUID() { function generateShortUUID() {