fix: 修复excel表格导出下载时的跨域问题
parent
a8f11f7e6d
commit
80f80c0cb9
|
@ -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,
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue