|
|
@@ -143,21 +143,39 @@ const handleItemClick = (file) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const handleDownload = (file) => {
|
|
|
- const link = document.createElement('a')
|
|
|
- link.href = file.url
|
|
|
- link.download = file.name
|
|
|
- document.body.appendChild(link)
|
|
|
- link.click()
|
|
|
- document.body.removeChild(link)
|
|
|
+const handleDownload = async (file) => {
|
|
|
+ try {
|
|
|
+ const response = await fetch(file.url, {
|
|
|
+ headers: { authorization: 'Bearer ' + getAccessToken() }
|
|
|
+ })
|
|
|
+ if (!response.ok) {
|
|
|
+ ElMessage.error('下载失败')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const blob = await response.blob()
|
|
|
+ const blobUrl = URL.createObjectURL(blob)
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.href = blobUrl
|
|
|
+ link.download = file.name || ''
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+ document.body.removeChild(link)
|
|
|
+ URL.revokeObjectURL(blobUrl)
|
|
|
+ } catch {
|
|
|
+ ElMessage.error('下载失败')
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const handleRemove = (file) => {
|
|
|
const newList = [...props.fileList]
|
|
|
+ const fileUrl = file.url
|
|
|
const index = newList.findIndex(f => {
|
|
|
+ // uid 优先匹配
|
|
|
if (file.uid && f.uid) return f.uid === file.uid
|
|
|
- if (file.url && f.url) return f.url === file.url
|
|
|
- return f.name === file.name
|
|
|
+ // url 统一经过 buildFileUrl 处理后比较
|
|
|
+ const fUrl = f.url || f.path || ''
|
|
|
+ const builtFUrl = buildFileUrl(fUrl)
|
|
|
+ return builtFUrl === fileUrl
|
|
|
})
|
|
|
if (index > -1) {
|
|
|
newList.splice(index, 1)
|