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_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'
// npm i pdfjs-dist@2.5.207
// 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';
export default {
components: { pdf },
@ -83,8 +84,8 @@ export default {
},
isLoadComplete:{
type: Boolean,
default: false
type: Number,
default: 0
}
},
data() {
@ -117,22 +118,47 @@ export default {
}
},
computed: {
// currentPdfUrl() {
// if (!this.loadPdfUrl) return ''
// const publicPath ='/static/'
// return pdf.createLoadingTask({
// url: this.loadPdfUrl,
// cMapUrl: `${publicPath}cmaps/`,
// cMapPacked: true
// })
// }
currentPdfUrl() {
if (!this.loadPdfUrl) return ''
console.log("====>currentPdfUrl==>",this.loadPdfUrl)
const publicPath ='/static/'
// return pdf.createLoadingTask({
// url: this.loadPdfUrl,
// cMapUrl: `${publicPath}cmaps/`,
// cMapPacked: true
// })
return pdf.createLoadingTask({
url: this.loadPdfUrl,
cMapUrl: `${publicPath}cmaps/`,
cMapPacked: true
url: this.loadPdfUrl
})
}
},
watch: {
pdfList(){
this.cacheFileList=this.pdfList;
this.initA4List();
this.showFirstFile();
},
// pdfList(){
// this.cacheFileList=this.pdfList;
// this.initA4List();
// this.showFirstFile();
// },
"pdfList": {
handler (newValue, oldValue) {
console.log("===>watch pdfList==>",this.pdfList);
// 按照给定的数据排序
this.cacheFileList=this.pdfList;
this.initA4List();
this.showFirstFile();
},
deep: true
},
thisPageCount(value) {
if(this.isA4){
this.doScale(50);
@ -189,7 +215,12 @@ export default {
this.scale=50;
this.preScale=50;
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{
this.scale=20;
this.preScale=20;
@ -290,21 +321,53 @@ export default {
downPDF() {
// 下载所有预览的PDF文件
if(this.isA4){
let that=this;
if(this.cacheA4FileList&&this.cacheA4FileList.length>0){
this.cacheA4FileList.forEach(async item=>{
if(!item.pdfUrl){
let thisSubList=item.childreen;
let needGenList=[];
// this.cacheA4FileList.forEach(item=>{
// if(!item.pdfUrl){
// 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++){
needGenList.push(thisSubList[j].pdfBase64)
}
item.pdfUrl=await this.pdfUtils.mergePdfToA4(needGenList);
this.downPdfFile(item.pdfUrl);
}else{
this.downPdfFile(item.pdfUrl);
}
}
this.pdfUtils.mergePdfToA4(needGenList,fileName,true);
}).catch(() => {});
});
}
}else{
if(this.cacheFileList&&this.cacheFileList.length>0){

View File

@ -381,16 +381,22 @@ export default class PdfUtils {
pdfBuffers.push(Buffer.from(dateArray));
});
const pdfDoc = await PDFDocument.create();
const pageA4 = pdfDoc.addPage(PageSizes.A4);
const drawHeight = pageA4.getHeight()/2;
const drawWidth = pageA4.getWidth()/2;
let pageA4 = pdfDoc.addPage(PageSizes.A4);
// const drawHeight = pageA4.getHeight()/2;
// const drawWidth = pageA4.getWidth()/2;
let i=0;
let x=0;
let y=0;
let width=0;
let height=0;
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 pageDims = page.scale(1.0);
// ...pageDims,
@ -413,8 +419,6 @@ export default class PdfUtils {
width = pageDims.width;
height = pageDims.height;
if(i==0){
x=spaceWidth;
y=pageA4.getHeight()/2;

View File

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