【更新】针对前端下载blob提出重复代码

pull/89/MERGE
小诺 2 years ago committed by 俞宝山
parent d552d86dd2
commit 87f43b5f17

@ -60,6 +60,7 @@
<script setup name="genIndex">
import { message } from 'ant-design-vue'
import downloadUtil from '@/utils/downloadUtil'
import steps from './steps.vue'
import genPreview from './preview.vue'
import genBasicApi from '@/api/gen/genBasicApi'
@ -173,16 +174,7 @@
} else {
//
genBasicApi.basicExecGenBiz(param).then((res) => {
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
const contentDisposition = res.headers['content-disposition']
const patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
const $link = document.createElement('a')
$link.href = URL.createObjectURL(blob)
$link.download = decodeURIComponent(patt.exec(contentDisposition)[1])
$link.click()
document.body.appendChild($link)
document.body.removeChild($link) //
window.URL.revokeObjectURL($link.href) // blob
downloadUtil.resultDownload(res)
})
}
}

@ -49,6 +49,7 @@
</template>
<script setup name="genSteps">
import { message } from 'ant-design-vue'
import downloadUtil from '@/utils/downloadUtil'
import basic from './basic.vue'
import config from './config.vue'
import genPreview from './preview.vue'
@ -133,16 +134,7 @@
} else {
//
genBasicApi.basicExecGenBiz(param).then((res) => {
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
const contentDisposition = res.headers['content-disposition']
const patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
const $link = document.createElement('a')
$link.href = URL.createObjectURL(blob)
$link.download = decodeURIComponent(patt.exec(contentDisposition)[1])
$link.click()
document.body.appendChild($link)
document.body.removeChild($link) //
window.URL.revokeObjectURL($link.href) // blob
downloadUtil.resultDownload(res)
emit('closed')
})
}

@ -38,6 +38,7 @@
<script setup name="userImpExp">
import userApi from '@/api/sys/userApi'
import downloadUtil from "@/utils/downloadUtil"
const impUploadLoading = ref(false)
const impAlertStatus = ref(false)
@ -93,16 +94,7 @@
//
const downloadImportUserTemplate = () => {
userApi.userDownloadImportUserTemplate().then((res) => {
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
const contentDisposition = res.headers['content-disposition']
const patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
const $link = document.createElement('a')
$link.href = URL.createObjectURL(blob)
$link.download = decodeURIComponent(patt.exec(contentDisposition)[1])
$link.click()
document.body.appendChild($link)
document.body.removeChild($link) //
window.URL.revokeObjectURL($link.href) // blob
downloadUtil.resultDownload(res)
})
}
//

Loading…
Cancel
Save