fix: 修复excel表格导出下载时的跨域问题

mengfanliang-0726-businessPerson_table
DESKTOP-2ESM03N\zcloud 2024-07-30 12:00:48 +08:00
parent a8f11f7e6d
commit 80f80c0cb9
2 changed files with 4 additions and 34 deletions

View File

@ -20,7 +20,7 @@ module.exports = {
}, },
// Various Dev Server settings // Various Dev Server settings
host: '192.168.0.118', // can be overwritten by process.env.HOST host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false, autoOpenBrowser: false,
errorOverlay: true, errorOverlay: true,

View File

@ -152,8 +152,8 @@
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import { requestFN } from '@/utils/request' import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' import waves from '@/directive/waves'
import axios from 'axios' // import axios from 'axios'
import moment from 'moment' // import moment from 'moment'
export default { export default {
components: { Pagination }, components: { Pagination },
@ -626,37 +626,7 @@ export default {
}, },
// excel // excel
exportExcelHandler(ids, head) { exportExcelHandler(ids, head) {
return new Promise((resolve, reject) => { window.open(`${this.config.httpurl}/openApi/excel?ids=${ids}&head=${head}`)
axios
.post(
config.httpurl + '/openApi/excel?' + `ids=${ids}&head=${head}`,
{},
{
responseType: 'blob'
}
)
.then(res => {
setTimeout(() => {
const blob = new Blob([res.data], {
type: 'application/vnd.ms-excel'
})
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.style.display = 'none'
downloadElement.href = href
downloadElement.download = moment().format('YYYY-MM-DD HH:mm:ss')
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
resolve(res)
}, 2000)
})
.catch(e => {
reject(e)
this.$message.error('导出失败,或未查询到隐患')
})
})
}, },
// //
openPopover() { openPopover() {