From 94ca89db27aab508c439de360870ff6930c590de Mon Sep 17 00:00:00 2001 From: "DESKTOP-6C3NK6N\\WXS" <815034831@qq.com> Date: Mon, 22 Jul 2024 18:02:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E6=8E=A7=E4=B8=8B=E8=BD=BD=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/trials.js | 3 + src/utils/uploadZip.js | 214 +++++++----------- .../qc-check/components/qualityAssurance.vue | 37 +-- 3 files changed, 106 insertions(+), 148 deletions(-) diff --git a/src/store/modules/trials.js b/src/store/modules/trials.js index 609faffa..33a1e7d4 100644 --- a/src/store/modules/trials.js +++ b/src/store/modules/trials.js @@ -9,6 +9,9 @@ const getDefaultState = () => { studyListQuery: null, unlock: false, config: {}, + uploadTip: null, + timer: null, + whiteList: [] } } diff --git a/src/utils/uploadZip.js b/src/utils/uploadZip.js index fdb48835..436e292f 100644 --- a/src/utils/uploadZip.js +++ b/src/utils/uploadZip.js @@ -1,17 +1,21 @@ -import JSZip from "jszip"; -import { saveAs } from "file-saver"; import Vue from 'vue'; import { requestPackageAndAnonymizImage, } from "@/api/load.js"; import streamSaver from "streamsaver"; import "streamsaver/examples/zip-stream.js" +import store from '@/store'; let flag = {}; export const resetFlag = () => { - flag = {} + flag = {}; + if (store.state.trials.timer) { + clearInterval(store.state.trials.timer); + store.state.trials.timer = null; + } } export const downloadImage = async (id, id2, IsDicom = true) => { - if (flag[`${id2}_${IsDicom}`]) return Vue.prototype.$message.warning(Vue.prototype.$t('trials:upload:tip:uploading')); + // if (flag[`${id2}_${IsDicom}`]) return Vue.prototype.$message.warning(Vue.prototype.$t('trials:upload:tip:uploading')); + if (flag[`${id2}_${IsDicom}`]) return false; flag[`${id2}_${IsDicom}`] = true try { let params = { @@ -23,26 +27,42 @@ export const downloadImage = async (id, id2, IsDicom = true) => { if (res.IsSuccess) { if (!res.Result) { flag[`${id2}_${IsDicom}`] = false; - Vue.prototype.$message.warning(Vue.prototype.$t("trials:upload:message:not")) - return 1; + // Vue.prototype.$message.warning(Vue.prototype.$t("trials:upload:message:not")) + let message = Vue.prototype.$t('trials:upload:tip:uploading').replace("xxx", res.OtherInfo.FileName); + store.state.trials.uploadTip = message; + console.log(store.state.trials.timer) + if (!store.state.trials.timer) { + store.state.trials.timer = setInterval(() => { + downloadImage(id, id2, IsDicom); + }, 2000); + } + return false; } - Vue.prototype.$message.success(Vue.prototype.$t("trials:upload:message:startUpload")); + if (store.state.trials.timer) { + clearInterval(store.state.trials.timer); + store.state.trials.timer = null; + } + let fileName = res.Result.split("/").pop(); let href = Vue.prototype.OSSclientConfig.basePath + res.Result; - download(href, res.OtherInfo.FileName, { id2, IsDicom }) - return 2; - // let a = document.createElement("a"); - // // let fileName = - // // res.Result.split("/")[res.Result.split("/").length - 1]; - // a.download = res.OtherInfo.FileName; - // a.href = href; - // a.click(); - // URL.revokeObjectURL(href); - // let timer = setTimeout(() => { - // a = null; - // href = null; - // timer = null; - // }, 500) - // return 2; + if (fileName !== res.OtherInfo.FileName) { + let message = Vue.prototype.$t('trials:upload:tip:uploading').replace("xxx", res.OtherInfo.FileName); + store.state.trials.uploadTip = message; + // Vue.prototype.$message.success(Vue.prototype.$t("trials:upload:message:startUpload")); + return download(href, res.OtherInfo.FileName, { id2, IsDicom }); + + } + let a = document.createElement("a"); + a.download = res.OtherInfo.FileName; + a.href = href; + a.click(); + URL.revokeObjectURL(href); + let timer = setTimeout(() => { + a = null; + href = null; + timer = null; + }, 500) + store.state.trials.uploadTip = null; + return true; } else { flag[`${id2}_${IsDicom}`] = false; return false; @@ -52,118 +72,6 @@ export const downloadImage = async (id, id2, IsDicom = true) => { console.log(err); } }; -const setfolder = async (item) => { - const zip = new JSZip(); // 创建实例对象 - let patientIds = item.PatientList.map(i => i.PatientIdStr); - let zipName = `${item.SubjectCode}_${patientIds.join(',')}`; - let zipObj = {}; - const promises = []; - for (let visit of item.VisitList) { - if (!zipObj[`${visit.VisitName}`]) { - zipObj[`${visit.VisitName}`] = zip.folder(visit.VisitName); - } - for (let study of visit.StudyList) { - let date = study.StudyTime.split(" ")[0]; - for (let series of study.SeriesList) { - if ( - !zipObj[ - `${visit.VisitName}${series.Modality}` - ] - ) { - zipObj[ - `${visit.VisitName}${series.Modality}` - ] = zipObj[`${visit.VisitName}`].folder( - `${date}_${series.Modality}` - ); - } - for (let instance of series.InstancePathList) { - let obj = { - subjectCode: item.SubjectCode, - visitName: visit.VisitName, - date: study.StudyTime.split(" ")[0], - modality: series.Modality, - instancePath: instance.Path, - dicomName: instance.Path.split("/Dicom/")[1], - }; - const promise = handleBatchDown( - obj, - zipObj[ - `${visit.VisitName}${series.Modality}` - ], - ); - promises.push(promise); - } - } - } - } - // 生成 zip 文件 - Promise.all(promises) - .then(() => { - // 生成zip 文件 - zip - .generateAsync({ - type: "blob", - compression: "DEFLATE", // STORE: 默认不压缩, DEFLATE:需要压缩 - compressionOptions: { - level: 9, // 压缩等级 1~9 1 压缩速度最快, 9 最优压缩方式 - }, - }) - .then((res) => { - saveAs(res, zipName + ".zip"); // 使用FileSaver.saveAs保存文件,文件名可自定义 - flag[`${id2}_${IsDicom}`] = false; - zipObj = null; - }); - }) - .catch((reason) => { flag[`${id2}_${IsDicom}`] = false; }); -}; -const handleBatchDown = async (item, zip) => { - return new Promise((resolve) => { - console.log("同步下载打包开始时间:" + new Date()); - // 创建压缩文件输出流 - const zipFileOutputStream = streamSaver.createWriteStream(zipName); - // 创建下载文件流 - const fileIterator = files.values(); - const readableZipStream = new window.ZIP({ - async pull(ctrl) { - const fileInfo = fileIterator.next(); - if (fileInfo.done) {//迭代终止 - ctrl.close(); - } else { - const { name, url } = fileInfo.value; - return fetch(url).then(res => { - ctrl.enqueue({ - name, - stream: () => res.body - }) - }) - } - } - }); - if (window.WritableStream && readableZipStream.pipeTo) { - // 开始下载 - readableZipStream - .pipeTo(zipFileOutputStream) - .then(() => { console.log("同步下载打包结束时间:" + new Date()); resolve(true) }) - } else { - resolve(false); - } - }) - -}; -const getFileData = (fileUrl) => { - return new Promise((resolve, reject) => { - axios(fileUrl, { - method: "GET", - responseType: "blob", // 返回的数据会被强制转为blob类型 ,转换成arraybuffer 也行 - }) - .then((res) => { - resolve(res); - }) - .catch((error) => { - reject(error); - }); - }); -}; export const fileDownload = (content, filename) => { const eleLink = document.createElement("a"); eleLink.download = filename; @@ -177,7 +85,9 @@ export const fileDownload = (content, filename) => { let download = async (downloadUrl, downloadFileName, res) => { const blob = await getBlob(downloadUrl); flag[`${res.id2}_${res.IsDicom}`] = false; + store.state.trials.uploadTip = null; saveAsB(blob, downloadFileName); + return true; } let getBlob = (url) => { @@ -217,3 +127,39 @@ let saveAsB = (blob, filename) => { window.URL.revokeObjectURL(link.href); } + +// 前端流式打包下载 +const handleBatchDown = async (item, zip) => { + return new Promise((resolve) => { + console.log("同步下载打包开始时间:" + new Date()); + // 创建压缩文件输出流 + const zipFileOutputStream = streamSaver.createWriteStream(zipName); + // 创建下载文件流 + const fileIterator = files.values(); + const readableZipStream = new window.ZIP({ + async pull(ctrl) { + const fileInfo = fileIterator.next(); + if (fileInfo.done) {//迭代终止 + ctrl.close(); + } else { + const { name, url } = fileInfo.value; + return fetch(url).then(res => { + ctrl.enqueue({ + name, + stream: () => res.body + }) + }) + } + } + }); + if (window.WritableStream && readableZipStream.pipeTo) { + // 开始下载 + readableZipStream + .pipeTo(zipFileOutputStream) + .then(() => { console.log("同步下载打包结束时间:" + new Date()); resolve(true) }) + } else { + resolve(false); + } + }) + +}; diff --git a/src/views/trials/trials-panel/visit/qc-check/components/qualityAssurance.vue b/src/views/trials/trials-panel/visit/qc-check/components/qualityAssurance.vue index 3b1dc947..983ce363 100644 --- a/src/views/trials/trials-panel/visit/qc-check/components/qualityAssurance.vue +++ b/src/views/trials/trials-panel/visit/qc-check/components/qualityAssurance.vue @@ -42,7 +42,13 @@ -