- Cataloghi: parte finale... prima bozza 9 dic

This commit is contained in:
Surya Paolo
2024-12-09 12:32:19 +01:00
parent 5c20e75b6a
commit 29c59588c7
33 changed files with 1009 additions and 397 deletions

View File

@@ -1,8 +1,9 @@
import {
defineComponent, onMounted, PropType, computed, ref, toRef, watch,
nextTick,
} from 'vue'
import { IColGridTable, IElemText, IElementiScheda, IImgGallery, ILabelValue, IMyCard, IMyElem, IMyPage, IMyScheda, IOperators, ISchedaSingola } from '@src/model'
import { ICatalogo, IColGridTable, IElemText, IElementiScheda, IImgGallery, ILabelValue, IMyCard, IMyElem, IMyPage, IMyScheda, IOperators, ISchedaSingola } from '@src/model'
import { useGlobalStore } from '@store/globalStore'
import { CImgTitle } from '@/components/CImgTitle'
@@ -37,6 +38,9 @@ import { costanti } from '@costanti'
import objectId from '@src/js/objectId'
import { useProducts } from '@src/store/Products'
import html2pdf from 'html2pdf.js'
export default defineComponent({
name: 'CMyEditElem',
components: {
@@ -287,10 +291,10 @@ export default defineComponent({
recscheda.scheda.etichette!.bestseller = {
show: false,
primiNInClassifica: 0,
}
}
if ((!recscheda.scheda?.barcode || !recscheda.scheda?.barcode.font)) {
recscheda.scheda.barcode = {
show: false,
@@ -888,10 +892,135 @@ export default defineComponent({
}
}
function toggleDebug() {
myel.value.catalogo!.indebug = !myel.value.catalogo!.indebug
}
const preparePDF = async () => {
myel.value.catalogo!.generazionePDFInCorso = true
myel.value.catalogo!.areadistampa!.scale = myel.value.catalogo!.areadistampa!.scale_printable
}
const terminaPDF = async () => {
myel.value.catalogo!.generazionePDFInCorso = false
myel.value.catalogo!.areadistampa!.scale = 1
}
const generatePDF = async (optcatalogo: ICatalogo) => {
await nextTick()
$q.dialog({
message: 'Generare il PDF ?',
ok: {
label: t('dialog.yes'),
push: true
},
cancel: {
label: t('dialog.cancel')
},
title: 'Generazione PDF'
}).onOk(async () => {
$q.loading.show({
message: 'Caricamento immagini e generazione PDF in corso...'
})
try {
let defaultMargin = 0.1
if (optcatalogo.printable) {
defaultMargin = 0
} else {
defaultMargin = 0
}
const unit = optcatalogo.areadistampa!.unit
let myformat = { ...optcatalogo.areadistampa!.format }
let scale = tools.getScale(optcatalogo)
let scalecanvas = optcatalogo.areadistampa!.scalecanvas
if (tools.isObject(myformat) && scale > 0) {
} else {
myformat = [210, 297]
}
const formatwidth = (myformat[0] * scale)
const formatheight = (myformat[1] * scale)
let myfile = (optcatalogo.pdf_filename ?? 'catalogo_completo')
myfile += '_' + formatwidth + '_' + formatheight + '_' + unit + '_scale_' + scale
myfile += '.pdf'
const element = document.getElementById('pdf-content')
const opt = {
margin: [
optcatalogo.printable ? (parseFloat(optcatalogo.areadistampa!.margini?.top) || defaultMargin) : defaultMargin,
optcatalogo.printable ? (parseFloat(optcatalogo.areadistampa!.margini?.left) || defaultMargin) : defaultMargin,
optcatalogo.printable ? (parseFloat(optcatalogo.areadistampa!.margini?.bottom) || defaultMargin) : defaultMargin,
optcatalogo.printable ? (parseFloat(optcatalogo.areadistampa!.margini?.right) || defaultMargin) : defaultMargin
],
filename: myfile,
image: {
type: 'jpeg',
quality: 0.98
},
html2canvas: {
scale: scalecanvas,
useCORS: true,
letterRendering: true,
},
jsPDF: {
unit: unit,
format: [formatwidth, formatheight],
orientation: optcatalogo.areadistampa!.orientation,
compress: optcatalogo.areadistampa!.compress,
},
enableLinks: true,
pagebreak: { mode: 'avoid-all', before: '.card-page' }
}
console.log('opt di stampa', opt)
// a4: [595.28, 841.89]
await html2pdf().set(opt).from(element).save()
optcatalogo.generazionePDFInCorso = false
optcatalogo.areadistampa!.scale = 1
$q.loading.hide()
$q.notify({
color: 'positive',
message: 'PDF generato con successo!',
icon: 'check'
})
} catch (error) {
$q.loading.hide()
$q.notify({
color: 'negative',
message: 'Errore nella generazione del PDF',
icon: 'error'
})
console.error('Errore nella generazione del PDF:', error)
}
})
}
onMounted(mounted)
return {
preparePDF, terminaPDF, generatePDF,
toggleDebug,
tools,
shared_consts,
getArrDisciplines,