mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-09 19:06:49 +08:00
feat(knowledge): 切换下载模板的方式
1. 由创建 a 链接的方式换成 window.open 2. 更改获取 链接的 方式
This commit is contained in:
@@ -26,9 +26,9 @@ export function getRuleList(data = {}) {
|
||||
* 下载知识文件模板
|
||||
*/
|
||||
export function downloadKnowledgeTemplate() {
|
||||
return request({
|
||||
return {
|
||||
url: getUrl('/datasetDocumentEx/download'),
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,38 +114,8 @@ export default {
|
||||
this.$emit('getFileType', this.form.radio)
|
||||
},
|
||||
downloadTemplate() {
|
||||
downloadKnowledgeTemplate().then((res) => {
|
||||
// 创建Blob URL
|
||||
const blob = new Blob([res.data])
|
||||
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
|
||||
console.log(`blob url: `, url)
|
||||
// 创建一个临时a标签并触发点击
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
|
||||
// 尝试从响应头获取文件名,如果没有则使用默认名称
|
||||
// const contentDisposition = res.headers['content-disposition']
|
||||
// console.log(`content-disposition: `, contentDisposition)
|
||||
let filename = '知识文件模板.pdf'
|
||||
// if (contentDisposition) {
|
||||
// const filenameMatch = contentDisposition.match(/filename="?(.+)"?/)
|
||||
// if (filenameMatch && filenameMatch[1]) {
|
||||
// filename = filenameMatch[1]
|
||||
// }
|
||||
// }
|
||||
|
||||
link.setAttribute('download', filename)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
|
||||
// 清理
|
||||
window.URL.revokeObjectURL(url)
|
||||
document.body.removeChild(link)
|
||||
}).catch(error => {
|
||||
this.$message.error(error)
|
||||
})
|
||||
console.log(`下载模板的链接是:${downloadKnowledgeTemplate().url}`)
|
||||
window.open(downloadKnowledgeTemplate().url, '_blank')
|
||||
},
|
||||
|
||||
// 生成filed
|
||||
|
||||
Reference in New Issue
Block a user