mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-19 15:25:19 +00:00
30
resources/scripts/helpers/csv-export.js
vendored
30
resources/scripts/helpers/csv-export.js
vendored
@@ -1,30 +0,0 @@
|
||||
import http from '@/scripts/http/index.js'
|
||||
|
||||
export async function downloadCsvExport(url, params = {}) {
|
||||
const response = await http.get(url, {
|
||||
params,
|
||||
responseType: 'blob',
|
||||
})
|
||||
|
||||
const contentDisposition = response.headers['content-disposition']
|
||||
let filename = 'export.csv'
|
||||
|
||||
if (contentDisposition) {
|
||||
const match = contentDisposition.match(/filename="?([^";]+)"?/)
|
||||
|
||||
if (match) {
|
||||
filename = match[1]
|
||||
}
|
||||
}
|
||||
|
||||
const blobUrl = window.URL.createObjectURL(
|
||||
new Blob([response.data], { type: 'text/csv;charset=utf-8' }),
|
||||
)
|
||||
const link = document.createElement('a')
|
||||
link.href = blobUrl
|
||||
link.setAttribute('download', filename)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
window.URL.revokeObjectURL(blobUrl)
|
||||
}
|
||||
Reference in New Issue
Block a user