This commit is contained in:
linfso 2025-01-05 07:56:38 +08:00
parent 600f3c24b2
commit 5e6db49aa4
4 changed files with 99 additions and 29 deletions

View File

@ -15,7 +15,7 @@ VUE_APP_BASE_API = 'http://47.96.189.20:58089/api/bizsvr'
VUE_APP_WS_HOST = 'ws://47.96.189.20:58089/api/bizsvr' VUE_APP_WS_HOST = 'ws://47.96.189.20:58089/api/bizsvr'
VUE_APP_PRINTER_HOST = '192.168.88.189:17080' VUE_APP_PRINTER_HOST = '192.168.88.108:17080'
# 路由懒加载 # 路由懒加载

View File

@ -69,7 +69,8 @@
import printJS from 'print-js' import printJS from 'print-js'
// npm i pdfjs-dist@2.5.207 // npm i pdfjs-dist@2.5.207
// npm i vue-pdf@4.2.0 // npm i vue-pdf@4.2.0
import pdf from 'xd-vue-pdf' // import pdf from 'xd-vue-pdf'
import pdf from "./xdpdf/vuePdfNoSss.vue"
import PdfUtils from '@/utils/pdfUtils.js'; import PdfUtils from '@/utils/pdfUtils.js';
export default { export default {
components: { pdf }, components: { pdf },
@ -83,8 +84,8 @@ export default {
}, },
isLoadComplete:{ isLoadComplete:{
type: Boolean, type: Number,
default: false default: 0
} }
}, },
data() { data() {
@ -117,22 +118,47 @@ export default {
} }
}, },
computed: { computed: {
// currentPdfUrl() {
// if (!this.loadPdfUrl) return ''
// const publicPath ='/static/'
// return pdf.createLoadingTask({
// url: this.loadPdfUrl,
// cMapUrl: `${publicPath}cmaps/`,
// cMapPacked: true
// })
// }
currentPdfUrl() { currentPdfUrl() {
if (!this.loadPdfUrl) return '' if (!this.loadPdfUrl) return ''
console.log("====>currentPdfUrl==>",this.loadPdfUrl)
const publicPath ='/static/' const publicPath ='/static/'
// return pdf.createLoadingTask({
// url: this.loadPdfUrl,
// cMapUrl: `${publicPath}cmaps/`,
// cMapPacked: true
// })
return pdf.createLoadingTask({ return pdf.createLoadingTask({
url: this.loadPdfUrl, url: this.loadPdfUrl
cMapUrl: `${publicPath}cmaps/`,
cMapPacked: true
}) })
} }
}, },
watch: { watch: {
pdfList(){ // pdfList(){
this.cacheFileList=this.pdfList; // this.cacheFileList=this.pdfList;
this.initA4List(); // this.initA4List();
this.showFirstFile(); // this.showFirstFile();
}, // },
"pdfList": {
handler (newValue, oldValue) {
console.log("===>watch pdfList==>",this.pdfList);
// 按照给定的数据排序
this.cacheFileList=this.pdfList;
this.initA4List();
this.showFirstFile();
},
deep: true
},
thisPageCount(value) { thisPageCount(value) {
if(this.isA4){ if(this.isA4){
this.doScale(50); this.doScale(50);
@ -189,7 +215,12 @@ export default {
this.scale=50; this.scale=50;
this.preScale=50; this.preScale=50;
this.pageCount=this.cacheA4FileList.length; this.pageCount=this.cacheA4FileList.length;
setTimeout( this.showA4Page(this.cacheA4FileList.length),3000); // setTimeout( this.showA4Page(this.cacheA4FileList.length),3000);
setTimeout(
async () => {
this.showA4Page(1);
}
,3000);
}else{ }else{
this.scale=20; this.scale=20;
this.preScale=20; this.preScale=20;
@ -290,21 +321,53 @@ export default {
downPDF() { downPDF() {
// 下载所有预览的PDF文件 // 下载所有预览的PDF文件
if(this.isA4){ if(this.isA4){
let that=this;
if(this.cacheA4FileList&&this.cacheA4FileList.length>0){ if(this.cacheA4FileList&&this.cacheA4FileList.length>0){
this.cacheA4FileList.forEach(async item=>{
if(!item.pdfUrl){ // this.cacheA4FileList.forEach(item=>{
let thisSubList=item.childreen; // if(!item.pdfUrl){
let needGenList=[]; // let thisSubList=item.childreen;
// let needGenList=[];
// for(let j=0;j<thisSubList.length;j++){
// needGenList.push(thisSubList[j].pdfBase64)
// }
// item.pdfUrl=await this.pdfUtils.mergePdfToA4(needGenList);
// this.downPdfFile(item.pdfUrl);
// }else{
// this.downPdfFile(item.pdfUrl);
// }
// });
this.$prompt('请输入保存文件名', "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
closeOnClickModal: false,
inputValidator (value) {
if (value) {
return true;
}else{
return false;
}
},
inputErrorMessage: "文件名不能为空"
}).then(async ({ value }) => {
let fileName=value+".pdf";
let needGenList=[];
for(let i=0;i<that.cacheA4FileList.length;i++){
let thisSubList=that.cacheA4FileList[i].childreen;
for(let j=0;j<thisSubList.length;j++){ for(let j=0;j<thisSubList.length;j++){
needGenList.push(thisSubList[j].pdfBase64) needGenList.push(thisSubList[j].pdfBase64)
} }
item.pdfUrl=await this.pdfUtils.mergePdfToA4(needGenList); }
this.downPdfFile(item.pdfUrl);
}else{ this.pdfUtils.mergePdfToA4(needGenList,fileName,true);
this.downPdfFile(item.pdfUrl); }).catch(() => {});
}
});
} }
}else{ }else{
if(this.cacheFileList&&this.cacheFileList.length>0){ if(this.cacheFileList&&this.cacheFileList.length>0){

View File

@ -381,16 +381,22 @@ export default class PdfUtils {
pdfBuffers.push(Buffer.from(dateArray)); pdfBuffers.push(Buffer.from(dateArray));
}); });
const pdfDoc = await PDFDocument.create(); const pdfDoc = await PDFDocument.create();
const pageA4 = pdfDoc.addPage(PageSizes.A4); let pageA4 = pdfDoc.addPage(PageSizes.A4);
const drawHeight = pageA4.getHeight()/2; // const drawHeight = pageA4.getHeight()/2;
const drawWidth = pageA4.getWidth()/2; // const drawWidth = pageA4.getWidth()/2;
let i=0; let i=0;
let x=0; let x=0;
let y=0; let y=0;
let width=0; let width=0;
let height=0; let height=0;
let spaceWidth=2; let spaceWidth=2;
for (let buffer of pdfBuffers) { for (let j=0;j<pdfBuffers.length;j++) {
let buffer=pdfBuffers[j];
if(j!=0 && j%4==0){
pageA4 = pdfDoc.addPage(PageSizes.A4);
i=0;
}
const [page] = await pdfDoc.embedPdf(buffer); const [page] = await pdfDoc.embedPdf(buffer);
const pageDims = page.scale(1.0); const pageDims = page.scale(1.0);
// ...pageDims, // ...pageDims,
@ -413,8 +419,6 @@ export default class PdfUtils {
width = pageDims.width; width = pageDims.width;
height = pageDims.height; height = pageDims.height;
if(i==0){ if(i==0){
x=spaceWidth; x=spaceWidth;
y=pageA4.getHeight()/2; y=pageA4.getHeight()/2;

View File

@ -814,6 +814,9 @@
// let pdfUrl=await this.pdfUtils.mergePdfToA4(needGenList); // let pdfUrl=await this.pdfUtils.mergePdfToA4(needGenList);
// mergeA4List.push(pdfUrl); // mergeA4List.push(pdfUrl);
// let fileName=new Date().getTime()+".pdf"; // let fileName=new Date().getTime()+".pdf";
console.log("==11111==>===> needGenList==>", needGenList);
let fileName=value+".pdf"; let fileName=value+".pdf";
this.pdfUtils.mergePdfToA4(needGenList,fileName,true); this.pdfUtils.mergePdfToA4(needGenList,fileName,true);