|
@@ -0,0 +1,138 @@
|
|
|
+import Docxtemplater from 'docxtemplater'
|
|
|
+import PizZip from 'pizzip'
|
|
|
+function MakerSpaceWord(data,fund){
|
|
|
+ //获取模板文件
|
|
|
+ let _url = "./file/2023年二级学院特色创客空间建设项目申报书模板.docx";
|
|
|
+ const x = new XMLHttpRequest();
|
|
|
+ x.open("GET", _url, true);
|
|
|
+ x.responseType = "blob";
|
|
|
+ x.onload = function (e) {
|
|
|
+ const blob = x.response;
|
|
|
+ //转成binary
|
|
|
+
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.readAsArrayBuffer(blob);
|
|
|
+ reader.onload=function(a){
|
|
|
+ const buffer = reader.result;
|
|
|
+ const binary = new Uint8Array(buffer)
|
|
|
+ //创建一个PizZip实例
|
|
|
+ const zip = new PizZip(binary);
|
|
|
+ // 将模板内容加载到 Docxtemplater 中
|
|
|
+ const doc = new Docxtemplater().loadZip(zip);
|
|
|
+ //处理项目数据
|
|
|
+ data['chapters'] = JSON.parse(data['chapters']);
|
|
|
+ data['course_teacher'] = JSON.parse(data['course_teacher']);
|
|
|
+ data['course_student'] = JSON.parse(data['course_student']);
|
|
|
+ //处理资金使用情况
|
|
|
+ let fundDataArray = [];
|
|
|
+ fund.forEach(item=>{
|
|
|
+ let fundData = {
|
|
|
+ total:"",
|
|
|
+ device:"",deviceRemarks:"",
|
|
|
+ Material:"",MaterialRemarks:"",
|
|
|
+ processing:"",processingRemarks:"",
|
|
|
+ Collaboration:"",CollaborationRemarks:"",
|
|
|
+ APPRAISAL:"",APPRAISALRemarks:"",
|
|
|
+ entery:"",enteryRemarks:"",
|
|
|
+ activities:"",activitiesRemarks:"",
|
|
|
+ Transaction:"",TransactionRemarks:""
|
|
|
+ }
|
|
|
+ //直接经费
|
|
|
+ let direct = JSON.parse(item['directFund']);
|
|
|
+ //间接经费
|
|
|
+ let indirect = JSON.parse(item['indirectFund']);
|
|
|
+
|
|
|
+ fundData['device'] = direct.filter(item=>item['directFundData']==1)[0]['budget'];
|
|
|
+ fundData['deviceRemarks'] = direct.filter(item=>item['directFundData']==1)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['Material'] = direct.filter(item=>item['directFundData']==2)[0]['budget']
|
|
|
+ fundData['MaterialRemarks'] = direct.filter(item=>item['directFundData']==2)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['processing'] = direct.filter(item=>item['directFundData']==3)[0]['budget']
|
|
|
+ fundData['processingRemarks'] = direct.filter(item=>item['directFundData']==3)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['Collaboration'] = direct.filter(item=>item['directFundData']==4)[0]['budget']
|
|
|
+ fundData['CollaborationRemarks'] = direct.filter(item=>item['directFundData']==4)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['APPRAISAL'] = indirect.filter(item=>item['indirectFundData']==1)[0]['budget']
|
|
|
+ fundData['APPRAISALRemarks'] = indirect.filter(item=>item['indirectFundData']==1)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['entery'] = indirect.filter(item=>item['indirectFundData']==2)[0]['budget']
|
|
|
+ fundData['enteryRemarks'] = indirect.filter(item=>item['indirectFundData']==2)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['activities'] = indirect.filter(item=>item['indirectFundData']==3)[0]['budget']
|
|
|
+ fundData['activitiesRemarks'] = indirect.filter(item=>item['indirectFundData']==3)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['Transaction'] = indirect.filter(item=>item['indirectFundData']==4)[0]['budget']
|
|
|
+ fundData['TransactionRemarks'] = indirect.filter(item=>item['indirectFundData']==4)[0]['reason'];
|
|
|
+
|
|
|
+ fundData['total'] = Number(fundData['device'])+Number(fundData['Material'])+Number(fundData['processing'])+Number(fundData['Collaboration'])+Number(fundData['APPRAISAL'])+Number(fundData['entery'])+Number(fundData['activities'])+Number(fundData['Transaction']);
|
|
|
+
|
|
|
+ fundDataArray.push(fundData);
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //模板数据
|
|
|
+ let wordData = {
|
|
|
+ projectName:data['title'],//项目名称
|
|
|
+ college:data['name'],//
|
|
|
+ begin_at:data['begin_at'],//项目开始时间
|
|
|
+ plannedEnd_at:data['plannedEnd_at'],//计划完成时间
|
|
|
+ pro_leader:data['pro_leader'],//项目负责人
|
|
|
+ lead_leader:data['lead_leader'],//学院牵头领导
|
|
|
+ people:(data['course_teacher'].length+data['course_student'].length),//项目组人数
|
|
|
+ teacherNum:data['course_teacher'].length,//参与教师人数
|
|
|
+ studentNum:data['course_student'].length,//参与学生人数
|
|
|
+ teacher:data['course_teacher'], //教师组//name:姓名 speciality:专业 title:职称 education:学历 section:所在教研室 work:项目组角色分工
|
|
|
+ student:data['course_student'], //学生组//name:姓名 class:班级 age:年龄 work:项目组任务分工
|
|
|
+ brief:data['brief'],//项目简介
|
|
|
+ Construction:data['chapters']['Construction'],//建设内容
|
|
|
+ ProjectBasis:data['chapters']['ProjectBasis'],//立项依据
|
|
|
+ development:data['chapters']['development'],//创客空间物理环境、制度建设及软件设施建设情况
|
|
|
+ studio:data['chapters']['studio'],//学生创客工作室建设情况
|
|
|
+ studentTeam:data['chapters']['studentTeam'],//学生创客团队(人才)培养预期成果、数量
|
|
|
+ studentActivities:data['chapters']['studentActivities'],//学生创客活动组织实施情况
|
|
|
+ Transforming:data['chapters']['Transforming'],//学生创客团队孵化、转化创业项目情况
|
|
|
+ condition:data['chapters']['condition'],//立 项基 础及条 件
|
|
|
+ fund:fundDataArray,//预算经费
|
|
|
+ //total:总经费
|
|
|
+ //小型仪器设备费:device deviceRemarks
|
|
|
+ //材料费:Material MaterialRemarks
|
|
|
+ //测试化验加工费:processing processingRemarks
|
|
|
+ //项目协作费:Collaboration CollaborationRemarks
|
|
|
+ //项目成果鉴定费:APPRAISAL APPRAISALRemarks
|
|
|
+ //参展参赛费:entery enteryRemarks
|
|
|
+ //创客交流活动费:activities activitiesRemarks
|
|
|
+ //知识产权事务费:Transaction TransactionRemarks
|
|
|
+ }
|
|
|
+ //渲染模板
|
|
|
+ doc.setData(wordData);
|
|
|
+
|
|
|
+ doc.render();
|
|
|
+ console.log(wordData)
|
|
|
+ //获取渲染后的文本
|
|
|
+ const output = doc.getZip().generate({
|
|
|
+ type: "blob",
|
|
|
+ mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
+ compression: "DEFLATE",
|
|
|
+ });
|
|
|
+ let link = document.createElement("a");
|
|
|
+ link.download = '附件3:2023年二级学院特色创客空间建设项目申报书模板(2).docx';
|
|
|
+ link.style.display = "none";
|
|
|
+ let blob = new Blob([output]);
|
|
|
+ link.href = URL.createObjectURL(blob);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+ }
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ x.send()
|
|
|
+}
|
|
|
+
|
|
|
+export{
|
|
|
+ MakerSpaceWord
|
|
|
+}
|