123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- import Docxtemplater from 'docxtemplater'
- import PizZip from 'pizzip'
- import { getNowDate } from './Date';
- import { GetTime } from './Date';
- import FileSaver, { saveAs } from 'file-saver';
- import JSZipUtils from 'jszip-utils'
- 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;
-
- const reader = new FileReader();
- reader.readAsArrayBuffer(blob);
- reader.onload=function(a){
- const buffer = reader.result;
- const binary = new Uint8Array(buffer)
-
- const zip = new PizZip(binary);
-
- const doc = new Docxtemplater().loadZip(zip);
- console.log(data)
-
- 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']);
-
- direct.forEach(item2=>{
- if (item2['directFundData']==1) {
- fundData['device'] = direct.filter(item=>item['directFundData']==1)[0]['budget'];
-
- fundData['deviceRemarks'] = direct.filter(item=>item['directFundData']==1)[0]['reason'];
- }
-
- if (item2['directFundData']==2) {
- fundData['Material'] = direct.filter(item=>item['directFundData']==2)[0]['budget']
- fundData['MaterialRemarks'] = direct.filter(item=>item['directFundData']==2)[0]['reason'];
- }
-
- if (item2['directFundData']==3) {
- fundData['processing'] = direct.filter(item=>item['directFundData']==3)[0]['budget']
- fundData['processingRemarks'] = direct.filter(item=>item['directFundData']==3)[0]['reason'];
- }
-
-
- if (item2['directFundData']==4) {
- fundData['Collaboration'] = direct.filter(item=>item['directFundData']==4)[0]['budget']
- fundData['CollaborationRemarks'] = direct.filter(item=>item['directFundData']==4)[0]['reason'];
- }
-
- })
-
- indirect.forEach(item3=>{
- if (item3['indirectFundData']==1) {
- fundData['APPRAISAL'] = indirect.filter(item=>item['indirectFundData']==1)[0]['budget']
- fundData['APPRAISALRemarks'] = indirect.filter(item=>item['indirectFundData']==1)[0]['reason'];
- }
-
- if (item3['indirectFundData']==2) {
- fundData['entery'] = indirect.filter(item=>item['indirectFundData']==2)[0]['budget']
- fundData['enteryRemarks'] = indirect.filter(item=>item['indirectFundData']==2)[0]['reason'];
- }
-
- if (item3['indirectFundData']==3) {
- fundData['activities'] = indirect.filter(item=>item['indirectFundData']==3)[0]['budget']
- fundData['activitiesRemarks'] = indirect.filter(item=>item['indirectFundData']==3)[0]['reason'];
- }
-
- if (item3['indirectFundData']==4) {
- 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);
- })
-
-
- for(let i in data['chapters']){
- data['chapters'][i]=data['chapters'][i].replace(/<[^>]+>/g,"");
- }
- let nowDate = getNowDate().split(' ')[0]
-
- let wordData = {
- year:nowDate.split('-')[0],
- month:nowDate.split('-')[1],
- day:nowDate.split('-')[2],
- ing:data['typeName']=='待建设'?"√":"□",
- ed:data['typeName']=='已建设'?"√":"□",
- 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'],
- student:data['course_student'],
- 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,
-
-
-
-
-
-
-
-
-
- }
-
- doc.setData(wordData);
- doc.render();
-
- 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()
- }
- function getMakerSpaceWord(wordData){
-
- let _url = "./file/2023年二级学院特色创客空间建设项目申报书模板 (2).docx";
- const x = new XMLHttpRequest();
- x.open("GET", _url, true);
- x.responseType = "blob";
- x.onload = function (e) {
- const blob = x.response;
-
- const reader = new FileReader();
- reader.readAsArrayBuffer(blob);
- reader.onload=function(a){
- const buffer = reader.result;
- const binary = new Uint8Array(buffer)
-
- const zip = new PizZip(binary);
-
- const doc = new Docxtemplater().loadZip(zip);
-
-
-
- let data = {
- applicationDate:wordData['applicationDate'],
- ing:wordData['stateName']=='待建设'?"√":"□",
- ed:wordData['stateName']=='已建设'?"√":"□",
- projectName:wordData['projectName'],
- college:wordData['collegeName'],
- begin_at:wordData['begin_at'],
- plannedEnd_at:wordData['plannedEnd_at'],
- pro_leader:wordData['pro_leader'],
- lead_leader:wordData['lead_leader'],
- people:(wordData['teacher'].length+wordData['student'].length),
- teacherNum:wordData['teacher'].length,
- studentNum:wordData['student'].length,
- teacher:wordData['teacher'],
- student:wordData['student'],
- brief:wordData['brief'],
- Construction:wordData['Construction'],
- ProjectBasis:wordData['ProjectBasis'],
- development:wordData['development'],
- studio:wordData['studio'],
- studentTeam:wordData['studentTeam'],
- studentActivities:wordData['studentActivities'],
- Transforming:wordData['Transforming'],
- condition:wordData['condition'],
- fund:[wordData['fund']],
-
-
-
-
-
-
-
-
-
- }
-
- doc.setData(data);
- doc.render();
-
- 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()
- }
- function MakerStudentWord(data,fund){
- console.log(data);
-
-
-
- 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;
-
- const reader = new FileReader();
- reader.readAsArrayBuffer(blob);
- reader.onload=function(a){
- const buffer = reader.result;
- const binary = new Uint8Array(buffer)
-
- const zip = new PizZip(binary);
-
- const doc = new Docxtemplater().loadZip(zip);
-
-
-
-
-
-
-
- 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']);
-
- direct.forEach(item2=>{
- if (item2['directFundData']==1) {
- fundData['device'] = direct.filter(item=>item['directFundData']==1)[0]['budget'];
-
- fundData['deviceRemarks'] = direct.filter(item=>item['directFundData']==1)[0]['reason'];
- }
-
- if (item2['directFundData']==2) {
- fundData['Material'] = direct.filter(item=>item['directFundData']==2)[0]['budget']
- fundData['MaterialRemarks'] = direct.filter(item=>item['directFundData']==2)[0]['reason'];
- }
-
- if (item2['directFundData']==3) {
- fundData['processing'] = direct.filter(item=>item['directFundData']==3)[0]['budget']
- fundData['processingRemarks'] = direct.filter(item=>item['directFundData']==3)[0]['reason'];
- }
-
-
- if (item2['directFundData']==4) {
- fundData['Collaboration'] = direct.filter(item=>item['directFundData']==4)[0]['budget']
- fundData['CollaborationRemarks'] = direct.filter(item=>item['directFundData']==4)[0]['reason'];
- }
-
- })
-
- indirect.forEach(item3=>{
- if (item3['indirectFundData']==1) {
- fundData['APPRAISAL'] = indirect.filter(item=>item['indirectFundData']==1)[0]['budget']
- fundData['APPRAISALRemarks'] = indirect.filter(item=>item['indirectFundData']==1)[0]['reason'];
- }
-
- if (item3['indirectFundData']==2) {
- fundData['entery'] = indirect.filter(item=>item['indirectFundData']==2)[0]['budget']
- fundData['enteryRemarks'] = indirect.filter(item=>item['indirectFundData']==2)[0]['reason'];
- }
-
- if (item3['indirectFundData']==3) {
- fundData['activities'] = indirect.filter(item=>item['indirectFundData']==3)[0]['budget']
- fundData['activitiesRemarks'] = indirect.filter(item=>item['indirectFundData']==3)[0]['reason'];
- }
-
- if (item3['indirectFundData']==4) {
- 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);
- })
-
- for(let i in data['chapters']){
- data['chapters'][i]=data['chapters'][i].replace(/<[^>]+>/g,"");
- }
- let nowDate = getNowDate().split(' ')[0]
-
- let wordData = {
-
- year:nowDate.split('-')[0],
- month:nowDate.split('-')[1],
- day:nowDate.split('-')[2],
- projectName:data['title'],
- ing:data['typeName']==0?"√":"□",
- ed:data['typeName']==0?"□":"√",
-
- mone:data['val.checkList'].indexOf(1)!=-1?"√":"□",
- mtwo:data['val.checkList'].indexOf(2)!=-1?"√":"□",
- mthree:data['val.checkList'].indexOf(3)!=-1?"√":"□",
- mfour:data['val.checkList'].indexOf(4)!=-1?"√":"□",
- sone:data['schoolRadio']==1?"√":"□",
- stwo:data['schoolRadio']==2?"√":"□",
- sthree:data['schoolRadio']==3?"√":"□",
- sfour:data['schoolRadio']==4?"√":"□",
- stu:data['projectApplyperson']==1?"√":"□",
- leg:data['projectApplyperson']==1?"□":"√",
- appPeason:data['pro_leader'],
- school:data['name'],
- tel:data['phone'],
- begin_at:data['begin_at'],
- plannedEnd_at:data['plannedEnd_at'],
- allnum:(data['course_teacher'].length+data['course_student'].length),
- snum:data['course_teacher'].length,
- tnum:data['course_student'].length,
- brief:data['brief'],
- back:data['chapters']['back'],
- innovate:data['chapters']['innovate'],
- path:data['chapters']['path'],
- scene:data['chapters']['scene'],
- worth:data['chapters']['worth'],
- team:data['chapters']['team'],
- cost:data['chapters']['cost'],
- expectResults:data['chapters']['expectResults'],
- expectResultsTeacher:data['chapters']['expectResultsTeacher'],
- expectConversion:data['chapters']['expectConversion'],
- plan:data['chapters']['plan'],
-
- teacher:data['course_teacher'],
- student:data['course_student'],
-
- fund:fundDataArray,
-
-
-
-
-
-
-
-
-
- }
-
- doc.setData(wordData);
- doc.render();
-
- const output = doc.getZip().generate({
- type: "blob",
- mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
- compression: "DEFLATE",
- });
- let link = document.createElement("a");
- link.download = '2023年学生创客项目申报书.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()
- }
- function getWord(val){
- JSZipUtils.getBinaryContent('./file/2023年学生创客项目申报书模板.docx',(err,content)=>{
- if (err) {
- return console.log(err);
- }
- let zip=new PizZip(content);
- let doc=new Docxtemplater().loadZip(zip);
-
-
-
-
- doc.setData({
- nowTime:getNowDate(1),
- projectName:val.projectName,
- ing:val.radio=='ed917c55-f51d-11ed-a3f6-509a4c5b67cf'?'√':'□',
- ed:val.radio=='f3068e26-f51d-11ed-a3f6-509a4c5b67cf'?'√':'□',
- mone:val.checkList.includes('1')?'√':'□',
- mtwo:val.checkList.includes('2')?'√':'□',
- mthree:val.checkList.includes('3')?'√':'□',
- mfour:val.checkList.includes('4')?'√':'□',
- sone:val.schoolRadio.includes('1')?'√':'□',
- stwo:val.schoolRadio.includes('2')?'√':'□',
- sthree:val.schoolRadio.includes('3')?'√':'□',
- sfour:val.schoolRadio.includes('4')?'√':'□',
- stu:val.applyParsonRadio.includes('1')?'√':'□',
- leg:val.applyParsonRadio.includes('2')?'√':'□',
- appPeason:val.applyParsonName,
- school:val.dp,
- tel:val.tel,
- begin_at:val.btime,
- plannedEnd_at:val.etime,
- allnum:val.studentS.length+val.teacherS.length,
- snum:val.studentS.length,
- tnum:val.teacherS.length,
- student:val.studentS,
- teacher:val.teacherS,
- brief:val.brief,
- back:val.introduce.back,
- innovate:val.introduce.innovate,
- path:val.introduce.path,
- scene:val.introduce.scene,
- worth:val.introduce.worth,
- team:val.introduce.team,
- cost:val.introduce.cost,
- expectResults:val.introduce.expectResults,
- expectResultsTeacher:val.introduce.expectResultsTeacher,
- expectConversion:val.introduce.expectConversion,
- plan:val.introduce.plan,
- total:val.fund.facility*1 + val.fund.materials*1+val.fund.process*1+ val.fund.assist*1+val.fund.authenticate*1+ val.fund.match*1+val.fund.activity*1+val.fund.affair*1,
- facility:val.fund.facility,
- materials:val.fund.materials,
- process:val.fund.process,
- assist:val.fund.assist,
- authenticate:val.fund.authenticate,
- match:val.fund.match,
- activity:val.fund.activity,
- affair:val.fund.affair,
- })
-
- doc.render()
- let out=doc.getZip().generate({
- type:'blob',
- mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
- })
-
- saveAs(out,'2023年学生创客项目申报书.docx')
- })
- }
- function ActivityWord(data){
- let _url = "./file/附件 2:创客专项资金项目申请表创客活动模板.docx";
- const x = new XMLHttpRequest();
- x.open("GET", _url, true);
- x.responseType = "blob";
- x.onload = function (e) {
- const blob = x.response;
-
- const reader = new FileReader();
- reader.readAsArrayBuffer(blob);
- reader.onload=function(a){
- const buffer = reader.result;
- const binary = new Uint8Array(buffer)
-
- const zip = new PizZip(binary);
-
- const doc = new Docxtemplater().loadZip(zip);
-
-
- data['chapters'] = JSON.parse(data['chapters']);
- data['begin_at'] = GetTime(data['begin_at'])
- data['course_teacher'] = JSON.parse(data['course_teacher'])
-
- let wordData = {
- activityName:data['title'],
- money:data['money'],
- pro_leader:data['pro_leader'],
- class:data['className'],
- phone:data['phone'],
- activityTime:data['begin_at'],
- studentNum:data['students'],
- teacher:data['course_teacher'],
- plan:data['chapters'][0].replace(/<[^>]+>/g,""),
- Expectations:data['chapters'][1].replace(/<[^>]+>/g,""),
- EventAudience:data['chapters'][2].replace(/<[^>]+>/g,""),
- fund:data['chapters'][3].replace(/<[^>]+>/g,""),
- }
-
- doc.setData(wordData);
- doc.render();
-
- const output = doc.getZip().generate({
- type: "blob",
- mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
- compression: "DEFLATE",
- });
- let link = document.createElement("a");
- link.download = '附件 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()
- }
- function makerActivityWord(data,total){
- let _url = "./file/附件 2:创客专项资金项目申请表(创客活动、个人创客)模板.docx";
- const x = new XMLHttpRequest();
- x.open("GET", _url, true);
- x.responseType = "blob";
- x.onload = function (e) {
- const blob = x.response;
-
- const reader = new FileReader();
- reader.readAsArrayBuffer(blob);
- reader.onload=function(a){
- const buffer = reader.result;
- const binary = new Uint8Array(buffer)
-
- const zip = new PizZip(binary);
-
- const doc = new Docxtemplater().loadZip(zip);
-
-
- let wordData = {...data,total}
-
- wordData['MP1'] = wordData['expenditureMothPlan'][0];
- wordData['MP2'] = wordData['expenditureMothPlan'][1];
- wordData['MP3'] = wordData['expenditureMothPlan'][2];
- wordData['MP4'] = wordData['expenditureMothPlan'][3];
- wordData['MP5'] = wordData['expenditureMothPlan'][4];
- wordData['MP6'] = wordData['expenditureMothPlan'][5];
- wordData['MP7'] = wordData['expenditureMothPlan'][6];
- wordData['MP8'] = wordData['expenditureMothPlan'][7];
- wordData['MP9'] = wordData['expenditureMothPlan'][8];
- wordData['MP10'] = wordData['expenditureMothPlan'][9];
- wordData['MP11'] = wordData['expenditureMothPlan'][10];
- wordData['MP12'] = wordData['expenditureMothPlan'][11];
- wordData['beTime'] = wordData['activityTime'][0].split(' ')[0]
- wordData['edTime'] = wordData['activityTime'][1].split(' ')[0]
- wordData['device'] = wordData['fund']['device']
- wordData['Material'] = wordData['fund']['Material']
- wordData['processing'] = wordData['fund']['processing']
- wordData['Collaboration'] = wordData['fund']['Collaboration']
- wordData['APPRAISAL'] = wordData['fund']['APPRAISAL']
- wordData['entery'] = wordData['fund']['entery']
- wordData['activities'] = wordData['fund']['activities']
- wordData['Transaction'] = wordData['fund']['Transaction']
- wordData['type'] = Boolean(wordData['type'])
- doc.setData(wordData);
- doc.render();
-
- const output = doc.getZip().generate({
- type: "blob",
- mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
- compression: "DEFLATE",
- });
- let link = document.createElement("a");
- link.download = `附件 2:创客专项资金项目申请表(${wordData['type']?'个人创客':'创客活动'}).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,
- getMakerSpaceWord,
- MakerStudentWord,
- ActivityWord,
- getWord,
- makerActivityWord,
- }
|