Bladeren bron

下载word

SanHQin 1 jaar geleden
bovenliggende
commit
50b6a6134a

BIN
public/file/2023年学生创客项目申报书模板 - 副本.docx


BIN
public/file/2023年学生创客项目申报书模板.docx


+ 20 - 20
src/components/tool/getWord.js

@@ -493,26 +493,26 @@ function getWord(val){
             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,
+            back:val.introduce.back.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            innovate:val.introduce.innovate.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            path:val.introduce.path.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            scene:val.introduce.scene.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            worth:val.introduce.worth.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            team:val.introduce.team.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            cost:val.introduce.cost.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            expectResults:val.introduce.expectResults.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            expectResultsTeacher:val.introduce.expectResultsTeacher.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            expectConversion:val.introduce.expectConversion.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            plan:val.introduce.plan.replace(/<\/?.+?\/?>/g,"").replace(/&nbsp;/gi,' '),
+            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,
         })
 
         // 进行填充

+ 166 - 0
src/components/tool/getWord2.js

@@ -0,0 +1,166 @@
+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'
+import html2canvas from 'html2canvas'
+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]
+					}
+				}
+				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')
+
+    })
+}
+
+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)
+			}
+		})
+	})
+}
+
+// 
+
+function base64DataURLToArrayBuffer(dataURL) {
+  const base64Regex = /^data:image\/(png|jpg|svg|svg\+xml);base64,/;
+  if (!base64Regex.test(dataURL)) {
+    return false;
+  }
+  const stringBase64 = dataURL.replace(base64Regex, "");
+  let binaryString;
+  if (typeof window !== "undefined") {
+    binaryString = window.atob(stringBase64);
+  } else {
+    binaryString = new Buffer(stringBase64, "base64").toString("binary");
+  }
+  const len = binaryString.length;
+  const bytes = new Uint8Array(len);
+  for (let i = 0; i < len; i++) {
+    const ascii = binaryString.charCodeAt(i);
+    bytes[i] = ascii;
+  }
+  return bytes.buffer;
+}
+
+export{
+    getWord2,
+}

+ 75 - 7
src/views/projectApply/components/studentProjectWordDetail.vue

@@ -13,17 +13,23 @@
     />
     <div
       style="
-        width: 300px;
+        width: 500px;
         margin: 20px auto;
         display: flex;
         justify-content: space-between;
       "
-    >
+    >	
+			<el-button
+        style="width: 140px; margin: 20px auto"
+        @click="downloadWordDig = true"
+        type="primary"
+        >下载文档(Word)</el-button
+      >
       <el-button
-        style="width: 120px; margin: 20px auto"
+        style="width: 140px; margin: 20px auto"
         @click="downloadDig = true"
         type="primary"
-        >下载文档</el-button
+        >下载文档(PDF)</el-button
       >
       <el-button
         style="width: 120px; margin: 20px auto"
@@ -54,14 +60,14 @@
 
     <!-- 下载文档开始 -->
     <el-dialog
-      title="下载文档"
+      title="下载文档(PDF)"
       :visible.sync="downloadDig"
       width="600px"
       class="pageSubmitData"
     >
       <div class="deleteContent">确定下载文档?</div>
       <span slot="footer" class="dialog-footer">
-        <el-button type="primary" @click="downloadWord" class="AllDialogBtn"
+        <el-button type="primary" @click="downloadPDFFile" class="AllDialogBtn"
           >确认</el-button
         >
         <el-button @click="downloadDig = false" class="AllDialogBtn"
@@ -69,6 +75,26 @@
         >
       </span>
     </el-dialog>
+
+		<el-dialog
+      title="下载文档(Word)"
+      :visible.sync="downloadWordDig"
+      width="600px"
+      class="pageSubmitData"
+    >
+      <div class="deleteContent">确定下载文档?</div>
+      <span slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="downloadWordFile" class="AllDialogBtn"
+          >确认</el-button
+        >
+				<!-- <el-button type="primary" @click="downloadWord2" class="AllDialogBtn"
+          >确认2</el-button
+        > -->
+        <el-button @click="downloadWordDig = false" class="AllDialogBtn"
+          >取消</el-button
+        >
+      </span>
+    </el-dialog>
     <!-- 下载文档结束-->
   </div>
 </template>
@@ -87,6 +113,7 @@ export default {
       isupload: 1,
       DepartmentData: [], //部门学院
       downloadDig: false, //下载文档对话框
+			downloadWordDig:false,
       updatedWordDig: false, //立即修改对话框
       downWordData: {
         applicationDate: getNowDate(1), //申请日期
@@ -491,16 +518,57 @@ export default {
           }
         );
     },
