|
@@ -9,132 +9,144 @@ import ImageModule from 'docxtemplater-image-module-free'
|
|
|
|
|
|
// 新学生创业项目申请表下载模板word版
|
|
|
function getWord2(val){
|
|
|
- JSZipUtils.getBinaryContent('./file/2023年学生创客项目申报书模板 - 副本.docx',async (err,content)=>{
|
|
|
- if (err) {
|
|
|
- return console.log(err);
|
|
|
- }
|
|
|
-
|
|
|
- let ImageList = await getImage(val.elementList);
|
|
|
-
|
|
|
- // console.log(ImageList.find(i=>i.tagName=='back').url)
|
|
|
- // return console.log(ImageList)
|
|
|
-
|
|
|
- let zip=new PizZip(content);
|
|
|
-
|
|
|
- // 图片处理
|
|
|
- const opts = {
|
|
|
- centered:false,
|
|
|
- fileType:"docx",
|
|
|
- getImage:(value,value2,value3)=>{
|
|
|
- return base64DataURLToArrayBuffer(value)
|
|
|
- },
|
|
|
- getSize:(arrayValue,value,tagName)=>{
|
|
|
- let imgObj = ImageList.find(i=>i.tagName==tagName)
|
|
|
- let newWidth = 550;
|
|
|
- let newHeight = (newWidth*imgObj.height)/imgObj.width;
|
|
|
- return [newWidth,newHeight]
|
|
|
- }
|
|
|
+ return new Promise((resolve,reject)=>{
|
|
|
+ JSZipUtils.getBinaryContent('./file/2024年校级学生创新创业训练计划项目申报书模版2 - 图片.docx',async (err,content)=>{
|
|
|
+ if (err) {
|
|
|
+ return console.log(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ let ImageList = await getImage(val.elementList);
|
|
|
+
|
|
|
+ let zip=new PizZip(content);
|
|
|
+
|
|
|
+ // 图片处理
|
|
|
+ const opts = {
|
|
|
+ centered:false,
|
|
|
+ fileType:"docx",
|
|
|
+ getImage:(value,value2,value3)=>{
|
|
|
+ return base64DataURLToArrayBuffer(value)
|
|
|
+ },
|
|
|
+ getSize:(arrayValue,value,tagName)=>{
|
|
|
+ let imgObj = ImageList.find(i=>i.tagName==tagName)
|
|
|
+ let newWidth = 550;
|
|
|
+ let newHeight = (newWidth*imgObj.height)/imgObj.width;
|
|
|
+ return [newWidth,newHeight]
|
|
|
}
|
|
|
- let doc=new Docxtemplater()
|
|
|
- doc.loadZip(zip);
|
|
|
-
|
|
|
- doc.attachModule(new ImageModule(opts));
|
|
|
- // return console.log(val);
|
|
|
-
|
|
|
- // let FundAll=
|
|
|
- // return console.log(val);
|
|
|
-
|
|
|
- //填写数据
|
|
|
- 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:ImageList.find(i=>i.tagName=='back').url,
|
|
|
- innovate:ImageList.find(i=>i.tagName=='innovate').url,
|
|
|
- path:ImageList.find(i=>i.tagName=='path').url,
|
|
|
- scene:ImageList.find(i=>i.tagName=='scene').url,
|
|
|
- worth:ImageList.find(i=>i.tagName=='worth').url,
|
|
|
- team:ImageList.find(i=>i.tagName=='team').url,
|
|
|
- cost:ImageList.find(i=>i.tagName=='cost').url,
|
|
|
- expectResults:ImageList.find(i=>i.tagName=='expectResults').url,
|
|
|
- expectResultsTeacher:ImageList.find(i=>i.tagName=='expectResultsTeacher').url,
|
|
|
- expectConversion:ImageList.find(i=>i.tagName=='expectConversion').url,
|
|
|
- plan:ImageList.find(i=>i.tagName=='plan').url,
|
|
|
- total:0,
|
|
|
- facility:0,
|
|
|
- materials:0,
|
|
|
- process:0,
|
|
|
- assist:0,
|
|
|
- authenticate:0,
|
|
|
- match:0,
|
|
|
- activity:0,
|
|
|
- affair:0,
|
|
|
- total:val.fund.device*1 + val.fund.Material*1+val.fund.processing*1+ val.fund.Collaboration*1+val.fund.APPRAISAL*1+ val.fund.entery*1+val.fund.activities*1+val.fund.Transaction*1,
|
|
|
- facility:val.fund.device,
|
|
|
- materials:val.fund.Material,
|
|
|
- process:val.fund.processing,
|
|
|
- assist:val.fund.Collaboration,
|
|
|
- authenticate:val.fund.APPRAISAL,
|
|
|
- match:val.fund.entery,
|
|
|
- activity:val.fund.activities,
|
|
|
- affair:val.fund.Transaction,
|
|
|
- })
|
|
|
-
|
|
|
- // 进行填充
|
|
|
- doc.render()
|
|
|
-
|
|
|
- let out=doc.getZip().generate({
|
|
|
- type:'blob',
|
|
|
- mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
- })
|
|
|
-
|
|
|
- // fs.writeFileSync(path.resolve(__dirname, "output.docx"), buf);
|
|
|
- saveAs(out,'2023年学生创客项目申报书.docx')
|
|
|
-
|
|
|
- })
|
|
|
+ }
|
|
|
+ let doc=new Docxtemplater()
|
|
|
+ doc.loadZip(zip);
|
|
|
+
|
|
|
+ doc.attachModule(new ImageModule(opts));
|
|
|
+
|
|
|
+ //填写数据
|
|
|
+ doc.setData({
|
|
|
+ nowTime:getNowDate(1),//申请日期
|
|
|
+ projectName:val.projectName,
|
|
|
+ itp:val.radio=='4a4e2cfe-e1a1-11ee-81d4-00ff5c7a43f5'?'☑':'□',
|
|
|
+ etp:val.radio=='56f0ad8d-e1a1-11ee-81d4-00ff5c7a43f5'?'☑':'□',
|
|
|
+ ing:val.radio=='ed917c55-f51d-11ed-a3f6-509a4c5b67cf'?'☑':'□',
|
|
|
+ mone:val.checkList.includes('1')?'☑':'□',
|
|
|
+ mtwo:val.checkList.includes('2')?'☑':'□',
|
|
|
+ mthree:val.checkList.includes('3')?'☑':'□',
|
|
|
+ mfour:val.checkList.includes('4')?'☑':'□',
|
|
|
+ mfive:val.checkList.includes('5')?'☑':'□',
|
|
|
+ msix:val.checkList.includes('6')?'☑':'□',
|
|
|
+ mseven:val.checkList.includes('7')?'☑':'□',
|
|
|
+ sone:val.schoolRadio.includes('1')?'☑':'□',
|
|
|
+ stwo:val.schoolRadio.includes('2')?'☑':'□',
|
|
|
+ sthree:val.schoolRadio.includes('3')?'☑':'□',
|
|
|
+ sfour:val.schoolRadio.includes('4')?'☑':'□',
|
|
|
+ appPeason:val.applyParsonName,
|
|
|
+ school:val.dp,
|
|
|
+ tel:val.tel,
|
|
|
+ begin_at:val.btime.split(' ')[0],
|
|
|
+ plannedEnd_at:val.etime.split(' ')[0],
|
|
|
+ allnum:val.studentS.filter(i=>i.name!='').length+val.teacherS.filter(i=>i.name!='').length,
|
|
|
+ snum:val.studentS.filter(i=>i.name!='').length,
|
|
|
+ tnum:val.teacherS.filter(i=>i.name!='').length,
|
|
|
+ student:val.studentS,
|
|
|
+ teacher:val.teacherS,
|
|
|
+ brief:val.brief,
|
|
|
+ back:ImageList.find(i=>i.tagName=='back').url,
|
|
|
+ innovate:ImageList.find(i=>i.tagName=='innovate').url,
|
|
|
+ path:ImageList.find(i=>i.tagName=='path').url,
|
|
|
+ scene:ImageList.find(i=>i.tagName=='scene').url,
|
|
|
+ worth:ImageList.find(i=>i.tagName=='worth').url,
|
|
|
+ team:ImageList.find(i=>i.tagName=='team').url,
|
|
|
+ cost:ImageList.find(i=>i.tagName=='cost').url,
|
|
|
+ expectResults:ImageList.find(i=>i.tagName=='expectResults').url,
|
|
|
+ expectResultsTeacher:ImageList.find(i=>i.tagName=='expectResultsTeacher').url,
|
|
|
+ expectConversion:ImageList.find(i=>i.tagName=='expectConversion').url,
|
|
|
+ plan:ImageList.find(i=>i.tagName=='plan').url,
|
|
|
+ total:0,
|
|
|
+ facility:0,
|
|
|
+ materials:0,
|
|
|
+ process:0,
|
|
|
+ assist:0,
|
|
|
+ authenticate:0,
|
|
|
+ match:0,
|
|
|
+ activity:0,
|
|
|
+ affair:0,
|
|
|
+ total:val.fund.device*1 + val.fund.Material*1+val.fund.processing*1+ val.fund.Collaboration*1+val.fund.APPRAISAL*1+ val.fund.entery*1+val.fund.activities*1+val.fund.Transaction*1,
|
|
|
+ facility:val.fund.device,
|
|
|
+ materials:val.fund.Material,
|
|
|
+ process:val.fund.processing,
|
|
|
+ assist:val.fund.Collaboration,
|
|
|
+ authenticate:val.fund.APPRAISAL,
|
|
|
+ match:val.fund.entery,
|
|
|
+ activity:val.fund.activities,
|
|
|
+ affair:val.fund.Transaction,
|
|
|
+ signOne:val.signData.filter(i=>i.type==4)[0]?val.signData.filter(i=>i.type==4)[0].text:'',
|
|
|
+ signOnePerson:val.signData.filter(i=>i.type==4)[0]?val.signData.filter(i=>i.type==4)[0].username:'',
|
|
|
+ signOneTime:val.signData.filter(i=>i.type==4)[0]?val.signData.filter(i=>i.type==4)[0].time:'',
|
|
|
+
|
|
|
+ signTwo:val.signData.filter(i=>i.type==0)[0]?val.signData.filter(i=>i.type==0)[0].text:'',
|
|
|
+ signTwoPerson:val.signData.filter(i=>i.type==0)[0]?val.signData.filter(i=>i.type==0)[0].username:'',
|
|
|
+ signTwoTime:val.signData.filter(i=>i.type==0)[0]?val.signData.filter(i=>i.type==0)[0].time:'',
|
|
|
+
|
|
|
+ signThree:val.signData.filter(i=>i.type==3)[0]?val.signData.filter(i=>i.type==3)[0].text:'',
|
|
|
+ signThreePerson:val.signData.filter(i=>i.type==3)[0]?val.signData.filter(i=>i.type==3)[0].username:'',
|
|
|
+ signThreeTime:val.signData.filter(i=>i.type==3)[0]?val.signData.filter(i=>i.type==3)[0].time:'',
|
|
|
+ })
|
|
|
+
|
|
|
+ // 进行填充
|
|
|
+ doc.render()
|
|
|
+
|
|
|
+ let out=doc.getZip().generate({
|
|
|
+ type:'blob',
|
|
|
+ mimeType:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
+ })
|
|
|
+
|
|
|
+ // fs.writeFileSync(path.resolve(__dirname, "output.docx"), buf);
|
|
|
+ saveAs(out,'2024年校级学生创新创业训练计划项目申报书.docx')
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
function getImage(elList){
|
|
|
return new Promise(async (resolve)=>{
|
|
|
let imgList=[]
|
|
|
- elList.forEach(async el=>{
|
|
|
- let imgObj = {tagName:"",url:"",width:0,height:0}
|
|
|
- imgObj.tagName=el.getAttribute("tag");
|
|
|
- let canvas = await html2canvas(el,{
|
|
|
- allowTaint:true,
|
|
|
- useCORS:true,
|
|
|
- scale:2
|
|
|
- })
|
|
|
- imgObj.url = canvas.toDataURL('image/png');
|
|
|
- imgObj.width = canvas.width;
|
|
|
- imgObj.height = canvas.height;
|
|
|
- imgList.push(imgObj)
|
|
|
- if(imgList.length==elList.length){
|
|
|
- resolve(imgList)
|
|
|
- }
|
|
|
+ let promiseList = [];
|
|
|
+
|
|
|
+ elList.forEach(i=>{
|
|
|
+ promiseList.push(new Promise(async (resolve)=>{
|
|
|
+ let imgObj = {tagName:"",url:"",width:0,height:0}
|
|
|
+ imgObj.tagName=i.getAttribute("tag");
|
|
|
+ let canvas = await html2canvas(i,{
|
|
|
+ allowTaint:true,
|
|
|
+ useCORS:true,
|
|
|
+ scale:1
|
|
|
+ })
|
|
|
+ imgObj.url = canvas.toDataURL('image/png');
|
|
|
+ imgObj.width = canvas.width;
|
|
|
+ imgObj.height = canvas.height;
|
|
|
+ imgList.push(imgObj)
|
|
|
+ resolve();
|
|
|
+ }))
|
|
|
})
|
|
|
+
|
|
|
+ await Promise.all(promiseList).then(_=>resolve(imgList));
|
|
|
})
|
|
|
}
|
|
|
|