赛事编排导出功能
This commit is contained in:
parent
6a34c1e8ff
commit
589e6138f9
@ -58,7 +58,7 @@ export const eventarrangementPreviewPost = (eventid) => {
|
||||
/**
|
||||
* 导出编排
|
||||
* @param {number} eventid - 赛事ID (路径参数)
|
||||
* @returns {Promise<string>} 返回导出文件URL
|
||||
* @returns {Promise<string>} 返回Base64编码的文件内容
|
||||
*/
|
||||
export const eventarrangementExportPost = (eventid) => {
|
||||
return http.post(`/eventarrangement/export/${eventid}`);
|
||||
|
||||
@ -380,8 +380,42 @@ const onSave = async () => {
|
||||
}
|
||||
|
||||
//export default {
|
||||
const downloadByBlob = (blob, filename = '赛事编排.xlsx') => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const getArr = async () => {
|
||||
const res = await eventarrangementExportPost(initParam.value.id);
|
||||
try {
|
||||
const { succeeded, data, errors } = await eventarrangementExportPost(initParam.value.id);
|
||||
if (!succeeded) {
|
||||
ElMessage.error(errors || '导出失败');
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
ElMessage.warning('未获取到导出文件');
|
||||
return;
|
||||
}
|
||||
// data 是 Base64 编码的文件内容,解码为二进制并下载
|
||||
const byteCharacters = atob(data);
|
||||
const byteNumbers = new Array(byteCharacters.length);
|
||||
for (let i = 0; i < byteCharacters.length; i++) {
|
||||
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
||||
}
|
||||
const byteArray = new Uint8Array(byteNumbers);
|
||||
const blob = new Blob([byteArray], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||
downloadByBlob(blob, '赛事编排.xlsx');
|
||||
ElMessage.success('导出成功');
|
||||
} catch (error) {
|
||||
console.error('导出失败:', error);
|
||||
ElMessage.error('导出失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user