指控下载提示修改
parent
b786c5e656
commit
94ca89db27
|
@ -9,6 +9,9 @@ const getDefaultState = () => {
|
|||
studyListQuery: null,
|
||||
unlock: false,
|
||||
config: {},
|
||||
uploadTip: null,
|
||||
timer: null,
|
||||
whiteList: []
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
})
|
||||
|
||||
};
|
||||
|
|
|
@ -42,7 +42,13 @@
|
|||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div style="text-align: right">
|
||||
<div style="text-align: right; position: relative">
|
||||
<div
|
||||
class="uploadTip"
|
||||
style="position: absolute; top: 0; left: 0"
|
||||
>
|
||||
{{ $store.state.trials.uploadTip }}
|
||||
</div>
|
||||
<!-- 下载所有影像 -->
|
||||
<el-button
|
||||
v-if="$store.state.trials.config.IsSupportQCDownloadImage"
|
||||
|
@ -294,7 +300,13 @@
|
|||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div style="text-align: right">
|
||||
<div style="text-align: right; position: relative">
|
||||
<div
|
||||
class="uploadTip"
|
||||
style="position: absolute; top: 0; left: 0"
|
||||
>
|
||||
{{ $store.state.trials.uploadTip }}
|
||||
</div>
|
||||
<!-- 下载所有影像 -->
|
||||
<el-button
|
||||
v-if="$store.state.trials.config.IsSupportQCDownloadImage"
|
||||
|
@ -366,7 +378,10 @@
|
|||
<!-- 预览 -->
|
||||
<el-button
|
||||
type="text"
|
||||
:disabled="files.row.FileType && files.row.FileType.indexOf('zip') >= 0"
|
||||
:disabled="
|
||||
files.row.FileType &&
|
||||
files.row.FileType.indexOf('zip') >= 0
|
||||
"
|
||||
@click.native.prevent="previewFile(files.row)"
|
||||
>
|
||||
{{ $t("trials:audit:button:nonDicomsPreview") }}
|
||||
|
@ -1218,7 +1233,7 @@ import SignForm from "@/views/trials/components/newSignForm";
|
|||
import { getToken } from "@/utils/auth";
|
||||
import const_ from "@/const/sign-code";
|
||||
import uploadPetClinicalData from "@/views/trials/trials-panel/visit/crc-upload/components/uploadPetClinicalData.vue";
|
||||
import { downloadImage , resetFlag } from "@/utils/uploadZip.js";
|
||||
import { downloadImage, resetFlag } from "@/utils/uploadZip.js";
|
||||
export default {
|
||||
name: "QualityAssurance",
|
||||
components: {
|
||||
|
@ -1331,9 +1346,6 @@ export default {
|
|||
BodyPart: {},
|
||||
};
|
||||
},
|
||||
beforeDestroy(){
|
||||
resetFlag();
|
||||
},
|
||||
async mounted() {
|
||||
this.BodyPart.Bodypart = await this.$getBodyPart(this.$route.query.trialId);
|
||||
if (this.disabled) {
|
||||
|
@ -1354,16 +1366,13 @@ export default {
|
|||
if (this.open) {
|
||||
this.open.close();
|
||||
}
|
||||
resetFlag();
|
||||
},
|
||||
methods: {
|
||||
// 打包下载
|
||||
async downloadImage(IsDicom) {
|
||||
try {
|
||||
await downloadImage(
|
||||
this.$route.query.trialId,
|
||||
this.data.Id,
|
||||
IsDicom
|
||||
);
|
||||
await downloadImage(this.$route.query.trialId, this.data.Id, IsDicom);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -2229,7 +2238,7 @@ export default {
|
|||
this.open.close();
|
||||
}
|
||||
// this.previewAllNoneDicomVisible = true
|
||||
let trialId = this.$route.query.trialId
|
||||
let trialId = this.$route.query.trialId;
|
||||
var token = getToken();
|
||||
const routeData = this.$router.resolve({
|
||||
path: `/showNoneDicoms?trialId=${trialId}&subjectVisitId=${this.data.Id}&TokenKey=${token}`,
|
||||
|
@ -2241,7 +2250,7 @@ export default {
|
|||
if (this.open) {
|
||||
this.open.close();
|
||||
}
|
||||
let trialId = this.$route.query.trialId
|
||||
let trialId = this.$route.query.trialId;
|
||||
var token = getToken();
|
||||
const routeData = this.$router.resolve({
|
||||
path: `/showNoneDicoms?trialId=${trialId}&subjectVisitId=${this.data.Id}&studyId=${row.Id}&TokenKey=${token}`,
|
||||
|
|
Loading…
Reference in New Issue