mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-11-06 00:57:08 +08:00
refactor: 文件管理,重命名,下载,滚动查询
This commit is contained in:
@@ -22,6 +22,7 @@ export function downloadByUrl({
|
||||
url: string
|
||||
target?: '_self' | '_blank'
|
||||
fileName?: string
|
||||
isSameHost: boolean
|
||||
}): Promise<boolean> {
|
||||
// 是否同源
|
||||
const isSameHost = new URL(url).host == location.host
|
||||
@@ -49,28 +50,36 @@ export function downloadByUrl({
|
||||
window.open(url, target)
|
||||
return resolve(true)
|
||||
} else {
|
||||
const canvas = document.createElement('canvas')
|
||||
const img = document.createElement('img')
|
||||
img.setAttribute('crossOrigin', 'Anonymous')
|
||||
img.src = url
|
||||
img.onload = () => {
|
||||
canvas.width = img.width
|
||||
canvas.height = img.height
|
||||
const context = canvas.getContext('2d')!
|
||||
context.drawImage(img, 0, 0, img.width, img.height)
|
||||
// window.navigator.msSaveBlob(canvas.msToBlob(),'image.jpg');
|
||||
// saveAs(imageDataUrl, '附件');
|
||||
canvas.toBlob((blob) => {
|
||||
const link = document.createElement('a')
|
||||
if (!blob) return
|
||||
link.href = window.URL.createObjectURL(blob)
|
||||
link.download = getFileName(url)
|
||||
link.click()
|
||||
URL.revokeObjectURL(link.href)
|
||||
resolve(true)
|
||||
}, 'image/jpeg')
|
||||
}
|
||||
img.onerror = (e) => reject(e)
|
||||
const elink = document.createElement('a')
|
||||
elink.href = url
|
||||
elink.target = '_self'
|
||||
elink.download = fileName as string
|
||||
elink.style.display = 'none'
|
||||
document.body.appendChild(elink)
|
||||
elink.click()
|
||||
document.body.removeChild(elink)
|
||||
// const canvas = document.createElement('canvas')
|
||||
// const img = document.createElement('img')
|
||||
// img.setAttribute('crossOrigin', 'Anonymous')
|
||||
// img.src = url
|
||||
// img.onload = () => {
|
||||
// canvas.width = img.width
|
||||
// canvas.height = img.height
|
||||
// const context = canvas.getContext('2d')!
|
||||
// context.drawImage(img, 0, 0, img.width, img.height)
|
||||
// // window.navigator.msSaveBlob(canvas.msToBlob(),'image.jpg');
|
||||
// // saveAs(imageDataUrl, '附件');
|
||||
// canvas.toBlob((blob) => {
|
||||
// const link = document.createElement('a')
|
||||
// if (!blob) return
|
||||
// link.href = window.URL.createObjectURL(blob)
|
||||
// link.download = fileName || getFileName(url)
|
||||
// link.click()
|
||||
// URL.revokeObjectURL(link.href)
|
||||
// resolve(true)
|
||||
// }, 'image/jpeg')
|
||||
// }
|
||||
// img.onerror = (e) => reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user