From 680be1bf0a96474ae7e49a4ac5332144ef762b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Sat, 6 Jul 2019 00:00:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/shixunHomework/Listofworks.js | 34 +++---------- .../shixunHomework/ShixunStudentWork.js | 46 ++++++++++++++++- .../shixunHomework/ShixunWorkReport.js | 45 +++++++++++++++-- .../shixunHomework/Trainingjobsetting.js | 47 +++++++++++++++++- .../shixunHomework/Workquestionandanswer.js | 49 +++++++++++++++++-- 5 files changed, 184 insertions(+), 37 deletions(-) diff --git a/public/react/src/modules/courses/shixunHomework/Listofworks.js b/public/react/src/modules/courses/shixunHomework/Listofworks.js index 2ce92df78..db008e2c4 100644 --- a/public/react/src/modules/courses/shixunHomework/Listofworks.js +++ b/public/react/src/modules/courses/shixunHomework/Listofworks.js @@ -1358,23 +1358,22 @@ class Listofworks extends Component { }else{ // window.location.href("/api"+url); - console.log("开始下载zip文件") + // console.log("开始下载zip文件") const type='application/zip'//ZIP文件 const blob = new Blob([response.data], { type: type }) const downloadElement = document.createElement('a') const href = window.URL.createObjectURL(blob) //后台再header中传文件名 - console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); downloadElement.href = href var now=""; try { - now = moment().year()+""+moment().month()+1+""+moment().date()+""+moment().hour()+""+moment().minute()+"" - console.log("1422"); + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" console.log(now); } catch (e) { - console.log("1432"); + console.log("1376"); } downloadElement.download = string+now+".zip" document.body.appendChild(downloadElement) @@ -1389,20 +1388,6 @@ class Listofworks extends Component { // 课堂学生成绩的导出下载 Classstudentachievement=(url)=>{ console.log("Classstudentachievement"); - // const course_id = this.props.match.params.coursesId; - // let url = "/courses/"+course_id+"/export_member_scores_excel.xlsx"; - // ,{ - // params: { - // group_id: this.state.checkedValuesineinfo, - // search: this.state.searchtext, - // } - // },{responseType: 'blob'}) - // 56S+5Yy65a+85biIX+iuoeeul+aAnee7tOWvvOiuujIwMTnmmKXlraPor77l,oIJfUHl0aG9u5a6e546w6YCJ5oup,.xls - // console.log(decodeURIComponent("b178a6c387c1dd2d4097b0dcaa19a043_1562205834")); - // console.log(decodeURI("b178a6c387c1dd2d4097b0dcaa19a043_1562205834")); - // console.log(Base64.decode("b178a6c387c1dd2d4097b0dcaa19a043_1562205834")); - // console.log(Base64.decode("56S-5Yy65a-85biIX-iuoeeul-aAnee7tOWvvOiuujIwMTnmmKXlraPor77loIJfUHl0aG9u5a6e546w6YCJ5oup")); - axios.get((url),{responseType: 'blob'}).then((response) => { console.log("1374"); console.log(response); @@ -1417,16 +1402,12 @@ class Listofworks extends Component { const downloadElement = document.createElement('a') const href = window.URL.createObjectURL(blob) //后台再header中传文件名 - // const name = decodeURI(response.headers['content-disposition'].split('=')[1]) - // console.log(response.headers['content-disposition'].split('=')[1]); - // console.log(name); - // console.log(decodeURIComponent(response.headers['content-disposition'].split('=')[1])); - console.log("1409"); - console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + // console.log("1409"); + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); var now=""; try { - now = moment().year()+""+moment().month()+1+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" console.log("1422"); console.log(now); @@ -1439,7 +1420,6 @@ class Listofworks extends Component { downloadElement.click() document.body.removeChild(downloadElement) // 下载完成移除元素 window.URL.revokeObjectURL(href) // 释放掉blob对象 - } }).catch((error) => { console.log(error) diff --git a/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js b/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js index 109988fa9..5744c8ffe 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js @@ -469,7 +469,27 @@ class ShixunStudentWork extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.open("/api"+url, '_blank'); + const type='application/zip'//ZIP文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + downloadElement.href = href + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log(now); + + } catch (e) { + console.log("1376"); + } + downloadElement.download = string+now+".zip" + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => { @@ -491,7 +511,29 @@ class ShixunStudentWork extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.open("/api"+url, '_blank'); + const type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' //excel文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log("1409"); + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log("1422"); + console.log(now); + + } catch (e) { + console.log("1432"); + } + downloadElement.href = href + downloadElement.download =string+now+".xlsx"; + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => { diff --git a/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js b/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js index d120ec5ad..e8a42bdae 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js @@ -17,6 +17,7 @@ import '../css/members.css'; import "../common/formCommon.css"; import '../css/Courses.css'; import './style.css'; +import moment from "./Trainingjobsetting"; class ShixunWorkReport extends Component { @@ -28,7 +29,47 @@ class ShixunWorkReport extends Component { spinning:true } } + // 导出实习报告批量 + internshipreport = (url) => { + console.log("internshipreport"); + // var homeworkid = this.props.match.params.homeworkid; + // let url = "/zip/shixun_report"; + axios.get(url).then((response) => { + console.log("326"); + console.log(response); + if(response.data.status&&response.data.status===-1){ + + }else if(response.data.status&&response.data.status===-2){ + + }else{ + const type='application/zip'//ZIP文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + downloadElement.href = href + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log(now); + + } catch (e) { + console.log("1376"); + } + downloadElement.download = string+now+".zip" + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 + } + + }).catch((error) => { + console.log(error) + }); + } componentDidMount() { this.setState({ spinning:true @@ -93,9 +134,7 @@ class ShixunWorkReport extends Component { {/*{this.props.isAdmin()?导出实训报告数据:""}*/} {this.props.isAdmin() ? this.internshipreport(`/zip/shixun_report?homework_common_id=${homeworkid}`)} >导出实训报告数据 : ""} diff --git a/public/react/src/modules/courses/shixunHomework/Trainingjobsetting.js b/public/react/src/modules/courses/shixunHomework/Trainingjobsetting.js index 8e857199b..efa418db0 100644 --- a/public/react/src/modules/courses/shixunHomework/Trainingjobsetting.js +++ b/public/react/src/modules/courses/shixunHomework/Trainingjobsetting.js @@ -24,6 +24,7 @@ import './style.css'; import '../css/busyWork.css' import '../poll/pollStyle.css' import moment from 'moment'; +import 'moment/locale/zh-cn'; import Modals from "../../modals/Modals"; const RadioGroup = Radio.Group; @@ -1621,7 +1622,27 @@ class Trainingjobsetting extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.open("/api"+url, '_blank'); + const type='application/zip'//ZIP文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + downloadElement.href = href + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log(now); + + } catch (e) { + console.log("1376"); + } + downloadElement.download = string+now+".zip" + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => { @@ -1643,7 +1664,29 @@ class Trainingjobsetting extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.open("/api"+url, '_blank'); + const type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' //excel文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log("1409"); + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log("1422"); + console.log(now); + + } catch (e) { + console.log("1432"); + } + downloadElement.href = href + downloadElement.download =string+now+".xlsx"; + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => { diff --git a/public/react/src/modules/courses/shixunHomework/Workquestionandanswer.js b/public/react/src/modules/courses/shixunHomework/Workquestionandanswer.js index 8d88e9fb5..572f1e44f 100644 --- a/public/react/src/modules/courses/shixunHomework/Workquestionandanswer.js +++ b/public/react/src/modules/courses/shixunHomework/Workquestionandanswer.js @@ -23,7 +23,8 @@ import { notification } from "antd"; import {Link, Switch, Route, Redirect} from 'react-router-dom'; -import moment from 'moment' +import moment from 'moment'; +import 'moment/locale/zh-cn'; import axios from 'axios'; import '../css/members.css' import "../common/formCommon.css" @@ -332,7 +333,27 @@ class Workquestionandanswer extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.open("/api"+url, '_blank'); + const type='application/zip'//ZIP文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + downloadElement.href = href + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log(now); + + } catch (e) { + console.log("1376"); + } + downloadElement.download = string+now+".zip" + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => { @@ -354,7 +375,29 @@ class Workquestionandanswer extends Component { }else if(response.data.status&&response.data.status===-2){ }else{ - window.open("/api"+url, '_blank'); + const type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' //excel文件 + const blob = new Blob([response.data], { type: type }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + //后台再header中传文件名 + // console.log("1409"); + // console.log(Base64.decode(response.headers['content-disposition'].split('=')[1])); + const string = Base64.decode(response.headers['content-disposition'].split('=')[1]); + var now=""; + try { + now = moment().year()+""+(moment().month()+1)+""+moment().date()+""+moment().hour()+""+moment().minute()+"" + console.log("1422"); + console.log(now); + + } catch (e) { + console.log("1432"); + } + downloadElement.href = href + downloadElement.download =string+now+".xlsx"; + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放掉blob对象 } }).catch((error) => {