From b36bef307b515401c4ff0d7c278e95920389e5c9 Mon Sep 17 00:00:00 2001 From: leviathan233 <1209712383@qq.com> Date: Wed, 1 Nov 2023 00:22:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=89=E6=95=B0=E6=8D=AE=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/face/Single.vue | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/views/face/Single.vue b/src/views/face/Single.vue index 10e147233..71481765a 100644 --- a/src/views/face/Single.vue +++ b/src/views/face/Single.vue @@ -122,7 +122,7 @@ 版本 : {{ item.created_at }} 备注 : {{ item.describe }} - 下载 + 下载 @@ -448,11 +448,51 @@ export default { this.loading = false; }); }, - getDownUrl(uuid) { + getDownUrl(uuid, filename) { getDownUrl(this.id, uuid).then((res) => { - window.location.href = resolveImagePath(res.data.data?.url); + // window.location.href = resolveImagePath(res.data.data?.url); + this.downloadfile(res.data.data?.url, filename) }); }, + downloadfile(url, filename) { + this.getBlob(url).then((blob) => { + this.saveAs(blob, filename); + }); + }, + getBlob(url) { + return new Promise((resolve) => { + const xhr = new XMLHttpRequest(); + + xhr.open('GET', url, true); + xhr.responseType = 'blob'; + xhr.onload = () => { + if (xhr.status === 200) { + resolve(xhr.response); + } + }; + + xhr.send(); + }); + }, + saveAs(blob, filename) { + if (window.navigator.msSaveOrOpenBlob) { + navigator.msSaveBlob(blob, filename); + } else { + const link = document.createElement('a'); + const body = document.querySelector('body'); + + link.href = window.URL.createObjectURL(blob); + link.download = filename; + // fix Firefox + link.style.display = 'none'; + body.appendChild(link); + + link.click(); + body.removeChild(link); + + window.URL.revokeObjectURL(link.href); + } + }, downloadAll() { const urlArr = [] this.downFileList.forEach(item => { @@ -463,7 +503,7 @@ export default { p.then(arr => { downloadFiles = arr.map((item, index) => { return { - name: this.downFileList[index].name + '.jx3dat', + name: this.downFileList[index].name, url: item.data.data?.url } })