| | |
| | | this.axios.post(this.$api.url.saleDownload, { |
| | | id: row.id |
| | | }).then(res => { |
| | | // console.log(res.data); |
| | | // 循环遍历每个文件并创建下载链接 |
| | | for (let index = 0; index < 2; index++) { |
| | | const element = res.data[0]; |
| | | // 创建一个链接元素 |
| | | var a = document.createElement('a'); |
| | | const fileUrls = []; // 文件的urls |
| | | res.data.forEach(item=>{ |
| | | let url=baseIp+item |
| | | fileUrls.push(url) |
| | | }) |
| | | const downloadFile = (url, fileName) => { |
| | | const link = document.createElement('a'); |
| | | link.href = url; |
| | | link.download = fileName; |
| | | // link.style.display = 'none'; |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | document.body.removeChild(link); |
| | | }; |
| | | |
| | | // 设置链接元素的href属性为文件的URL |
| | | a.href = baseIp+element; |
| | | |
| | | // // 设置链接元素的download属性为文件名 |
| | | a.download = row.name+"附件"+(index+1); |
| | | |
| | | // 模拟点击链接以触发下载 |
| | | a.click(); |
| | | |
| | | // |
| | | a.remove() |
| | | } |
| | | console.log(fileUrls); |
| | | fileUrls.forEach((url, index) => { |
| | | let s=url.split(".") |
| | | const fileName = row.name+`附件(${index + 1}).`+s[s.length-1]; |
| | | downloadFile(url, fileName); |
| | | }); |
| | | }) |
| | | }, |
| | | closeDialog() { |