From 34aedd9998b5572488e49db884b2f7966d960a57 Mon Sep 17 00:00:00 2001
From: 819527061@qq.com <123456>
Date: 星期一, 18 十一月 2024 14:06:43 +0800
Subject: [PATCH] 订单统计页面

---
 src/libs/word.js |  256 ++++++++++++++++++++++++++------------------------
 1 files changed, 134 insertions(+), 122 deletions(-)

diff --git a/src/libs/word.js b/src/libs/word.js
index 9b52e2a..cde67d2 100644
--- a/src/libs/word.js
+++ b/src/libs/word.js
@@ -28,7 +28,13 @@
         // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹�
         let zip = new PizZip(content);
         // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄
-        let doc = new docxtemplater().loadZip(zip);
+        let doc = new docxtemplater().loadZip(zip).setOptions({
+            linebreaks:true,
+            paragraphLoop: true,
+            nullGetter:function () {
+                return ""
+            }
+        });
         // 璁剧疆妯℃澘鍙橀噺鐨勫��
         doc.setData(e);
 
@@ -58,145 +64,151 @@
 
 //涓嬭浇word锛屽甫鍥剧墖
 export const exportDocWidthImg = (e, path , dname, imgSize) => {
-  for (let attr in e) {
-    if (e[attr] == null) {
-      e[attr] = "";
+
+    for (let attr in e) {
+        if (e[attr] == null) {
+            e[attr] = "";
+        }
     }
-  }
-  let docxsrc = path;        //妯℃澘鏂囦欢鐨勪綅缃�
-  let docxname = dname;        //瀵煎嚭鏂囦欢鐨勫悕瀛�
-  // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹�
-  JSZipUtils.getBinaryContent(docxsrc, function (error, content) {
-    // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁
-    // 鎶涘嚭寮傚父
-    if (error) {
-      throw error;
-    }
+    let docxsrc = path;        //妯℃澘鏂囦欢鐨勪綅缃�
+    let docxname = dname;        //瀵煎嚭鏂囦欢鐨勫悕瀛�
+    // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹�
+    JSZipUtils.getBinaryContent(docxsrc, function (error, content) {
+        // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁
+        // 鎶涘嚭寮傚父
+        if (error) {
+            throw error;
+        }
 
-    // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹�
-    let zip = new PizZip(content);
-    // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄
-    let doc = new docxtemplater().loadZip(zip).setOptions({
-      linebreaks:true,
-      paragraphLoop: true,
-      nullGetter:function () {
-        return ""
-      }
-    });
+        // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹�
+        let zip = new PizZip(content);
+        // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄
+        let doc = new docxtemplater().loadZip(zip).setOptions({
+            linebreaks:true,
+            paragraphLoop: true,
+            nullGetter:function () {
+                return ""
+            }
+        });
 
-    // // 鍥剧墖澶勭悊
-    let opts = {}
-    opts = {
-      // 鍥惧儚鏄惁灞呬腑
-      centered: false
-    };
-    opts.fileType = "docx";
-    opts.getImage = (chartId) =>{
-      return base64DataURLToArrayBuffer(chartId);
-    }
+        // // 鍥剧墖澶勭悊
+        let opts = {}
+        opts = {
+            // 鍥惧儚鏄惁灞呬腑
+            centered: false
+        };
+        opts.fileType = "docx";
+        opts.getImage = (chartId) =>{
+            return base64DataURLToArrayBuffer(chartId);
+        }
 
-    opts.getSize = function(img, tagVlaue, tagName){  //鍥剧墖size
-      if(imgSize.hasOwnProperty(tagName)) {
-        return imgSize[tagName]
-      }else {
-        return [300,300]
-      }
-    }
-    let imageModule = new ImageModule(opts);
-    doc.attachModule(imageModule);
+        opts.getSize = function(img, tagVlaue, tagName){  //鍥剧墖size
+            if(imgSize.hasOwnProperty(tagName)) {
+                return imgSize[tagName]
+            }else {
+                return [70, 30]
+            }
+        }
+        let imageModule = new ImageModule(opts);
+        doc.attachModule(imageModule);
 
-    // 璁剧疆妯℃澘鍙橀噺鐨勫��
-    doc.setData(e);
-    console.log(doc,'涓嬭浇---甯﹀浘鐗囩殑---')
+        // 璁剧疆妯℃澘鍙橀噺鐨勫��
+        doc.setData(e);
 
-    try {
-      //鏇挎崲鎵�鏈夋ā鏉垮彉閲�
-      doc.render();
-    } catch (error) {
-      let e = {
-        message: error.message,
-        name: error.name,
-        stack: error.stack,
-        properties: error.properties
-      };
-      console.log(JSON.stringify({error: e}));
-      throw error;
-    }
+        try {
+            //鏇挎崲鎵�鏈夋ā鏉垮彉閲�
+            doc.render();
+        } catch (error) {
+            let e = {
+                message: error.message,
+                name: error.name,
+                stack: error.stack,
+                properties: error.properties
+            };
+            console.log(JSON.stringify({error: e}));
+            throw error;
+        }
 
-    // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級
-    let out = doc.getZip().generate({
-      type: "blob",
-      mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
-    });
-    // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚�
-    saveAs(out, docxname);
-  },2000);
+        // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級
+        let out = doc.getZip().generate({
+            type: "blob",
+            mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
+        });
+        // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚�
+        saveAs(out, docxname);
+    },2000);
 }
 
 //涓嬭浇word锛屽甫鍥剧墖
 export const exportDocWidthImg2 = (e, path , dname, arry, imgSize) => {
-  for (let attr in e) {
-    if (e[attr] == null) {
-      e[attr] = "";
+    for (let attr in e) {
+        if (e[attr] == null) {
+            e[attr] = "";
+        }
     }
-  }
-  let docxsrc = path;        //妯℃澘鏂囦欢鐨勪綅缃�
-  let docxname = dname;        //瀵煎嚭鏂囦欢鐨勫悕瀛�
-  // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹�
-  JSZipUtils.getBinaryContent(docxsrc, function (error, content) {
-    // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁
-    // 鎶涘嚭寮傚父
-    if (error) {
-      throw error;
-    }
+    let docxsrc = path;        //妯℃澘鏂囦欢鐨勪綅缃�
+    let docxname = dname;        //瀵煎嚭鏂囦欢鐨勫悕瀛�
+    // 璇诲彇骞惰幏寰楁ā鏉挎枃浠剁殑浜岃繘鍒跺唴瀹�
+    JSZipUtils.getBinaryContent(docxsrc, function (error, content) {
+        // docxsrc鏄ā鏉裤�傛垜浠湪瀵煎嚭鐨勬椂鍊欙紝浼氭牴鎹妯℃澘鏉ュ鍑哄搴旂殑鏁版嵁
+        // 鎶涘嚭寮傚父
+        if (error) {
+            throw error;
+        }
 
-    // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹�
-    let zip = new PizZip(content);
-    // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄
-    let doc = new docxtemplater().loadZip(zip);
+        // 鍒涘缓涓�涓狿izZip瀹炰緥锛屽唴瀹逛负妯℃澘鐨勫唴瀹�
+        let zip = new PizZip(content);
+        // 鍒涘缓骞跺姞杞絛ocx templater瀹炰緥瀵硅薄
+        let doc = new docxtemplater().loadZip(zip).setOptions({
+            linebreaks:true,
+            paragraphLoop: true,
+            nullGetter:function () {
+                return ""
+            }
+        });
 
-    // // 鍥剧墖澶勭悊
-    const opts = {}
-    opts.fileType = "docx";
-    opts.getImage = (chartId) =>{
-      return base64DataURLToArrayBuffer(chartId);
-    }
+        // // 鍥剧墖澶勭悊
+        const opts = {}
+        opts.fileType = "docx";
+        opts.getImage = (chartId) =>{
+            return base64DataURLToArrayBuffer(chartId);
+        }
 
-    opts.getSize = function(img, tagVlaue, tagName){  //鍥剧墖size
-      if(imgSize.hasOwnProperty(tagName)) {
-        return imgSize[tagName]
-      }else {
-        return [300,300]
-      }
-    }
-    let imageModule = new ImageModule(opts);
-    doc.attachModule(imageModule);
+        opts.getSize = function(img, tagVlaue, tagName){  //鍥剧墖size
+            if(imgSize.hasOwnProperty(tagName)) {
+                return imgSize[tagName]
+            }else {
+                return [300,300]
+            }
+        }
+        let imageModule = new ImageModule(opts);
+        doc.attachModule(imageModule);
 
-    // 璁剧疆妯℃澘鍙橀噺鐨勫��
-    doc.setData(e);
+        // 璁剧疆妯℃澘鍙橀噺鐨勫��
+        doc.setData(e);
 
-    try {
-      //鏇挎崲鎵�鏈夋ā鏉垮彉閲�
-      doc.render();
-    } catch (error) {
-      let e = {
-        message: error.message,
-        name: error.name,
-        stack: error.stack,
-        properties: error.properties
-      };
-      console.log(JSON.stringify({error: e}));
-      throw error;
-    }
+        try {
+            //鏇挎崲鎵�鏈夋ā鏉垮彉閲�
+            doc.render();
+        } catch (error) {
+            let e = {
+                message: error.message,
+                name: error.name,
+                stack: error.stack,
+                properties: error.properties
+            };
+            console.log(JSON.stringify({error: e}));
+            throw error;
+        }
 
-    // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級
-    let out = doc.getZip().generate({
-      type: "blob",
-      mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
-    });
-    // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚�
-    saveAs(out, docxname);
-  },2000);
+        // 鐢熸垚涓�涓唬琛╠ocxtemplater瀵硅薄鐨剒ip鏂囦欢锛堜笉鏄竴涓湡瀹炵殑鏂囦欢锛岃�屾槸鍦ㄥ唴瀛樹腑鐨勮〃绀猴級
+        let out = doc.getZip().generate({
+            type: "blob",
+            mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
+        });
+        // 灏嗙洰鏍囨枃浠跺璞′繚瀛樹负鐩爣绫诲瀷鐨勬枃浠讹紝骞跺懡鍚�
+        saveAs(out, docxname);
+    },2000);
 }
 
 //棰勮word锛屼笉甯﹀浘鐗囩殑

--
Gitblit v1.9.1