媒体库-单独下载、批量下载bug修正

main
滕嵩 3 weeks ago
parent 218c6ae04d
commit 23a04dba72

@ -27,10 +27,10 @@
id: 'meitiku', id: 'meitiku',
name: '媒体库', name: '媒体库',
children: [ children: [
{ // {
id: '', // id: '',
name: '全部资源', // name: '',
}, // },
{ {
id: '1', id: '1',
name: '可见光', name: '可见光',

@ -20,17 +20,30 @@
<a-button :icon="h(PlusOutlined)" @click="addFolder"> </a-button> <a-button :icon="h(PlusOutlined)" @click="addFolder"> </a-button>
<a-button :icon="h(ColumnHeightOutlined)" @click="moveFolderOrFile"></a-button> <a-button :icon="h(ColumnHeightOutlined)" @click="moveFolderOrFile"></a-button>
<a-button :icon="h(DeleteOutlined)" @click="deleteFolderOrFile"> </a-button> <a-button :icon="h(DeleteOutlined)" @click="deleteFolderOrFile"> </a-button>
<a-button
:icon="h(DownloadOutlined)"
:loading="downloadAloneLoading"
@click="downloadAloneFile"
>
单独下载
</a-button>
<a-popover trigger="hover"> <a-popover trigger="hover">
<template #content> <template #content>
<div v-if="!downloadLoading"> /</div> <div v-if="!downloadZipLoading">
<div v-if="downloadLoading"> 选择下载的文件/文件夹压缩下载成一个压缩包文件
<a-progress :percent="downPercent" type="circle" /> </div>
<div v-if="downloadZipLoading">
<a-progress
type="circle"
:percent="downloadZipPercent"
:format="(downloadZipPercent) => `下载中\n${downloadZipPercent}%`"
/>
</div> </div>
</template> </template>
<a-button <a-button
:icon="h(DownloadOutlined)" :icon="h(DownloadOutlined)"
:loading="downloadLoading" :loading="downloadZipLoading"
@click="downloadOpenMoadl" @click="downloadZipOpenMoadl"
> >
批量下载 批量下载
</a-button> </a-button>
@ -306,7 +319,7 @@
<!-- 下载文件命名窗口 --> <!-- 下载文件命名窗口 -->
<a-modal <a-modal
v-model:open="downloadOpen" v-model:open="downloadZipOpen"
title="压缩" title="压缩"
width="30%" width="30%"
:centered="true" :centered="true"
@ -315,13 +328,13 @@
:keyboard="false" :keyboard="false"
:mask="false" :mask="false"
:maskClosable="false" :maskClosable="false"
@ok="downloadFile" @ok="downloadZipFile"
@cancel="((zipFileName = null), (downloadRows = []))" @cancel="((zipFileName = null), (downloadRows = []))"
> >
<div style="width: 100%; margin: 10px; padding: 10px"> <div style="width: 100%; margin: 10px; padding: 10px">
<a-row> <a-row>
<a-col :span="24"> <a-col :span="24">
<div style="width: 100%; height: 40px">批量下载会先进行压缩成一个文件再下载</div> <div style="width: 100%; height: 40px">批量下载会先进行压缩成一个文件后再下载</div>
</a-col> </a-col>
<a-col :span="4"> <a-col :span="4">
<div style="width: 100%"> 压缩包名称: </div> <div style="width: 100%"> 压缩包名称: </div>
@ -484,7 +497,7 @@
const paginations = document.querySelectorAll('.ant-pagination'); const paginations = document.querySelectorAll('.ant-pagination');
if (paginations) { if (paginations) {
paginations.forEach((pagination) => { paginations.forEach((pagination) => {
pagination.style.display = 'block'; pagination.style.display = 'flex';
}); });
} }
// //
@ -647,6 +660,19 @@
arr.graffitiJson = []; arr.graffitiJson = [];
} }
}); });
showTableData.value = result;
setTimeout(() => {
//
if (tableType.value === 'store') {
// -
const paginations = document.querySelectorAll('.ant-pagination');
if (paginations) {
paginations.forEach((pagination) => {
pagination.style.display = 'none';
});
}
}
}, 100);
return result; return result;
}, },
}); });
@ -683,8 +709,9 @@
// //
if (tableType.value == 'table') { if (tableType.value == 'table') {
reload(); reload();
} else { }
// //
if (tableType.value === 'store') {
getShowTableData(); getShowTableData();
} }
} }
@ -809,22 +836,61 @@
}); });
} }
//
const downloadAloneLoading = ref(false);
async function downloadAloneFile() {
//
let rows = getSelectRows();
if (tableType.value == 'store') {
rows = showTableData.value.filter((item) => item.checked);
}
if (rows.length != 1) {
return createMessage.warn('请选择一个文件进行下载');
}
if (!rows[0].objectKey) {
return createMessage.warn('单独下载只能下载非文件夹的文件');
}
try {
downloadAloneLoading.value = true;
const response = await fetch(VITE_GLOB_MEDIALIBRARY_IMAGE_URL + rows[0].objectKey, {
mode: 'cors',
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const blob = await response.blob();
const urlObject = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = urlObject;
link.download = rows[0].name || 'download';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(urlObject);
} catch (error) {
console.error('Error downloading image:', error);
} finally {
downloadAloneLoading.value = false;
}
}
// //
const downloadOpen = ref(false); const downloadZipOpen = ref(false);
const downloadLoading = ref(false); const downloadZipLoading = ref(false);
const downPercent = ref(0); const downloadZipPercent = ref(0);
// //
let downloadRows: any = []; let downloadRows: any = [];
const zipFileName = ref(''); const zipFileName = ref('');
// - // -
function downloadOpenMoadl() { function downloadZipOpenMoadl() {
// //
let rows = getSelectRows(); let rows = getSelectRows();
if (tableType.value == 'store') { if (tableType.value == 'store') {
rows = showTableData.value.filter((item) => item.checked); rows = showTableData.value.filter((item) => item.checked);
} }
if (rows.length == 0) { if (rows.length == 0) {
return createMessage.warn('请选择一个或者多个文件/文件夹进行删除'); return createMessage.warn('请选择一个或者多个文件/文件夹进行下载');
} }
zipFileName.value = '压缩文件' + dayjs().format('YYYY-MM-DD HH:mm:ss'); zipFileName.value = '压缩文件' + dayjs().format('YYYY-MM-DD HH:mm:ss');
if (floders.value.length > 1) { if (floders.value.length > 1) {
@ -834,12 +900,15 @@
zipFileName.value = rows[0].name; zipFileName.value = rows[0].name;
} }
downloadRows = rows; downloadRows = rows;
downloadOpen.value = true; downloadZipOpen.value = true;
} }
// - // -
async function downloadFile() { async function downloadZipFile() {
downloadOpen.value = false; if (!zipFileName.value) {
downloadLoading.value = true; return createMessage.warn('压缩包名称不能为空');
}
downloadZipOpen.value = false;
downloadZipLoading.value = true;
getFileList(downloadRows).then(async (res) => { getFileList(downloadRows).then(async (res) => {
let filelist: any = res; let filelist: any = res;
const token = localStorage.getItem('X-Token'); const token = localStorage.getItem('X-Token');
@ -863,7 +932,7 @@
console.error('请求失败:', error); console.error('请求失败:', error);
} finally { } finally {
index++; index++;
downPercent.value = parseFloat(((index / filelist.length) * 100).toFixed(2)); downloadZipPercent.value = parseFloat(((index / filelist.length) * 100).toFixed(2));
} }
} }
// ZIP // ZIP
@ -873,7 +942,7 @@
} catch (error) { } catch (error) {
console.error('生成ZIP文件时出错:', error); console.error('生成ZIP文件时出错:', error);
} finally { } finally {
downloadLoading.value = false; downloadZipLoading.value = false;
} }
}); });
} }
@ -1111,7 +1180,7 @@
flex-wrap: wrap; flex-wrap: wrap;
} }
.flodersname { .flodersname {
max-width: 120px; max-width: 240px;
white-space: nowrap; /* 禁止换行 */ white-space: nowrap; /* 禁止换行 */
overflow: hidden; /* 超出部分隐藏 */ overflow: hidden; /* 超出部分隐藏 */
text-overflow: ellipsis; /* 超出显示省略号 */ text-overflow: ellipsis; /* 超出显示省略号 */
@ -1199,4 +1268,8 @@
::v-deep .ant-modal-body { ::v-deep .ant-modal-body {
height: 100% !important; height: 100% !important;
} }
::v-deep .ant-pagination {
justify-content: flex-end !important;
}
</style> </style>

Loading…
Cancel
Save