Переглянути джерело

添加插件实现同屏对比导出操作

DESKTOP-6LTVLN7\Liumouren 2 роки тому
батько
коміт
25e52fd0c0
3 змінених файлів з 151 додано та 23 видалено
  1. 38 0
      package-lock.json
  2. 1 0
      package.json
  3. 112 23
      src/components/common/BottomForm/SameScreenComparison.vue

+ 38 - 0
package-lock.json

@@ -12410,6 +12410,11 @@
       "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
       "dev": true
     },
+    "base64-arraybuffer": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmmirror.com/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
+      "integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ=="
+    },
     "base64-js": {
       "version": "1.5.1",
       "resolved": "https://registry.npmmirror.com/base64-js/-/base64-js-1.5.1.tgz",
@@ -13038,6 +13043,14 @@
       "dev": true,
       "requires": {}
     },
+    "css-line-break": {
+      "version": "2.1.0",
+      "resolved": "https://registry.npmmirror.com/css-line-break/-/css-line-break-2.1.0.tgz",
+      "integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
+      "requires": {
+        "utrie": "^1.0.2"
+      }
+    },
     "css-loader": {
       "version": "6.7.2",
       "resolved": "https://registry.npmmirror.com/css-loader/-/css-loader-6.7.2.tgz",
@@ -14202,6 +14215,15 @@
         "tapable": "^2.0.0"
       }
     },
+    "html2canvas": {
+      "version": "1.4.1",
+      "resolved": "https://registry.npmmirror.com/html2canvas/-/html2canvas-1.4.1.tgz",
+      "integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
+      "requires": {
+        "css-line-break": "^2.1.0",
+        "text-segmentation": "^1.0.3"
+      }
+    },
     "htmlparser2": {
       "version": "6.1.0",
       "resolved": "https://registry.npmmirror.com/htmlparser2/-/htmlparser2-6.1.0.tgz",
@@ -16846,6 +16868,14 @@
         }
       }
     },
+    "text-segmentation": {
+      "version": "1.0.3",
+      "resolved": "https://registry.npmmirror.com/text-segmentation/-/text-segmentation-1.0.3.tgz",
+      "integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
+      "requires": {
+        "utrie": "^1.0.2"
+      }
+    },
     "thenify": {
       "version": "3.3.1",
       "resolved": "https://registry.npmmirror.com/thenify/-/thenify-3.3.1.tgz",
@@ -17044,6 +17074,14 @@
       "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
       "dev": true
     },
+    "utrie": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmmirror.com/utrie/-/utrie-1.0.2.tgz",
+      "integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
+      "requires": {
+        "base64-arraybuffer": "^1.0.2"
+      }
+    },
     "uuid": {
       "version": "8.3.2",
       "resolved": "https://registry.npmmirror.com/uuid/-/uuid-8.3.2.tgz",

+ 1 - 0
package.json

@@ -12,6 +12,7 @@
     "deep-clone": "^3.0.3",
     "echarts": "^5.4.0",
     "element-ui": "^2.15.10",
+    "html2canvas": "^1.4.1",
     "jquery": "^3.6.1",
     "vue": "^2.6.14",
     "vue-router": "^3.5.1",

+ 112 - 23
src/components/common/BottomForm/SameScreenComparison.vue

@@ -8,9 +8,14 @@
       </div>
     </template>
     <!-- 同屏对比主题 -->
-    <div class="ssc_main">
+    <div
+      class="ssc_main"
+      id="doPrint"
+      ref="doPrint"
+      :style="{ height: !subMitStatus ? 'calc(100vh - 190px)' : 'calc(100vh - 310px)' }"
+    >
       <!-- 地图列表 -->
-      <div class="ssc_main_mapList" :style="{ width: subMitStatus ? '100%' : '60%' }">
+      <div class="ssc_main_mapList">
         <div
           class="ssc_main_mapList_showList"
           :id="'map' + index"
@@ -31,18 +36,15 @@
       </div>
       <!-- 底图列表 -->
       <div class="ssc_main_aimapList" v-show="!subMitStatus">
-        <span>地图底图(最多只能选择6个)</span>
-        <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
+        <span>地图底图(最多选择6个) </span>
+        <div>
+          已选择<span class="checkLength">{{ checkedCities.length }}</span
+          >个
+        </div>
+        <el-checkbox-group id="mapCheckBox" v-model="checkedCities" @change="handleCheckedCitiesChange">
           <el-checkbox
             class="mapCheckBox"
             :disabled="checkedCities.length >= 6 && checkedCities.indexOf(index) == -1"
-            @click="
-              index => {
-                if (this.checkedCities.length >= 6 && this.checkedCities.indexOf(index) == -1) {
-                  this.$message.info('最多只能选择6个地图底图哦!');
-                }
-              }
-            "
             v-for="(city, index) in mapList"
             :label="index"
             :key="index"
@@ -51,6 +53,18 @@
         </el-checkbox-group>
       </div>
     </div>
+    <!-- 底部文本域 -->
+    <div id="textareaBox" v-if="subMitStatus">
+      <div class="textareaTitle">描述记录</div>
+      <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 4 }" placeholder="请输入内容" v-model="textarea1"> </el-input>
+    </div>
+    <!-- 打印区域 -->
+    <div id="imgBox">
+      <span>基本农田被侵占</span>
+      <img src="" id="imgOut" style="width: 1240px; background-repeat: no-repeat; background-size: 100% 100%" />
+      <span><div>描述记录</div></span>
+      <div>{{ textarea1 }}</div>
+    </div>
     <span slot="footer" class="dialog-footer">
       <el-button @click="clearDialogVisible()">{{ subMitStatus ? "返回上级" : "取 消" }}</el-button>
       <el-button type="primary" @click="subMitDialogVisible()">{{ subMitStatus ? "打 印" : "确 定" }}</el-button>