-    downloadWord() {
+		downloadWordFile(){
+			getWord(this.downWordData);
+			this.downloadWordDig = false;
+		},
+    downloadPDFFile() {
+			// let elementList = this.$refs.myChild.$refs.pdfShow.querySelectorAll('.downImage')
+			// elementList.forEach(el => {
+			//   let img = el.getElementsByTagName('img');
+			// 	for(let i=0;i<img.length;i++){
+			// 		img[i].crossOrigin = "*"
+			// 	}
+			// })
       downloadPDF(
         this.$refs.myChild.$refs.pdfShow,
         "附件2:2023年学生创客项目申报书"
       );
       // this.wordData['total']=this.wordData.fund.facility*1 + this.wordData.fund.materials*1+this.wordData.fund.process*1+ this.wordData.fund.assist*1+this.wordData.fund.authenticate*1+ this.wordData.fund.match*1+this.wordData.fund.activity*1+this.wordData.fund.affair*1
       // return console.log(this.wordData);
+			// let elementList = this.$refs.myChild.$refs.pdfShow.querySelectorAll('.downImage')
+			// elementList.forEach(el => {
+			//   let img = el.getElementsByTagName('img');
+			// 	for(let i=0;i<img.length;i++){
+			// 		img[i].crossOrigin = "*"
+			// 	}
+			// })
+			// return console.log(elementList)
+      // getWord({...this.downWordData,elementList:this.$refs.myChild.$refs.pdfShow.querySelectorAll('.downImage')})
       // getWord(this.downWordData)
+
       this.downloadDig = false;
     },
+		// downloadWord2() {
+    //   // downloadPDF(
+    //   //   this.$refs.myChild.$refs.pdfShow,
+    //   //   "附件2:2023年学生创客项目申报书"
+    //   // );
+    //   // this.wordData['total']=this.wordData.fund.facility*1 + this.wordData.fund.materials*1+this.wordData.fund.process*1+ this.wordData.fund.assist*1+this.wordData.fund.authenticate*1+ this.wordData.fund.match*1+this.wordData.fund.activity*1+this.wordData.fund.affair*1
+    //   // return console.log(this.wordData);
+		// 	let elementList = this.$refs.myChild.$refs.pdfShow.querySelectorAll('.downImage')
+		// 	elementList.forEach(el => {
+		// 	  let img = el.getElementsByTagName('img');
+		// 		for(let i=0;i<img.length;i++){
+		// 			img[i].crossOrigin = "*"
+		// 		}
+		// 	})
+		// 	// return console.log(elementList)
+    //   getWord2({...this.downWordData,elementList:this.$refs.myChild.$refs.pdfShow.querySelectorAll('.downImage')})
+    //   // getWord(this.downWordData)
+
+    //   this.downloadDig = false;
+    // },
   },
   //小型仪器设备费:device        deviceRemarks
   //材料费:Material             MaterialRemarks

+ 11 - 11
src/views/projectApply/components/studentProjectWordShow.vue

@@ -92,71 +92,71 @@
           <tr>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>项目研发背景</p>
-              <span v-html="downWordData.introduce.back"></span>
+              <span class="downImage" tag="back" v-html="downWordData.introduce.back"></span>
             </td>
           </tr>
           <tr>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>项目创新点</p>
-              <span v-html="downWordData.introduce.innovate"></span>
+              <span class="downImage" tag="innovate" v-html="downWordData.introduce.innovate"></span>
             </td>
           </tr>
           <tr>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>技术研发路线</p>
-              <span v-html="downWordData.introduce.path"></span>
+              <span class="downImage" tag="path" v-html="downWordData.introduce.path"></span>
             </td>
           </tr>
           <tr>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>项目应用场景 </p>
-              <span v-html="downWordData.introduce.scene"></span>
+              <span class="downImage" tag="scene" v-html="downWordData.introduce.scene"></span>
             </td>
           </tr>
           <tr>
             <td> <span class="jc">商业模式</span><br><br> <span class="jc">及社会价值</span></td>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>项目商业模式/社会价值</p>
-              <span v-html="downWordData.introduce.worth"></span>
+              <span class="downImage" tag="worth" v-html="downWordData.introduce.worth"></span>
             </td>
           </tr>
           <tr>
             <td><span class="jc">团队</span><br><br> <span class="jc">优势</span></td>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>团队构成及优势</p>
-              <span v-html='downWordData.introduce.team'></span>
+              <span class="downImage" tag="team" v-html='downWordData.introduce.team'></span>
             </td>
           </tr>
           <tr>
             <td><span class="jc">研发</span><br><br> <span class="jc">成本</span></td>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>研发成本来源及构成</p>
-              <span v-html="downWordData.introduce.cost"></span>
+              <span class="downImage" tag="cost" v-html="downWordData.introduce.cost"></span>
             </td>
           </tr>
           <tr>
             <td rowspan="3"><span class="jc">预期</span><br><br> <span class="jc">成果</span></td>
             <td style="text-align: left;" colspan="6" class="textLeft">
               <p>项目预期成果、数量及形式(产品原型/发明专利/双创竞赛/成果转化/社会效益)</p>
-              <span v-html="downWordData.introduce.expectResults"></span>
+              <span class="downImage" tag="expectResults" v-html="downWordData.introduce.expectResults"></span>
             </td>
           </tr>
           <tr class="textLeft">
             <td style="text-align: left;" colspan="6">
               <p>学生创客人才培养预期成果、数量(教师填写)</p>
-              <span v-html="downWordData.introduce.expectResultsTeacher"></span>
+              <span class="downImage" tag="expectResultsTeacher" v-html="downWordData.introduce.expectResultsTeacher"></span>
             </td>
           </tr>
           <tr class="textLeft">
             <td style="text-align: left;" colspan="6">
               <p>项目预期孵化、转化创业项目情况</p>
-              <span v-html="downWordData.introduce.expectConversion"></span>
+              <span class="downImage" tag="expectConversion" v-html="downWordData.introduce.expectConversion"></span>
             </td>
           </tr>
           <tr>
             <td><span class="jc">实施</span><br><br> <span class="jc">计划</span></td>
             <td style="text-align: left;" colspan="6" class="textLeft">
-              <span v-html="downWordData.introduce.plan"></span>
+              <span class="downImage" tag="plan" v-html="downWordData.introduce.plan"></span>
             </td>
           </tr>
           <tr id="fund">