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

perf: Downloading files does not trigger the beforeunload event #4224

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions src/components/Table/ListTable/TableAction/ExportDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import Dialog from '@/components/Dialog/index.vue'
import { createSourceIdCache } from '@/api/common'
import * as queryUtil from '@/components/Table/DataTable/compenents/el-data-table/utils/query'
import { download } from '@/utils/common'

export default {
name: 'ExportDialog',
Expand Down Expand Up @@ -187,10 +188,7 @@ export default {
})
},
downloadCsv(url) {
const a = document.createElement('a')
a.href = url
a.click()
window.URL.revokeObjectURL(url)
download(url)
},
async defaultPerformExport(selectRows, exportOption, q, exportTypeOption) {
const url = (process.env.VUE_APP_ENV === 'production') ? (`${this.url}`) : (`${process.env.VUE_APP_BASE_API}${this.url}`)
Expand Down
7 changes: 2 additions & 5 deletions src/components/Table/ListTable/TableAction/ImportDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<script>
import Dialog from '@/components/Dialog/index.vue'
import ImportTable from '@/components/Table/ListTable/TableAction/ImportTable.vue'
import { getErrorResponseMsg } from '@/utils/common'
import { download, getErrorResponseMsg } from '@/utils/common'
import { createSourceIdCache } from '@/api/common'

export default {
Expand Down Expand Up @@ -221,10 +221,7 @@ export default {
this.$message.success(msg)
},
downloadCsv(url) {
const a = document.createElement('a')
a.href = url
a.click()
window.URL.revokeObjectURL(url)
download(url)
},
async handleImportConfirm() {
await this.$refs['importTable'].performUpload()
Expand Down
8 changes: 7 additions & 1 deletion src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,19 @@ export function downloadText(content, filename) {
}

export function download(downloadUrl, filename) {
const iframe = document.createElement('iframe')
iframe.style.display = 'none'
document.body.appendChild(iframe)
const a = document.createElement('a')
a.href = downloadUrl
if (filename) {
a.download = filename
}
iframe.contentWindow.document.body.appendChild(a)
a.click()
window.URL.revokeObjectURL(downloadUrl)
setTimeout(() => {
document.body.removeChild(iframe)
}, 1000 * 60 * 30) // If you can't download it in half an hour, don't download it.
}

export function diffObject(object, base) {
Expand Down
6 changes: 2 additions & 4 deletions src/views/sessions/CommandList/BaseList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import isFalsey from '@/components/Table/DataTable/compenents/el-data-table/util
import deepmerge from 'deepmerge'
import * as queryUtil from '@/components/Table/DataTable/compenents/el-data-table/utils/query'
import { createSourceIdCache } from '@/api/common'
import { download } from '@/utils/common'

export default {
name: 'CommandList',
Expand Down Expand Up @@ -144,10 +145,7 @@ export default {
queryUtil.stringify(query, '=', '&')
url = url + queryStr
this.$log.debug('Export url: ', this.url, '=>', url)
const a = document.createElement('a')
a.href = url
a.click()
window.URL.revokeObjectURL(url + queryStr)
download(url + queryStr)
}
}
},
Expand Down
Loading