From 85faf11d278a53d78d25e4ce62527800d9a93ed4 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Mon, 12 May 2025 18:43:25 +0200 Subject: [PATCH] - Creazione PDF Temporanei (Generati) - Assegnazione di questi su PDF OnLine e PDF per Stampa --- .../CMyRecCatalog/CMyRecCatalog.vue | 42 +-- src/store/globalStore.ts | 9 + src/views/ecommerce/catalogo/catalogo.ts | 262 +++++++++++------- src/views/ecommerce/catalogo/catalogo.vue | 103 +++++-- 4 files changed, 279 insertions(+), 137 deletions(-) diff --git a/src/components/CMyRecCatalog/CMyRecCatalog.vue b/src/components/CMyRecCatalog/CMyRecCatalog.vue index 7fdedfe8..b01496e8 100755 --- a/src/components/CMyRecCatalog/CMyRecCatalog.vue +++ b/src/components/CMyRecCatalog/CMyRecCatalog.vue @@ -102,16 +102,28 @@ }}
- - +   PDF GeneratoPDF OnLine - (Data: {{ tools.getstrDate(myrec.data_generato) }}) + aggiornato al ({{ tools.getstrDate(myrec.data_online) }}) +
+
+   + PDF per Stampa + aggiornato al ({{ tools.getstrDate(myrec.data_online_stampa) }})
-
- - - PDF ONLINE - (Data: {{ tools.getstrDate(myrec.data_online) }}) -
- - + diff --git a/src/store/globalStore.ts b/src/store/globalStore.ts index 8fc19196..d5b09afc 100644 --- a/src/store/globalStore.ts +++ b/src/store/globalStore.ts @@ -2528,6 +2528,15 @@ export const useGlobalStore = defineStore('GlobalStore', { return false; }); }, + async execOnlinePDF(paramquery: any) { + return Api.SendReq('/admin/online-pdf', 'POST', paramquery) + .then((res) => { + return res.data; + }) + .catch((error) => { + return false; + }); + }, async convertPdf( pdfFile: any, diff --git a/src/views/ecommerce/catalogo/catalogo.ts b/src/views/ecommerce/catalogo/catalogo.ts index 540b9af0..cffa1dc3 100755 --- a/src/views/ecommerce/catalogo/catalogo.ts +++ b/src/views/ecommerce/catalogo/catalogo.ts @@ -1727,12 +1727,32 @@ export default defineComponent({ optcatalogo.value.indebug = !optcatalogo.value.indebug; } - const preparePDF = async () => { - optcatalogo.value.generazionePDFInCorso = true; - optcatalogo.value.areadistampa!.scale = optcatalogo.value.areadistampa!.scale_printable; + const preparePDF = () => { + $q.dialog({ + message: 'Generare il PDF ?', + ok: { + label: t('dialog.yes'), + push: true, + }, + cancel: { + label: t('dialog.cancel'), + }, + title: 'Generazione PDF', + }).onOk(async () => { + optcatalogo.value.generazionePDFInCorso = true; + optcatalogo.value.areadistampa!.scale = optcatalogo.value.areadistampa!.scale_printable; + + setTimeout(() => { + optcatalogo.value.generazionePDFInCorso = true; + + setTimeout(() => { + generatePDF(); + }, 500); + }, 500); + }); }; - const terminaPDF = async () => { + const terminaPDF = () => { optcatalogo.value.generazionePDFInCorso = false; optcatalogo.value.areadistampa!.scale = 1; }; @@ -1831,103 +1851,143 @@ export default defineComponent({ const generatePDF = async () => { 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.value.printable) { - defaultMargin = 0; - } else { - defaultMargin = 0; - } - const unit = optcatalogo.value.areadistampa!.unit; - - let myformat = { ...optcatalogo.value.areadistampa!.format }; - - const scale = tools.getScale(optcatalogo.value); - - const scalecanvas = optcatalogo.value.areadistampa!.scalecanvas; - - if (tools.isObject(myformat) && scale > 0) { - } else { - myformat = [210, 297]; - } - - const formatwidth = myformat[0] * scale; - const formatheight = myformat[1] * scale; - - let myfile = getPdfFilename(); - - // myfile += '_' + tools.getDateYYYYMMDD_Today(); - - myfile += '.pdf'; - - let file_out = myfile; - - const element = document.getElementById('pdf-content'); - const opt = { - margin: [defaultMargin, defaultMargin, 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.value.areadistampa!.orientation, - compress: optcatalogo.value.areadistampa!.compress, - }, - enableLinks: true, - pagebreak: { mode: 'avoid-all', before: '.card-page' }, - }; - - console.log('opt di stampa', opt); - // a4: [595.28, 841.89] - - if (true) { - await generateLargePDF(opt, '.pdf-section', false, 'upload/cataloghi/', file_out); - } else { - await html2pdf().set(opt).from(element).save(); - } - - optcatalogo.value.generazionePDFInCorso = false; - optcatalogo.value.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); - } + $q.loading.show({ + message: 'Caricamento immagini e generazione PDF in corso...', }); + + try { + let defaultMargin = 0.1; + if (optcatalogo.value.printable) { + defaultMargin = 0; + } else { + defaultMargin = 0; + } + const unit = optcatalogo.value.areadistampa!.unit; + + let myformat = { ...optcatalogo.value.areadistampa!.format }; + + const scale = tools.getScale(optcatalogo.value); + + const scalecanvas = optcatalogo.value.areadistampa!.scalecanvas; + + if (tools.isObject(myformat) && scale > 0) { + } else { + myformat = [210, 297]; + } + + const formatwidth = myformat[0] * scale; + const formatheight = myformat[1] * scale; + + let myfile = getPdfFilename(); + + // myfile += '_' + tools.getDateYYYYMMDD_Today(); + + myfile += '.pdf'; + + let file_out = myfile; + + const element = document.getElementById('pdf-content'); + const opt = { + margin: [defaultMargin, defaultMargin, 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.value.areadistampa!.orientation, + compress: optcatalogo.value.areadistampa!.compress, + }, + enableLinks: true, + pagebreak: { mode: 'avoid-all', before: '.card-page' }, + }; + + console.log('opt di stampa', opt); + // a4: [595.28, 841.89] + + if (true) { + await generateLargePDF(opt, '.pdf-section', false, 'upload/cataloghi/', file_out); + } else { + await html2pdf().set(opt).from(element).save(); + } + + optcatalogo.value.generazionePDFInCorso = false; + optcatalogo.value.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); + } + }; + + const pubblicaPDF = async () => { + const catalog = getCatalogoByMyPage.value; + + const ris = await globalStore.execOnlinePDF({ id_catalog: catalog._id, stampa: false }); + + if (ris) { + if (ris.catalog?.pdf_online) { + catalog.pdf_online = ris.catalog.pdf_online; + catalog.data_online = ris.catalog.data_online; + } + $q.notify({ + color: 'positive', + message: 'PDF inviato ONLINE!', + icon: 'check', + }); + } else { + $q.loading.hide(); + $q.notify({ + color: 'negative', + message: "Errore nell'invio del PDF OnLine", + icon: 'error', + }); + } + }; + + const pubblicaPDFStampa = async () => { + const catalog = getCatalogoByMyPage.value; + + const ris = await globalStore.execOnlinePDF({ id_catalog: catalog._id, stampa: true }); + + if (ris) { + if (ris.catalog.pdf_online_stampa) { + catalog.pdf_online_stampa = ris.catalog.pdf_online_stampa; + catalog.data_online_stampa = ris.catalog.data_online_stampa; + } + $q.notify({ + color: 'positive', + message: 'PDF STAMPA inviato ONLINE!', + icon: 'check', + }); + } else { + $q.loading.hide(); + $q.notify({ + color: 'negative', + message: "Errore nell'invio del PDF STAMPA OnLine", + icon: 'error', + }); + } + + // await saveCatalog(); }; onMounted(mounted); @@ -2007,6 +2067,8 @@ export default defineComponent({ getPdfFilename, filtroStrApplicato, getCollane, + pubblicaPDF, + pubblicaPDFStampa, }; }, }); diff --git a/src/views/ecommerce/catalogo/catalogo.vue b/src/views/ecommerce/catalogo/catalogo.vue index af9ea271..b5b15a9a 100755 --- a/src/views/ecommerce/catalogo/catalogo.vue +++ b/src/views/ecommerce/catalogo/catalogo.vue @@ -407,11 +407,13 @@ -
- +
-
-
- PDF: - - {{tools.getHost() + getCatalogoByMyPage.pdf_generato}} - - - -
(Generato il {{ tools.getstrDateTime(getCatalogoByMyPage.data_generato)}}) +
+
+ PDF generati Temporanei
-
-
- PDF Stampa: - - {{tools.getHost() + getCatalogoByMyPage.pdf_generato_stampa}} +
+ PDF Generato: + + {{ tools.getHost() + getCatalogoByMyPage.pdf_generato }} - -
(Generato il {{ tools.getstrDateTime(getCatalogoByMyPage.data_generato_stampa) }}) +
(del {{ tools.getstrDateTime(getCatalogoByMyPage.data_generato) }}) +
+ +
+
+
+ PDF Generato Stampa: + + {{ tools.getHost() + getCatalogoByMyPage.pdf_generato_stampa }} + + - +
(del {{ tools.getstrDateTime(getCatalogoByMyPage.data_generato_stampa) }}) +
+ +
+
+
+ PDF Pubblicati OnLine +
+
+ PDF OnLine: + + {{ tools.getHost() + getCatalogoByMyPage.pdf_online }} + + - +
(del {{ tools.getstrDateTime(getCatalogoByMyPage.data_online) }}) +
+
+
+ PDF OnLine Stampa: + + {{ tools.getHost() + getCatalogoByMyPage.pdf_online_stampa }} + + - +
(del {{ tools.getstrDateTime(getCatalogoByMyPage.data_online_stampa) }}) +