From 6bcd30969bebffa7fd96c27501d27cceabad81b3 Mon Sep 17 00:00:00 2001 From: wangxiaoshuang <825034831@qq.com> Date: Thu, 11 Dec 2025 16:29:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=B7=BB=E5=8A=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=A7=E5=B0=8F=E6=8F=90=E9=86=92=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E8=BF=9B=E5=BA=A6=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/stream.js | 33 +++++++-- src/views/trials/trials-inspection/index.vue | 71 +++++++++++++++++--- 2 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/utils/stream.js b/src/utils/stream.js index a5a4622..3ee6276 100644 --- a/src/utils/stream.js +++ b/src/utils/stream.js @@ -39,9 +39,14 @@ function createFloders(obj, arr, r) { createFloders(obj[i], arr, r) } } -function zipFilesJsZip(zipName, files, obj = {}) { +function zipFilesJsZip(zipName, files, obj = {}, callback) { return new Promise(resolve => { try { + if (callback) { + callback({ + type: 'start' + }) + } console.log("同步下载打包开始时间:" + new Date()); files = formatFiles(files) const zip = new JSZip(); @@ -50,11 +55,22 @@ function zipFilesJsZip(zipName, files, obj = {}) { let res = getFile(file.url).then(r => { const arr = file.name.split('/') createFloders(obj, arr, r) + if (callback) { + callback({ + type: 'downLoad', + data: r + }) + } // zip.file(fileName, r, { binary: true }); }) all.push(res) }) Promise.all(all).then(() => { + if (callback) { + callback({ + type: 'downLoaded', + }) + } addFilesRecursively(zip, obj) zip.generateAsync({ type: "blob", @@ -63,10 +79,13 @@ function zipFilesJsZip(zipName, files, obj = {}) { level: 9 // 压缩等级1~9 1压缩速度最快,9最优压缩方式 } }).then((res) => { - FileSaver.saveAs(res, zipName, () => { - resolve(true) - console.log("同步下载打包结束时间:" + new Date()); - }) // 利用file-saver保存文件 + if (callback) { + callback({ + type: 'zipEnd', + }) + } + console.log("同步下载打包结束时间:" + new Date()); + FileSaver.saveAs(res, zipName) // 利用file-saver保存文件 }) }) } catch (err) { @@ -171,8 +190,8 @@ function decodeUtf8(bytes) { str2.pop(); return str2.join("/") + '/' + name; } -export async function downLoadFile(file, name, type = 'file') { - if (type === 'zip') return await zipFilesJsZip(name, file, {}); +export async function downLoadFile(file, name, type = 'file', callback) { + if (type === 'zip') return await zipFilesJsZip(name, file, {}, callback); return await updateFile(file, name) } \ No newline at end of file diff --git a/src/views/trials/trials-inspection/index.vue b/src/views/trials/trials-inspection/index.vue index a80c88f..710975d 100644 --- a/src/views/trials/trials-inspection/index.vue +++ b/src/views/trials/trials-inspection/index.vue @@ -214,6 +214,16 @@ + + + {{ $t('dialog:sattus:downLoading') }} + + + + {{ $t('dialog:sattus:ziping') }} + +