mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-08 02:16:43 +08:00
下载可能存在报错,不采用open方式
This commit is contained in:
@@ -336,6 +336,8 @@ import apiCoursePortal from "@/api/modules/coursePortal.js";
|
||||
import { mapGetters,mapActions } from 'vuex';
|
||||
import apiUser from '@/api/system/user.js';
|
||||
import apiStudy from '@/api/modules/courseStudy.js';
|
||||
import { getToken } from '@/utils/token'
|
||||
import axios from 'axios'
|
||||
export default {
|
||||
components: {auditCourse1,auditCourse2},
|
||||
computed: {
|
||||
@@ -510,23 +512,28 @@ export default {
|
||||
courseName:this.manageStudyData.name,
|
||||
contentId:this.contentId
|
||||
}
|
||||
window.open(`/systemapi/xboe/m/course/portal/export?contentId=${params.contentId}&courseName=${params.courseName}`)
|
||||
apicourseStudy.homeworkExport(params).then(res=>{
|
||||
console.log(res,'res')
|
||||
const link = document.createElement('a');// 创建a标签
|
||||
let blob = new Blob([res], { type: 'application/zip' }); // 设置文件类型
|
||||
link.style.display = "none";
|
||||
link.href = URL.createObjectURL(blob); // 创建URL
|
||||
console.log(link.href);
|
||||
link.setAttribute("download", "作业.zip");
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
URL.revokeObjectURL(link.href)
|
||||
document.body.removeChild(link);
|
||||
}).catch(err=>{
|
||||
console.log(err,'err')
|
||||
this.$message.warning(err.data.msg);
|
||||
})
|
||||
// window.open(`/systemapi/xboe/m/course/portal/export?contentId=${params.contentId}&courseName=${params.courseName}`)
|
||||
const url = `/systemapi/xboe/m/course/portal/export?contentId=${params.contentId}&courseName=${params.courseName}`
|
||||
axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
responseType: 'blob',
|
||||
headers: { 'X-Access-Token': getToken() }
|
||||
}).then(res => {
|
||||
console.log(res,'res')
|
||||
this.resolveBlob(res, 'application/zip',`${params.courseName}【作业】`)
|
||||
})
|
||||
},
|
||||
resolveBlob(res, mimeType,filename) {
|
||||
const link = document.createElement('a');// 创建a标签
|
||||
let blob = new Blob([res.data], { type: mimeType }); // 设置文件类型
|
||||
link.style.display = "none";
|
||||
link.href = URL.createObjectURL(blob); // 创建URL
|
||||
link.setAttribute("download", `${filename}`);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
URL.revokeObjectURL(link.href);
|
||||
document.body.removeChild(link);
|
||||
},
|
||||
handleSizeChangeSituation(val) {
|
||||
this.learningSituation.pageSize = val;
|
||||
|
||||
Reference in New Issue
Block a user