// 使用Id下载导出数据
export function getDownload (data) {
return request({
method: 'get',
url: `/download/${data}`,
responseType: 'blob'
})
}
// 下载数据
getTeacherDownload () {
//浏览器下载
// window.open(getTeacherDownload + this.opData.orgId)
if (this.id) {
getTeacherDownload(this.id).then(res => {
// function downFile (blob, fileName) {
// if (window.navigator.msSaveOrOpenBlob) {
// navigator.msSaveBlob(blob, fileName)
// } else {
// const link = document.createElement('a')
// link.href = window.URL.createObjectURL(blob)
// link.download = fileName
// link.click()
// window.URL.revokeObjectUrl(link.href)
// }
// }
//Blob 对象的 type 属性给出文件的 MIME 类型
const blob = new Blob([res], { type: 'application/octet-stream' })
downFile(blob, '数据.xlsx')
})
}
}
// 这里要[res] ---调用方式 ---调用前
// const blob = new Blob([res], { type: 'application/octet-stream' });
// 文件名要带后缀的--------调用
// downFile(blob, '生成全班电子报告.xlsx')
downFile = (blob, fileName) => {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, fileName)
} else {
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = fileName
link.click()
window.URL.revokeObjectURL(link.href)
}
}
路由跳转及传参
//跳转方法及传过去一个id
const route = this.$router.resolve({ path: '/newsinfo', query: { id: id } })
window.open(route.href, '_blank')
//接受方法
const id = this.$route.query.id