From 5aa3e8b2e3eda6a39b3c07bf9f8abc297df7fadf Mon Sep 17 00:00:00 2001 From: xiao-fajia <1665375861@qq.com> Date: Thu, 29 Aug 2024 19:18:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=A3=E6=A1=88=E7=AE=A1=E7=90=863?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- src/components/FileUpload2/index.vue | 25 +++ src/utils/downloadZIP.js | 29 +++ .../archives/components/ArchivesTable.vue | 80 ++++++- .../archives/form/ArchivesCatalogForm.vue | 33 ++- .../views/archives/form/ArchivesForm.vue | 13 +- .../views/archives/form/ArchivesShowForm.vue | 199 ++++++++++++++++++ 7 files changed, 362 insertions(+), 20 deletions(-) create mode 100644 src/utils/downloadZIP.js create mode 100644 src/views/knowledge/views/archives/form/ArchivesShowForm.vue diff --git a/package.json b/package.json index 6c2d691..57ccf95 100644 --- a/package.json +++ b/package.json @@ -52,11 +52,12 @@ "dayjs": "^1.11.12", "echarts": "5.4.0", "element-ui": "2.15.12", - "file-saver": "2.0.5", + "file-saver": "^2.0.5", "fuse.js": "6.6.2", "highlight.js": "9.18.5", "js-beautify": "1.13.0", "jsencrypt": "3.3.1", + "jszip": "^3.10.1", "min-dash": "3.5.2", "nprogress": "0.2.0", "qrcode.vue": "^1.7.0", diff --git a/src/components/FileUpload2/index.vue b/src/components/FileUpload2/index.vue index e7873ad..5183ce4 100644 --- a/src/components/FileUpload2/index.vue +++ b/src/components/FileUpload2/index.vue @@ -98,8 +98,13 @@ export default { return this.isShowTip && (this.fileType || this.fileSize); }, }, + mounted(){ + //加载文件列表 + this.initFiles() + }, watch: { value(val) { + if (val) { let temp = 1; const list = Array.isArray(val)? val : this.value.split(","); @@ -116,6 +121,26 @@ export default { }, }, methods: { + /** + * 手动加载文件列表,为了解决本组件value值变化可能会出现监听不到的情况 + */ + initFiles(){ + if(this.fileList.length==0){ + // 不存在就是新增,新增时直接返回,不然要报错 + if (!this.value){ + return; + } + let temp = 1; + const list = Array.isArray(this.value)? this.value : this.value.split(","); + this.fileList = list.map((item) => { + if (typeof item === "string") { + item = { name: item, url: item }; + } + item.uid = item.uid || new Date().getTime() + temp++; + return item; + }); + } + }, handleBeforeUpload(file) { if (this.fileType.length) { const name = file.name.split("."); diff --git a/src/utils/downloadZIP.js b/src/utils/downloadZIP.js new file mode 100644 index 0000000..444554c --- /dev/null +++ b/src/utils/downloadZIP.js @@ -0,0 +1,29 @@ +import JSZip from 'jszip' +import { saveAs } from 'file-saver' + +export async function downloadFilesAsZip(fileObject) { + const zip = new JSZip() + for (const item of fileObject.files) { + try { + const response = await fetch(item.url) + if (!response.ok) { + throw new Error(`下载失败 ${item.url}: ${response.status}`) + } + const blob = await response.blob() + // 提取文件名,假设文件路径中最后一部分为文件名 + const fileName = item.name + zip.file(fileName, blob) + } catch (error) { + console.error(`下载失败 ${item.url}:`, error) + } + } + + // 生成压缩文件 + try { + const content = await zip.generateAsync({ type: 'blob' }); + // 保存压缩文件 + saveAs(content, fileObject.zipName); + } catch (error) { + console.error('生成ZIP错误', error); + } +} diff --git a/src/views/knowledge/views/archives/components/ArchivesTable.vue b/src/views/knowledge/views/archives/components/ArchivesTable.vue index 46282b1..d974eda 100644 --- a/src/views/knowledge/views/archives/components/ArchivesTable.vue +++ b/src/views/knowledge/views/archives/components/ArchivesTable.vue @@ -34,6 +34,7 @@ :filter-node-method="filterNode" @node-click="handleNodeClick" highlight-current + :default-checked-keys="[chooseData.id]" >