Q-ABAB 1 jaar geleden
bovenliggende
commit
013f28038d

BIN
public/file/附件 2:创客专项资金项目申请表(个人创客)模板.doc


BIN
public/file/附件 2:创客专项资金项目申请表(创客活动)模板.doc


BIN
public/file/附件 2:创客专项资金项目申请表(创客活动)模板.docx


+ 108 - 1
src/components/tool/getWord.js

@@ -590,11 +590,118 @@ function ActivityWord(data){
     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;
+        //转成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);
+          
+            //模板数据
+            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'])
+
+            // device:"",
+            //         Material:"",
+            //         processing:"",
+            //         Collaboration:"",
+            //         APPRAISAL:"",
+            //         entery:"",
+            //         activities:"",
+            //         Transaction:"",
+            // return console.log(wordData);
+            //渲染模板
+            // doc.setData(wordData);
+
+            // 注册一个自定义的数组模板标签处理器 {{index numbers 0}}
+     // 注册一个自定义的模板标签处理器,用于处理数组索引
+        // doc.setOptions({
+        //     parser: function (tag) {
+        //       if (tag.position === 'content' && tag.type === 'placeholder') {
+        //         const [property] = tag.parts;
+        //         const value = tag.moduleContext.scope.find(property).value;
+            
+        //         return value;
+        //       }
+        //     }
+        //   });
+
+            // 注册一个自定义对象的模板标签处理器 {{obj.a}}
+            // doc.setOptions({
+            //     parser: function (tag) {
+            //       if (tag.position === 'content') {
+            //         const value = tag.moduleContext.scope.resolve(tag.originalValue);
+                
+            //         return value;
+            //       }
+            //     }
+            //   });
+
+            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()
+}
+
 
 export{
     MakerSpaceWord,
     getMakerSpaceWord,
     MakerStudentWord,
     ActivityWord,
-    getWord
+    getWord,
+    makerActivityWord,
 }

+ 10 - 1
src/views/activityManage/makerActivityWordDetail.vue

@@ -12,7 +12,7 @@
         <markeractivityWordShow v-if="wordData['state']!=0" :wordData="wordData" :total="total"/>
         <div>
             <el-button type="primary" v-if="wordData['state']==0" @click="test">立即修改</el-button>
-            <el-button type="primary">下载表单</el-button>
+            <el-button type="primary" @click="getActivityWord">下载表单</el-button>
         </div>
         <el-dialog
           title="提示"
@@ -33,6 +33,7 @@
   import markeractivityWord from './components/markeractivityWord.vue'
   import NomMarkerWord from './components/NomMarkerWord.vue'
   import markeractivityWordShow from './components/markeractivityWordShow.vue'
+  import {makerActivityWord} from '@/components/tool/getWord'
       export default {
         components:{markeractivityWord,NomMarkerWord,markeractivityWordShow},
         data() {
@@ -245,6 +246,14 @@
               }).catch(err=>{
                 console.log(err)
               })
+            },
+            getActivityWord(){
+              // if(this.wordData['type']==0){
+                // this.$message.info("正在下载创客活动表单");
+                makerActivityWord(this.wordData,this.total)
+              // }else if(this.wordData['type']==1){
+                // this.$message.info("正在下载个人创客表单")
+              // }
             }
           },
           computed:{