Skip to content

Commit

Permalink
fix:更换图片下载方式,修复点击下载之后跳转新标签页但不发起下载的问题 (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: aiden.chen <aiden.chen@ikotek.com>
  • Loading branch information
czh1998yr and aiden.chen committed Jul 15, 2023
1 parent 9844e4d commit 8eb46a4
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/views/Home/components/ChatList/ContextMenu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,25 @@ const download = () => {
const { body } = props.msg.message
const url = body?.url
if (!url) return
const a = document.createElement('a')
a.href = url
a.download = body.fileName || '未知文件'
a.click()
a.remove()
const xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onreadystatechange = () => {
// 下载失败提示
if (xhr.status != 200) return ElMessage.error('下载失败~')
if (xhr.readyState === 4 && xhr.status === 200) {
const blob = xhr.response
let link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.download = body.fileName || '未知文件'
link.dispatchEvent(new MouseEvent('click'))
link.remove()
}
}
xhr.send()
}
const onAddEmoji = () => {
Expand Down

0 comments on commit 8eb46a4

Please sign in to comment.