xiao преди 1 месец
родител
ревизия
41af195c02
променени са 5 файла, в които са добавени 75 реда и са изтрити 59 реда
  1. 5 0
      package-lock.json
  2. 2 1
      package.json
  3. 57 57
      src/utils/print.js
  4. 8 0
      src/views/anscard/Index.vue
  5. 3 1
      vue.config.js

+ 5 - 0
package-lock.json

@@ -21083,6 +21083,11 @@
         }
       }
     },
+    "print-js": {
+      "version": "1.6.0",
+      "resolved": "https://registry.npmmirror.com/print-js/-/print-js-1.6.0.tgz",
+      "integrity": "sha512-BfnOIzSKbqGRtO4o0rnj/K3681BSd2QUrsIZy/+WdCIugjIswjmx3lDEZpXB2ruGf9d4b3YNINri81+J0FsBWg=="
+    },
     "printj": {
       "version": "1.1.2",
       "resolved": "https://registry.npmmirror.com/printj/-/printj-1.1.2.tgz",

+ 2 - 1
package.json

@@ -3,7 +3,7 @@
   "version": "0.1.0",
   "private": true,
   "scripts": {
-    "serve": "vue-cli-service serve --open",
+    "serve": "vue-cli-service serve --open --no-lint",
     "build": "vue-cli-service build",
     "lint": "vue-cli-service lint"
   },
@@ -22,6 +22,7 @@
     "js-base64": "^2.5.2",
     "jspdf": "^2.5.1",
     "moment": "^2.29.1",
+    "print-js": "^1.6.0",
     "qrcode.vue": "^1.7.0",
     "qs": "^6.9.4",
     "url-search-params-polyfill": "^8.0.0",

+ 57 - 57
src/utils/print.js

@@ -1,19 +1,19 @@
 export default function printHtml(html) {
-    let style = getStyle();
-    let container = getContainer(html);
-  
-    document.body.appendChild(style);
-    document.body.appendChild(container);
-  
-    getLoadPromise(container).then(() => {
-      window.print();
-      document.body.removeChild(style);
-      document.body.removeChild(container);
-    });
-  }
-  
-  // 设置打印样式
-  function getStyle() {
+  let style = getStyle();
+  let container = getContainer(html);
+
+  document.body.appendChild(style);
+  document.body.appendChild(container);
+
+  getLoadPromise(container).then(() => {
+    window.print();
+    document.body.removeChild(style);
+    document.body.removeChild(container);
+  });
+}
+
+// 设置打印样式
+function getStyle() {
   let styleContent = `#print-container {
       display: none;
   }
@@ -29,48 +29,48 @@ export default function printHtml(html) {
           display: block;
       }
   }`;
-    let style = document.createElement("style");
-    style.innerHTML = styleContent;
-    return style;
-  }
-  
-  // 清空打印内容
-  function cleanPrint() {
-    let div = document.getElementById('print-container')
-    if (!!div) {
-      document.querySelector('body').removeChild(div)
-    }
+  let style = document.createElement("style");
+  style.innerHTML = styleContent;
+  return style;
+}
+
+// 清空打印内容
+function cleanPrint() {
+  let div = document.getElementById('print-container')
+  if (!!div) {
+    document.querySelector('body').removeChild(div)
   }
-  
-  // 新建DOM,将需要打印的内容填充到DOM
-  function getContainer(html) {
-    cleanPrint()
-    let container = document.createElement("div");
-    container.setAttribute("id", "print-container");
-    container.innerHTML = html;
-    return container;
+}
+
+// 新建DOM,将需要打印的内容填充到DOM
+function getContainer(html) {
+  cleanPrint()
+  let container = document.createElement("div");
+  container.setAttribute("id", "print-container");
+  container.innerHTML = html;
+  return container;
+}
+
+// 图片完全加载后再调用打印方法
+function getLoadPromise(dom) {
+  let imgs = dom.querySelectorAll("img");
+  imgs = [].slice.call(imgs);
+
+  if (imgs.length === 0) {
+    return Promise.resolve();
   }
-  
-  // 图片完全加载后再调用打印方法
-  function getLoadPromise(dom) {
-    let imgs = dom.querySelectorAll("img");
-    imgs = [].slice.call(imgs);
-  
-    if (imgs.length === 0) {
-      return Promise.resolve();
-    }
-  
-    let finishedCount = 0;
-    return new Promise(resolve => {
-      function check() {
-        finishedCount++;
-        if (finishedCount === imgs.length) {
-          resolve();
-        }
+
+  let finishedCount = 0;
+  return new Promise(resolve => {
+    function check() {
+      finishedCount++;
+      if (finishedCount === imgs.length) {
+        resolve();
       }
-      imgs.forEach(img => {
-        img.addEventListener("load", check);
-        img.addEventListener("error", check);
-      })
-    });
-  }
+    }
+    imgs.forEach(img => {
+      img.addEventListener("load", check);
+      img.addEventListener("error", check);
+    })
+  });
+}

+ 8 - 0
src/views/anscard/Index.vue

@@ -614,6 +614,8 @@ import Page from "../../components/Page";
 import Editor from "../../components/fuEditor/index1";
 import { downloadPDF } from "@/utils/htmlToPdf.js"
 import printHtml from "@/utils/print.js"
+import printJS from "print-js";
+import print from "print-js"
 export default {
   components: {
     Page,Editor
@@ -1297,6 +1299,12 @@ export default {
 			// downloadPDF(this.$refs.contenterPdf)
 			console.log(this.$refs.contenterPdf)
 			printHtml(document.getElementById("contenterPdf").innerHTML)
+			// printJS({
+			// 	printable:"contenterPdf",
+			// 	type:"html",
+			// 	style:workOrderStyle(),
+			// 	targetStyles:["*"]
+			// })
 			this.loading = false
 		}
   },

+ 3 - 1
vue.config.js

@@ -8,5 +8,7 @@ module.exports = {
             }
         }
     },
-    publicPath: '/'
+    publicPath: '/',
+    lintOnSave: false
+    
 }