mirror of https://gitee.com/xiaonuobase/snowy
【更新】针对前端下载blob提出重复代码
parent
d552d86dd2
commit
87f43b5f17
|
@ -60,6 +60,7 @@
|
||||||
|
|
||||||
<script setup name="genIndex">
|
<script setup name="genIndex">
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
|
import downloadUtil from '@/utils/downloadUtil'
|
||||||
import steps from './steps.vue'
|
import steps from './steps.vue'
|
||||||
import genPreview from './preview.vue'
|
import genPreview from './preview.vue'
|
||||||
import genBasicApi from '@/api/gen/genBasicApi'
|
import genBasicApi from '@/api/gen/genBasicApi'
|
||||||
|
@ -173,16 +174,7 @@
|
||||||
} else {
|
} else {
|
||||||
// 下载压缩包
|
// 下载压缩包
|
||||||
genBasicApi.basicExecGenBiz(param).then((res) => {
|
genBasicApi.basicExecGenBiz(param).then((res) => {
|
||||||
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
|
downloadUtil.resultDownload(res)
|
||||||
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对象
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script setup name="genSteps">
|
<script setup name="genSteps">
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
|
import downloadUtil from '@/utils/downloadUtil'
|
||||||
import basic from './basic.vue'
|
import basic from './basic.vue'
|
||||||
import config from './config.vue'
|
import config from './config.vue'
|
||||||
import genPreview from './preview.vue'
|
import genPreview from './preview.vue'
|
||||||
|
@ -133,16 +134,7 @@
|
||||||
} else {
|
} else {
|
||||||
// 下载压缩包
|
// 下载压缩包
|
||||||
genBasicApi.basicExecGenBiz(param).then((res) => {
|
genBasicApi.basicExecGenBiz(param).then((res) => {
|
||||||
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
|
downloadUtil.resultDownload(res)
|
||||||
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对象
|
|
||||||
emit('closed')
|
emit('closed')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
<script setup name="userImpExp">
|
<script setup name="userImpExp">
|
||||||
import userApi from '@/api/sys/userApi'
|
import userApi from '@/api/sys/userApi'
|
||||||
|
import downloadUtil from "@/utils/downloadUtil"
|
||||||
|
|
||||||
const impUploadLoading = ref(false)
|
const impUploadLoading = ref(false)
|
||||||
const impAlertStatus = ref(false)
|
const impAlertStatus = ref(false)
|
||||||
|
@ -93,16 +94,7 @@
|
||||||
// 下载用户导入模板
|
// 下载用户导入模板
|
||||||
const downloadImportUserTemplate = () => {
|
const downloadImportUserTemplate = () => {
|
||||||
userApi.userDownloadImportUserTemplate().then((res) => {
|
userApi.userDownloadImportUserTemplate().then((res) => {
|
||||||
const blob = new Blob([res.data], { type: 'application/octet-stream;charset=UTF-8' })
|
downloadUtil.resultDownload(res)
|
||||||
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对象
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 调用这个函数将子组件的一些数据和方法暴露出去
|
// 调用这个函数将子组件的一些数据和方法暴露出去
|
||||||
|
|
Loading…
Reference in New Issue