feat: download package

This commit is contained in:
Joel
2024-11-21 14:24:43 +08:00
parent b01c18ae7f
commit 11ed86f2a8
5 changed files with 48 additions and 3 deletions

View File

@ -34,3 +34,14 @@ export const formatTime = (num: number) => {
}
return `${num.toFixed(2)} ${units[index]}`
}
export const downloadFile = ({ data, fileName }: { data: Blob; fileName: string }) => {
const url = window.URL.createObjectURL(data)
const a = document.createElement('a')
a.href = url
a.download = fileName
document.body.appendChild(a)
a.click()
a.remove()
window.URL.revokeObjectURL(url)
}