From 23a04dba723a840a0c23b5c076093561ad2d77ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BB=95=E5=B5=A9?= <17854119262@163.com> Date: Mon, 18 Aug 2025 16:46:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AA=92=E4=BD=93=E5=BA=93-=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E3=80=81=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?bug=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/system/mediaLibrary/LeftTree.vue | 8 +- src/views/demo/system/mediaLibrary/index.vue | 119 ++++++++++++++---- 2 files changed, 100 insertions(+), 27 deletions(-) diff --git a/src/views/demo/system/mediaLibrary/LeftTree.vue b/src/views/demo/system/mediaLibrary/LeftTree.vue index b6dff1c..f42c82e 100644 --- a/src/views/demo/system/mediaLibrary/LeftTree.vue +++ b/src/views/demo/system/mediaLibrary/LeftTree.vue @@ -27,10 +27,10 @@ id: 'meitiku', name: '媒体库', children: [ - { - id: '', - name: '全部资源', - }, + // { + // id: '', + // name: '全部资源', + // }, { id: '1', name: '可见光', diff --git a/src/views/demo/system/mediaLibrary/index.vue b/src/views/demo/system/mediaLibrary/index.vue index d20c109..54cf51c 100644 --- a/src/views/demo/system/mediaLibrary/index.vue +++ b/src/views/demo/system/mediaLibrary/index.vue @@ -20,17 +20,30 @@ 新建文件夹 移动 删除 + + 单独下载 + 批量下载 @@ -306,7 +319,7 @@
-
批量下载会先进行压缩成一个文件,后续再下载
+
批量下载会先进行压缩成一个文件,然后再下载
压缩包名称:
@@ -484,7 +497,7 @@ const paginations = document.querySelectorAll('.ant-pagination'); if (paginations) { paginations.forEach((pagination) => { - pagination.style.display = 'block'; + pagination.style.display = 'flex'; }); } // 选中:格子→表格 @@ -647,6 +660,19 @@ 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; }, }); @@ -683,8 +709,9 @@ // 表格 if (tableType.value == 'table') { reload(); - } else { - // 格子 + } + // 格子 + if (tableType.value === 'store') { 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 downloadLoading = ref(false); - const downPercent = ref(0); + const downloadZipOpen = ref(false); + const downloadZipLoading = ref(false); + const downloadZipPercent = ref(0); + // 压缩文件名 let downloadRows: any = []; const zipFileName = ref(''); // 批量下载-窗口 - function downloadOpenMoadl() { + function downloadZipOpenMoadl() { // 获得所选 let rows = getSelectRows(); if (tableType.value == 'store') { rows = showTableData.value.filter((item) => item.checked); } if (rows.length == 0) { - return createMessage.warn('请选择一个或者多个文件/文件夹进行删除'); + return createMessage.warn('请选择一个或者多个文件/文件夹进行下载'); } zipFileName.value = '压缩文件' + dayjs().format('YYYY-MM-DD HH:mm:ss'); if (floders.value.length > 1) { @@ -834,12 +900,15 @@ zipFileName.value = rows[0].name; } downloadRows = rows; - downloadOpen.value = true; + downloadZipOpen.value = true; } // 批量下载-下载 - async function downloadFile() { - downloadOpen.value = false; - downloadLoading.value = true; + async function downloadZipFile() { + if (!zipFileName.value) { + return createMessage.warn('压缩包名称不能为空'); + } + downloadZipOpen.value = false; + downloadZipLoading.value = true; getFileList(downloadRows).then(async (res) => { let filelist: any = res; const token = localStorage.getItem('X-Token'); @@ -863,7 +932,7 @@ console.error('请求失败:', error); } finally { index++; - downPercent.value = parseFloat(((index / filelist.length) * 100).toFixed(2)); + downloadZipPercent.value = parseFloat(((index / filelist.length) * 100).toFixed(2)); } } // 生成ZIP文件并触发下载 @@ -873,7 +942,7 @@ } catch (error) { console.error('生成ZIP文件时出错:', error); } finally { - downloadLoading.value = false; + downloadZipLoading.value = false; } }); } @@ -1111,7 +1180,7 @@ flex-wrap: wrap; } .flodersname { - max-width: 120px; + max-width: 240px; white-space: nowrap; /* 禁止换行 */ overflow: hidden; /* 超出部分隐藏 */ text-overflow: ellipsis; /* 超出显示省略号 */ @@ -1199,4 +1268,8 @@ ::v-deep .ant-modal-body { height: 100% !important; } + + ::v-deep .ant-pagination { + justify-content: flex-end !important; + }