From e9cedbe9089fe1653f5e0ab3825f9bdd3eed7f20 Mon Sep 17 00:00:00 2001 From: zoujiandong <10130823232@qq.com> Date: Thu, 16 Nov 2023 09:56:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/downloadFile.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/downloadFile.js b/src/utils/downloadFile.js index 691e8f0..75a1e73 100644 --- a/src/utils/downloadFile.js +++ b/src/utils/downloadFile.js @@ -1,4 +1,7 @@ export const downloadFile=(fileUrl,name='')=>{ + let startIndex=fileUrl.indexOf("output"); + let endIndex=fileUrl.lastIndexOf("."); + let originName=fileUrl.substring(startIndex,endIndex); const request = new XMLHttpRequest() request.open('GET', fileUrl) request.responseType = 'blob' @@ -6,8 +9,8 @@ export const downloadFile=(fileUrl,name='')=>{ if (res.target.status == 200) { const url = window.URL.createObjectURL(res.currentTarget.response) const link = document.createElement('a') - link.href = url - link.setAttribute('download', name+new Date().getTime()) + link.href = url; + link.setAttribute('download',originName) link.click() } }