|
@@ -784,26 +784,52 @@ export default {
|
|
this.getList(); // 刷新文件列表
|
|
this.getList(); // 刷新文件列表
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ // handleDownload(row) {
|
|
|
|
+ // // if (!row || !row.fileId) {
|
|
|
|
+ // // this.$message.error('文件 ID 无效,无法下载')
|
|
|
|
+ // // return
|
|
|
|
+ // // }
|
|
|
|
+ // try {
|
|
|
|
+ // // this.loading = true
|
|
|
|
+ // const response = download(row.fileId)
|
|
|
|
+ // console.log(response)
|
|
|
|
+ // this.parseBlob(response, row.fileId)
|
|
|
|
+ // // if (response.status === 200) {
|
|
|
|
+ // // this.parseBlob(response, '文件名.pdf')
|
|
|
|
+ // // // const blob = new Blob([response.data], {type: 'application/octet-stream'})
|
|
|
|
+ // // // saveAs(blob, row.fileName)
|
|
|
|
+ // // this.$message.success('文件下载成功')
|
|
|
|
+ // // } else {
|
|
|
|
+ // // this.$message.error('文件下载失败,响应状态码异常')
|
|
|
|
+ // // }
|
|
|
|
+ // } catch (error) {
|
|
|
|
+ // console.error('文件下载出错:', error)
|
|
|
|
+ // this.$message.error('文件下载失败,请重试')
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
async handleDownload(row) {
|
|
async handleDownload(row) {
|
|
- if (!row || !row.fileId) {
|
|
|
|
- this.$message.error('文件 ID 无效,无法下载')
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
try {
|
|
try {
|
|
- this.loading = true
|
|
|
|
- const response = await download(row.fileId)
|
|
|
|
|
|
+ // 等待Promise解析,获取响应对象
|
|
|
|
+ const response = await download(row.fileId) // fileId替换为实际的文件标识
|
|
|
|
+ console.log(response)
|
|
|
|
+ // 使用若依封装的download方法(推荐,自动处理下载)
|
|
|
|
+ // const fileName = response.headers['content-disposition']
|
|
|
|
+ // ? decodeURIComponent(response.headers['content-disposition'].split('filename=')[1])
|
|
|
|
+ // : 'defaultFileName'
|
|
this.parseBlob(response, row.fileName)
|
|
this.parseBlob(response, row.fileName)
|
|
- // if (response.status === 200) {
|
|
|
|
- // this.parseBlob(response, '文件名.pdf')
|
|
|
|
- // // const blob = new Blob([response.data], {type: 'application/octet-stream'})
|
|
|
|
- // // saveAs(blob, row.fileName)
|
|
|
|
- // this.$message.success('文件下载成功')
|
|
|
|
- // } else {
|
|
|
|
- // this.$message.error('文件下载失败,响应状态码异常')
|
|
|
|
- // }
|
|
|
|
|
|
+
|
|
|
|
+ // 或者手动处理(了解原理)
|
|
|
|
+ /* const blob = response.data
|
|
|
|
+ const url = window.URL.createObjectURL(blob)
|
|
|
|
+ const link = document.createElement('a')
|
|
|
|
+ link.href = url
|
|
|
|
+ link.download = fileName
|
|
|
|
+ document.body.appendChild(link)
|
|
|
|
+ link.click()
|
|
|
|
+ document.body.removeChild(link)
|
|
|
|
+ window.URL.revokeObjectURL(url) */
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('文件下载出错:', error)
|
|
|
|
- this.$message.error('文件下载失败,请重试')
|
|
|
|
|
|
+ this.$modal.msgError('下载失败:' + error.message)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
parseBlob(blob, fileName) {
|
|
parseBlob(blob, fileName) {
|