Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:更换图片下载方式,修复点击下载之后跳转新标签页但不发起下载的问题 #86

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -70,11 +70,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 onDelete = () => chatStore.deleteMsg(props.msg.message.id)
Expand Down