瀏覽代碼

点击下载

gcj 2 年之前
父節點
當前提交
ea51152568
共有 3 個文件被更改,包括 321 次插入188 次删除
  1. 5 5
      package-lock.json
  2. 80 7
      src/views/wordcard/cread.vue
  3. 236 176
      src/views/wordcard/writeTable.vue

+ 5 - 5
package-lock.json

@@ -2654,7 +2654,7 @@
     },
     "base64-arraybuffer": {
       "version": "1.0.2",
-      "resolved": "https://registry.npmmirror.com/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
+      "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
       "integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ=="
     },
     "base64-js": {
@@ -4239,7 +4239,7 @@
     },
     "css-line-break": {
       "version": "2.1.0",
-      "resolved": "https://registry.npmmirror.com/css-line-break/-/css-line-break-2.1.0.tgz",
+      "resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
       "integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
       "requires": {
         "utrie": "^1.0.2"
@@ -6744,7 +6744,7 @@
     },
     "html2canvas": {
       "version": "1.4.1",
-      "resolved": "https://registry.npmmirror.com/html2canvas/-/html2canvas-1.4.1.tgz",
+      "resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
       "integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
       "requires": {
         "css-line-break": "^2.1.0",
@@ -12615,7 +12615,7 @@
     },
     "text-segmentation": {
       "version": "1.0.3",
-      "resolved": "https://registry.npmmirror.com/text-segmentation/-/text-segmentation-1.0.3.tgz",
+      "resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
       "integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
       "requires": {
         "utrie": "^1.0.2"
@@ -13172,7 +13172,7 @@
     },
     "utrie": {
       "version": "1.0.2",
-      "resolved": "https://registry.npmmirror.com/utrie/-/utrie-1.0.2.tgz",
+      "resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
       "integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
       "requires": {
         "base64-arraybuffer": "^1.0.2"

+ 80 - 7
src/views/wordcard/cread.vue

@@ -129,7 +129,7 @@
         <div @click="previewEvent">
           <img src="../../assets/teacherdev/word-eyes.png" alt="" /> 预览
         </div>
-        <div @click="download">
+        <div @click="download('pdfDom')">
           <img src="../../assets/teacherdev/word-download.png" alt="" /> 下载
         </div>
       </div>
@@ -208,7 +208,9 @@
 import Header from "@/components/Header";
 import { getLogin } from "@/api/api";
 import writeTable from "./writeTable.vue";
+import html2canvas from "html2canvas";
 import { jsPDF } from "jspdf";
+import canvg from "canvg";
 export default {
   //import引入的组件需要注入到对象中才能使用
   components: {
@@ -257,7 +259,78 @@ export default {
     handleClose() {
       this.saveShow = false;
     },
-    download() {
+    download(dom) {
+      let content = document.getElementById(dom);
+      content = content ? content : null;
+      // 条件判断是否打印
+      if (!content) {
+        alert("打印失败,请重新操作");
+        return false;
+      }
+      // 开始打印
+      console.log(content);
+      var contentWidth = content.width;
+      var contentHeight = content.height;
+      //以下是对svg的处理
+      var nodesToRecover = [];
+      var nodesToRemove = [];
+      var svgElem = $("#pdfDom").find("svg-icon"); //divReport为需要截取成图片的dom的id
+      console.log(svgElem);
+      svgElem.each(function (index, node) {
+        var parentNode = node.parentNode;
+        var svg = node.outerHTML.trim();
+        var canvas2 = document.createElement("canvas");
+        canvg(canvas2, svg);
+        if (node.style.position) {
+          canvas2.style.position += node.style.position;
+          canvas2.style.left += node.style.left;
+          canvas2.style.top += node.style.top;
+        }
+        nodesToRecover.push({
+          parent: parentNode,
+          child: node,
+        });
+        parentNode.removeChild(node);
+        nodesToRemove.push({
+          parent: parentNode,
+          child: canvas2,
+        });
+        parentNode.appendChild(canvas2);
+      });
+      var canvas = document.createElement("canvas");
+      canvas.width = contentWidth;
+      canvas.height = contentHeight;
+      var context = canvas.getContext("2d");
+      html2canvas(content, {
+        allowTaint: true,
+        scale: 2, // 提升画面质量,但是会增加文件大小
+      }).then(function (canvas) {
+        var pdfWidth = canvas.width;
+        var pdfHeight = canvas.height;
+        var pageHeight = (pdfWidth / 592.28) * 841.89;
+        var leftHeight = pdfHeight;
+        var position = 0;
+        var imgWidth = 595.28;
+        var imgHeight = (595.28 / pdfWidth) * pdfHeight;
+        var pageData = canvas.toDataURL("img/jpeg", 1.0);
+        var pdf = new jsPDF("", "pt", "a4");
+        // 判断打印dom高度是否需要分页,如果需要进行分页处理
+        if (leftHeight < pageHeight) {
+          pdf.addImage(pageData, "JPEG", 0, 0, imgWidth, imgHeight);
+        } else {
+          while (leftHeight > 0) {
+            pdf.addImage(pageData, "JPEG", 0, position, imgWidth, imgHeight);
+            leftHeight -= pageHeight;
+            position -= 841.89;
+            if (leftHeight > 0) {
+              pdf.addPage();
+            }
+          }
+        }
+        pdf.save("案例.pdf");
+      });
+    },
+    download2() {
       // 1
       // this.getPdf("#pdfDom")
       // 2
@@ -978,11 +1051,11 @@ export default {
     .el-switch__label.is-active {
       color: #000000;
     }
-    .numbre-input{
-        .el-input__inner {
-            padding: 0;
-            text-align: center;
-        }
+    .numbre-input {
+      .el-input__inner {
+        padding: 0;
+        text-align: center;
+      }
     }
   }
 }

+ 236 - 176
src/views/wordcard/writeTable.vue

@@ -1,77 +1,145 @@
 <template>
   <div class="writeTable" v-if="data">
     <div class="writeTop">
-        <div class="writeTop-row" v-for="(itemR,indexR) in data" :key="indexR" :style="{marginBottom:dataConfig.marginBottom}">
-            <div class="writeTop-item" :class="[indexI!==0?'writeTop-item-noLeft':'']" v-for="(itemI,indexI) in itemR" :key="indexI" :style="{width:dataConfig.width,height:dataConfig.width,borderColor:dataConfig.borderColor}">
-                <template v-if="itemI&&itemI.con&&!itemI.write&&!itemI.answer&&!itemI.miaoRed">
-                    <Strockplay
-                        v-if="'writeTop-item-' + pageNumber + '-' + indexR + '-' + indexI + type"
-                        className="adult-strockplay"
-                        :strokePlayColor="dataConfig.borderColor"
-                        :Book_text="itemI.con"
-                        :playStorkes="dataConfig.playStorkes"
-                        :strokeColor="dataConfig.fontColor"
-                        :palyWidth="dataConfig.playWidth"
-                        :BoxbgType="dataConfig.BoxbgType"
-                        :targetDiv="'writeTop-item-' + pageNumber + '-' + indexR + '-' + indexI + type"
-                     />
-                </template>
-                <template v-else-if="itemI&&itemI.answer">
-                    <StrockplayredlineTable
-                        :Book_text="itemI.con"
-                        :playStorkes="false"
-                        :strokeColorgray="dataConfig.miaoRedBgcolor"
-                        :strokeColor="dataConfig.fontColor"
-                        :strokeNumber="itemI.answer"
-                        :curItem="itemI.hzDetail"
-                        :BoxbgType="dataConfig.BoxbgType"
-                        :targetDiv="
-                            'write-item-miaohong-' +
-                            pageNumber + '-' + indexR + '-' + indexI + type + itemI.con
-                        "
-                        :targetDivGray="'write-item-miaohong-gray-'+
-                            pageNumber + '-' + indexR + '-' + indexI + type + itemI.con"
-                    />
-                </template>
-                <template v-else-if="itemI&&itemI.miaoRed">
-                    <Strockred
-                        v-if="'write-item-' + pageNumber + '-' + indexR + '-' + indexI + type"
-                        className="adult-strockplay"
-                        :strokePlayColor="dataConfig.borderColor"
-                        :Book_text="itemI.con"
-                        :curItem="itemI.hzDetail"
-                        :hanzicolor="dataConfig.miaoRedBgcolor"
-                        :drawingColor="dataConfig.writeColor"
-                        :BoxbgType="dataConfig.BoxbgType"
-                        :targetDiv="'write-item-' + pageNumber + '-' + indexR + '-' + indexI + type + itemI.con"
-                     />
-                </template>
-                <div v-else-if="itemI" class="tian-div" @click="freeWrite(itemI,indexR,indexI)">
-                    <svg-icon
-                        icon-class="tian"
-                        className="tian"
-                        v-if="dataConfig.BoxbgType==0"
-                        :style="{color:'#DEDEDE'}"
-                    />
-                    <svg-icon
-                        icon-class="mi"
-                        className="tian"
-                        v-if="dataConfig.BoxbgType==1"
-                        :style="{color:'#DEDEDE'}"
-                    />
-                    <img
-                        v-if="itemI&&itemI.strokes_image_url"
-                        :src="itemI.strokes_image_url"
-                        alt=""
-                    />
-                </div>
-            </div>
+      <div
+        class="writeTop-row"
+        v-for="(itemR, indexR) in data"
+        :key="indexR"
+        :style="{ marginBottom: dataConfig.marginBottom }"
+      >
+        <div
+          class="writeTop-item"
+          :class="[indexI !== 0 ? 'writeTop-item-noLeft' : '']"
+          v-for="(itemI, indexI) in itemR"
+          :key="indexI"
+          :style="{
+            width: dataConfig.width,
+            height: dataConfig.width,
+            borderColor: dataConfig.borderColor,
+          }"
+        >
+          <template
+            v-if="
+              itemI &&
+              itemI.con &&
+              !itemI.write &&
+              !itemI.answer &&
+              !itemI.miaoRed
+            "
+          >
+            <Strockplay
+              v-if="
+                'writeTop-item-' +
+                pageNumber +
+                '-' +
+                indexR +
+                '-' +
+                indexI +
+                type
+              "
+              className="adult-strockplay"
+              :strokePlayColor="dataConfig.borderColor"
+              :Book_text="itemI.con"
+              :playStorkes="dataConfig.playStorkes"
+              :strokeColor="dataConfig.fontColor"
+              :palyWidth="dataConfig.playWidth"
+              :BoxbgType="dataConfig.BoxbgType"
+              :targetDiv="
+                'writeTop-item-' +
+                pageNumber +
+                '-' +
+                indexR +
+                '-' +
+                indexI +
+                type
+              "
+            />
+          </template>
+          <template v-else-if="itemI && itemI.answer">
+            <StrockplayredlineTable
+              :Book_text="itemI.con"
+              :playStorkes="false"
+              :strokeColorgray="dataConfig.miaoRedBgcolor"
+              :strokeColor="dataConfig.fontColor"
+              :strokeNumber="itemI.answer"
+              :curItem="itemI.hzDetail"
+              :BoxbgType="dataConfig.BoxbgType"
+              :targetDiv="
+                'write-item-miaohong-' +
+                pageNumber +
+                '-' +
+                indexR +
+                '-' +
+                indexI +
+                type +
+                itemI.con
+              "
+              :targetDivGray="
+                'write-item-miaohong-gray-' +
+                pageNumber +
+                '-' +
+                indexR +
+                '-' +
+                indexI +
+                type +
+                itemI.con
+              "
+            />
+          </template>
+          <template v-else-if="itemI && itemI.miaoRed">
+            <Strockred
+              v-if="
+                'write-item-' + pageNumber + '-' + indexR + '-' + indexI + type
+              "
+              className="adult-strockplay"
+              :strokePlayColor="dataConfig.borderColor"
+              :Book_text="itemI.con"
+              :curItem="itemI.hzDetail"
+              :hanzicolor="dataConfig.miaoRedBgcolor"
+              :drawingColor="dataConfig.writeColor"
+              :BoxbgType="dataConfig.BoxbgType"
+              :targetDiv="
+                'write-item-' +
+                pageNumber +
+                '-' +
+                indexR +
+                '-' +
+                indexI +
+                type +
+                itemI.con
+              "
+            />
+          </template>
+          <div
+            v-else-if="itemI"
+            class="tian-div"
+            @click="freeWrite(itemI, indexR, indexI)"
+          >
+            <svg-icon
+              icon-class="tian"
+              className="tian"
+              v-if="dataConfig.BoxbgType == 0"
+              :style="{ color: '#DEDEDE' }"
+            />
+            <svg-icon
+              icon-class="mi"
+              className="tian"
+              v-if="dataConfig.BoxbgType == 1"
+              :style="{ color: '#DEDEDE' }"
+            />
+            <img
+              v-if="itemI && itemI.strokes_image_url"
+              :src="itemI.strokes_image_url"
+              alt=""
+            />
+          </div>
         </div>
+      </div>
     </div>
     <div class="writeBottom">
-        <span>BLCUP 全球国际中文教学云平台</span>
-        <b>{{pageNumber + '/' + totalNumber}}</b>
-        <a>www.chinesedu.com</a>
+      <span>BLCUP 全球国际中文教学云平台</span>
+      <b>{{ pageNumber + "/" + totalNumber }}</b>
+      <a>www.chinesedu.com</a>
     </div>
     <div class="practiceBox practiceBoxStrock" v-if="ifFreeShow">
       <FreewriteLettle
@@ -91,9 +159,9 @@
 <script>
 //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
 import StrockplayredlineTable from "../../components/corpus/StrockplayredlineTable.vue";
-import Strockplay from "../../components/corpus/Strockplay.vue"
-import Strockred from "../../components/corpus/Strockred.vue"
-import FreewriteLettle from "../../components/corpus/FreewriteLettle.vue"
+import Strockplay from "../../components/corpus/Strockplay.vue";
+import Strockred from "../../components/corpus/Strockred.vue";
+import FreewriteLettle from "../../components/corpus/FreewriteLettle.vue";
 
 export default {
   //import引入的组件需要注入到对象中才能使用
@@ -101,21 +169,15 @@ export default {
     StrockplayredlineTable,
     Strockplay,
     Strockred,
-    FreewriteLettle
+    FreewriteLettle,
   },
-  props: [
-    "dataConfig",
-    "data",
-    "pageNumber",
-    "totalNumber",
-    "type"
-  ],
+  props: ["dataConfig", "data", "pageNumber", "totalNumber", "type"],
   data() {
     //这里存放数据
     return {
-        ifFreeShow: false,
-        activeIndex: null,
-        activeColIndex: null,
+      ifFreeShow: false,
+      activeIndex: null,
+      activeColIndex: null,
     };
   },
   //计算属性 类似于data概念
@@ -135,28 +197,26 @@ export default {
       this.ifFreeShow = true;
       this.activeIndex = row;
       this.activeColIndex = col;
-    //   this.currentHz = this.curQue.option[indexs].rightOption[rightindex].con;
-      if(item){
+      //   this.currentHz = this.curQue.option[indexs].rightOption[rightindex].con;
+      if (item) {
         this.currenHzData = item;
-      }else{
+      } else {
         this.currenHzData = {};
       }
-      
     },
-    ExerciseChangeCurQue(answer, rowIndex, colIndex ) {
+    ExerciseChangeCurQue(answer, rowIndex, colIndex) {
       if (answer) {
-        this.data[rowIndex][colIndex].strokes_image_url = answer.strokes_image_url;
-        this.data[rowIndex][colIndex].history = answer.history
+        this.data[rowIndex][colIndex].strokes_image_url =
+          answer.strokes_image_url;
+        this.data[rowIndex][colIndex].history = answer.history;
         this.$forceUpdate();
       }
     },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
-  created() {
-  },
+  created() {},
   //生命周期 - 挂载完成(可以访问DOM元素)
-  mounted() {
-  },
+  mounted() {},
   //生命周期-创建之前
   beforeCreated() {},
   //生命周期-挂载之前
@@ -174,93 +234,93 @@ export default {
 };
 </script>
 <style lang="scss" scoped>
-.writeTable{
-    background: #FFFFFF;
-    border: 1px solid rgba(0, 0, 0, 0.08);
-    width: 595px;
-    height: 842px;
-    box-sizing: border-box;
-    .writeTop{
-        height: 732px;
-        padding-top: 48px;
-        .writeTop-row{
-            display: flex;
-            justify-content: center;
-            .writeTop-item{
-                border: 1px solid #DE4444;
-                &.writeTop-item-noLeft{
-                    border-left: none;
-                }
-            }
+.writeTable {
+  background: #ffffff;
+  border: 1px solid rgba(0, 0, 0, 0.08);
+  width: 595px;
+  height: 842px;
+  box-sizing: border-box;
+  .writeTop {
+    height: 732px;
+    padding-top: 48px;
+    .writeTop-row {
+      display: flex;
+      justify-content: center;
+      .writeTop-item {
+        border: 1px solid #de4444;
+        &.writeTop-item-noLeft {
+          border-left: none;
         }
+      }
     }
-    .writeBottom{
-        display: flex;
-        width: 100%;
-        justify-content: space-between;
-        padding: 0 38px;
-        box-sizing: border-box;
-        position: relative;
-        span{
-            font-weight: 500;
-            font-size: 10px;
-            line-height: 14px;
-            color: #000000;
-            opacity: 0.2;
-        }
-        b{
-            font-weight: 400;
-            font-size: 14px;
-            line-height: 14px;
-            color: #000000;
-            width: 60px;
-            text-align: center;
-            position: absolute;
-            left: 50%;
-            margin-left: -30px;
-            top: 0px;
-        }
-        a{
-            font-weight: 500;
-            font-size: 12px;
-            line-height: 14px;
-            color: #000000;
-            opacity: 0.2;
-        }
+  }
+  .writeBottom {
+    display: flex;
+    width: 100%;
+    justify-content: space-between;
+    padding: 0 38px;
+    box-sizing: border-box;
+    position: relative;
+    span {
+      font-weight: 500;
+      font-size: 10px;
+      line-height: 14px;
+      color: #000000;
+      opacity: 0.2;
     }
-    .tian-div{
-        width: 100%;
-        height: 100%;
-        position: relative;
-        .tian{
-            width: 100%;
-            height: 100%;
-        }
-        img{
-            width: 100%;
-            height: 100%;
-            position: absolute;
-            left: 0;
-            top: 0;
-        }
+    b {
+      font-weight: 400;
+      font-size: 14px;
+      line-height: 14px;
+      color: #000000;
+      width: 60px;
+      text-align: center;
+      position: absolute;
+      left: 50%;
+      margin-left: -30px;
+      top: 0px;
     }
-    .practiceBox {
-        position: fixed;
-        left: 0;
-        top: 0;
-        z-index: 100100;
-        width: 100%;
-        height: 100vh;
-        background: rgba(0, 0, 0, 0.19);
-        box-sizing: border-box;
-        overflow: hidden;
-        overflow-y: auto;
-        &.practiceBoxStrock {
-            display: flex;
-            justify-content: center;
-            align-items: center;
-            padding-top: 0px;
-        }
+    a {
+      font-weight: 500;
+      font-size: 12px;
+      line-height: 14px;
+      color: #000000;
+      opacity: 0.2;
+    }
+  }
+  .tian-div {
+    width: 100%;
+    height: 100%;
+    position: relative;
+    .tian {
+      width: 100%;
+      height: 100%;
+    }
+    img {
+      width: 100%;
+      height: 100%;
+      position: absolute;
+      left: 0;
+      top: 0;
+    }
+  }
+  .practiceBox {
+    position: fixed;
+    left: 0;
+    top: 0;
+    z-index: 100100;
+    width: 100%;
+    height: 100vh;
+    background: rgba(0, 0, 0, 0.19);
+    box-sizing: border-box;
+    overflow: hidden;
+    overflow-y: auto;
+    &.practiceBoxStrock {
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      padding-top: 0px;
     }
+  }
 }
 </style>