@@ -65,6 +79,7 @@
  * @Date: 2022年11月21-25日
  */
 import Map from "../../map/Map.vue";
+import html2canvas from "html2canvas";
 export default {
   name: "SameScreenComparison",
   components: { Map },
@@ -78,6 +93,8 @@ export default {
       mouseIndex: -1,
       // 确认状态
       subMitStatus: false,
+      // 底部文本域
+      textarea1: "",
       // 地图底图列表
       mapList: [
         {
@@ -235,14 +252,46 @@ export default {
     },
     // 同屏对比表单提交
     subMitDialogVisible() {
-      this.subMitStatus = !this.subMitStatus;
-      if (this.subMitStatus) {
-        this.$message.success("确定!");
+      if (!this.subMitStatus) {
+        this.subMitStatus = !this.subMitStatus;
       } else {
-        this.$message.success("打印!");
-        // this.clearDialogVisible();
+        // 出现新的弹窗并截图当前地图,以及文本域
+        this.cutDiv();
       }
     },
+    // div转图片
+    cutDiv() {
+      var container = document.getElementById("doPrint").innerHTML;
+      const _width = container.offsetWidth;
+      const _height = container.offsetHeight;
+      const ops = {
+        _width,
+        _height,
+        useCORS: true,
+        allowTaint: false
+      };
+      let that = this;
+      html2canvas(this.$refs.doPrint, ops).then(canvas => {
+        document.getElementById("imgOut").setAttribute("src", canvas.toDataURL("image/png"));
+      });
+      setTimeout(() =>{
+        that.doPrint();
+      },300);
+    },
+    // div打印(iframe的方式为最优)
+    doPrint() {
+      // 将包含转为图片的div获取。
+      var new_iframe = document.createElement("IFRAME");
+      var doc = null;
+      document.body.appendChild(new_iframe);
+      doc = new_iframe.contentWindow.document;
+      var obj = document.getElementById("imgBox");
+      doc.write('<div style="width:100%;height:auto;margin:0px;">' + obj.innerHTML + "</div>");
+      doc.close();
+      new_iframe.contentWindow.focus();
+      new_iframe.contentWindow.print();
+      // document.body.removeChild(iframe);
+    },
     // 修改
     handleCheckedCitiesChange(e) {
       // console.log("已选中的底图:", this.checkedCities, this.checkedCities.length);
@@ -268,6 +317,13 @@ export default {
   display: flex;
   width: 100%;
   height: calc(100vh - 190px);
+  position: relative;
+  #textareaBox {
+    width: calc(100% - 20px);
+    height: 100px;
+    position: absolute;
+    bottom: 0;
+  }
   &_mapList {
     width: 100%;
     height: 100%;
@@ -303,15 +359,32 @@ export default {
     }
   }
   &_aimapList {
-    width: 40%;
+    position: absolute;
+    z-index: 999;
+    right: 0;
+    width: 20rem;
     height: 100%;
+    font-size: 20px;
+    color: #fff;
+    padding: 10px;
     box-sizing: border-box;
-    overflow-x: hidden;
-    overflow-y: auto;
-    scrollbar-width: none; /* Firefox */
-    -ms-overflow-style: none; /* IE 10+ */
-    &::-webkit-scrollbar {
-      display: none; /* Chrome Safari */
+    border: 1px solid #ccc;
+    background: #002645 !important;
+    .checkLength {
+      font-size: 24px;
+      color: #74ffff;
+    }
+    #mapCheckBox {
+      height: calc(100% - 4rem);
+      width: 100%;
+      overflow-x: hidden;
+      overflow-y: auto;
+      scrollbar-width: none; /* Firefox */
+      -ms-overflow-style: none; /* IE 10+ */
+      border: 1px solid #fff;
+      &::-webkit-scrollbar {
+        display: none; /* Chrome Safari */
+      }
     }
     .mapCheckBox:hover {
       color: #ffffff;
@@ -334,4 +407,20 @@ export default {
     }
   }
 }
+.textareaTitle {
+  font-size: 20px;
+  font-weight: 400;
+}
+#imgBox {
+  display: none;
+  font-size: 16px;
+  color: #000;
+  font-weight: 400;
+  span {
+    font-size: 20px;
+    color: #000000;
+    font-weight: bold;
+    padding: 20px 10px;
+  }
+}
 </style>