From 3d1dc105d597445796920327fb67653bc42b8473 Mon Sep 17 00:00:00 2001
From: 819527061@qq.com <123456>
Date: 星期四, 28 十二月 2023 16:05:32 +0800
Subject: [PATCH] 罚单管理 下载 签名照不显示问题
---
src/libs/word.js | 256 ++++++++++++++++++++++++++------------------------
src/components/page/ticket/ticket-form2.vue | 7
2 files changed, 138 insertions(+), 125 deletions(-)
diff --git a/src/components/page/ticket/ticket-form2.vue b/src/components/page/ticket/ticket-form2.vue
index 97219fe..192c7ce 100644
--- a/src/components/page/ticket/ticket-form2.vue
+++ b/src/components/page/ticket/ticket-form2.vue
@@ -45,7 +45,7 @@
<script>
import WordView from './word-view/index'
- import {exportDoc} from '../../../libs/word'
+ import {exportDocWidthImg} from '../../../libs/word'
export default {
components: {
@@ -111,8 +111,9 @@
})
},
downloadWord(data) { //word涓嬭浇
-
- exportDoc(data,'/words/administratorReturn.docx','閫佽揪鍥炶瘉琛屾斂澶勭綒鍐冲畾涔�')
+ setTimeout(() => {
+ exportDocWidthImg(data,'/words/administratorReturn.docx','閫佽揪鍥炶瘉琛屾斂澶勭綒鍐冲畾涔�')
+ },1000)
},
}
}
diff --git a/src/libs/word.js b/src/libs/word.js
index 9b52e2a..2eb00c2 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 [300,300]
+ }
+ }
+ 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