diff --git a/src/views/backOfficeSystem/HumanIntelligence/fileOrientation/index.vue b/src/views/backOfficeSystem/HumanIntelligence/fileOrientation/index.vue index 7e6f9fa..b8c841c 100644 --- a/src/views/backOfficeSystem/HumanIntelligence/fileOrientation/index.vue +++ b/src/views/backOfficeSystem/HumanIntelligence/fileOrientation/index.vue @@ -177,54 +177,36 @@ const previewFile = (item) => { window.open(item.wjdz); } const downloadFile = async (item) => { - console.log(item); try { const dataList =JSON.parse(item.wjdz) - if (dataList.length === 0) { - proxy.$message.warning('没有文件可下载'); - return; - } -console.log(dataList); - + if (dataList.length === 0) return proxy.$message.warning('没有文件可下载'); const downloadCount = dataList.length; let successCount = 0; let failCount = 0; - proxy.$message.info(`开始下载${downloadCount}个文件...`); - - // 并行下载所有文件 - const downloadPromises = dataList.map(async (fileData, index) => { - + const downloadPromises = dataList.map(async (fileData, index) => { try { + // fileData.url = "http://47.108.232.77:9000/image/2025-01-06/081102a5418e4146beea277d18018e07.jpeg"; // 使用fetch获取文件内容 - const response = await fetch(fileData.url); - if (!response.ok) { - throw new Error('文件下载失败'); - } - + const downloadUrl = fileData.url.replace(/^https?:\/\/[^/]+/, '/zyminio'); + const response = await fetch(downloadUrl); + if (!response.ok) throw new Error('文件下载失败'); // 将响应转换为Blob对象 const blob = await response.blob(); - // 创建下载链接 const downloadLink = document.createElement('a'); downloadLink.href = URL.createObjectURL(blob); - // 设置下载文件的名称,避免冲突 - const fileName = dataList.length > 1 - ? `${item.wjmc}_${index + 1}` - : item.wjmc; + const fileName = dataList.length > 1 ? `${item.wjmc}_${index + 1}` : item.wjmc; downloadLink.download = fileName; - // 触发下载 document.body.appendChild(downloadLink); downloadLink.click(); - // 清理 setTimeout(() => { document.body.removeChild(downloadLink); URL.revokeObjectURL(downloadLink.href); }, 100); - successCount++; } catch (error) { console.error(`文件${index + 1}下载失败:`, error);