- estrazione dei dati del libro sul sito di Amazon.

- possibilità di visualizzare i dati estratti e di aggiornare i dati, sia solo se vuoti, che sovrascrivere tutti i dati.
This commit is contained in:
Surya Paolo
2025-05-16 18:52:12 +02:00
parent 810815a12a
commit 859ba022fa
18 changed files with 1840 additions and 798 deletions

View File

@@ -1,30 +1,32 @@
import { PropType, computed, defineComponent, onMounted, ref, watch } from "vue";
import draggable from 'vuedraggable'
import {
PropType,
computed,
defineComponent,
onMounted,
ref,
watch,
} from 'vue';
import draggable from 'vuedraggable';
import { tools } from '@tools'
import { tools } from '@tools';
import { useGlobalStore } from '@src/store/globalStore'
import { useGlobalStore } from '@src/store/globalStore';
import { CTableCupleLabelValue } from '@src/components/CTableCupleLabelValue'
import { CTableCupleLabelValue } from '@src/components/CTableCupleLabelValue';
import { costanti } from '@costanti'
import type {
IMyScheda,
IProduct,
IRecFields
} from '@src/model';
import { shared_consts } from "app/src/common/shared_vuejs";
import { useProducts } from "app/src/store/Products";
import { useI18n } from "vue-i18n";
import { useQuasar } from "quasar";
import { costanti } from '@costanti';
import type { IMyScheda, IProduct, IRecFields } from '@src/model';
import { shared_consts } from 'app/src/common/shared_vuejs';
import { useProducts } from 'app/src/store/Products';
import { useI18n } from 'vue-i18n';
import { useQuasar } from 'quasar';
export default defineComponent({
name: "CSchedaProdotto",
name: 'CSchedaProdotto',
emits: ['updateproductmodif'],
components: {
CTableCupleLabelValue
CTableCupleLabelValue,
},
props: {
modelValue: {
@@ -34,36 +36,35 @@ export default defineComponent({
scheda: {
type: Object as PropType<IMyScheda>,
required: false,
default: () => ({
}),
default: () => ({}),
},
},
setup(props, { emit }) {
// Copia locale della lista_prodotti per manipolazione interna
const $q = useQuasar()
const { t } = useI18n()
const $q = useQuasar();
const { t } = useI18n();
const globalStore = useGlobalStore()
const products = useProducts()
const globalStore = useGlobalStore();
const products = useProducts();
const mytab = ref('scheda')
const mytab = ref('scheda');
const loading = ref(false)
const loading = ref(false);
const updatetogm = ref(false)
const field_updated_toGM = ref('')
const updatetogm = ref(false);
const field_updated_toGM = ref('');
const myproduct = ref<IProduct>({ ...props.modelValue })
const myproduct = ref<IProduct>({ ...props.modelValue });
watch(() => props.modelValue, (newVal) => {
myproduct.value = { ...newVal };
}, { deep: false });
watch(
() => props.modelValue,
(newVal) => {
myproduct.value = { ...newVal };
},
{ deep: false }
);
async function mounted() {
}
async function mounted() {}
/*
// Aggiorna la copia locale quando il prop cambia
@@ -79,101 +80,102 @@ export default defineComponent({
const arrlist: IRecFields[] = [
{
editOn: false,
label: "Fatturati",
table: "productinfos",
label: 'Fatturati',
table: 'productinfos',
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "totFat",
debounce: "1000",
mykey: 'totFat',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Fatturati ultimi 3 Mesi",
table: "productinfos",
label: 'Fatturati ultimi 3 Mesi',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "fatLast3M",
debounce: "1000",
mykey: 'fatLast3M',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Fatturati ultimi 6 Mesi",
table: "productinfos",
label: 'Fatturati ultimi 6 Mesi',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "fatLast6M",
debounce: "1000",
mykey: 'fatLast6M',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Fatturati ultimo Anno",
table: "productinfos",
label: 'Fatturati ultimo Anno',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "fatLast1Y",
debounce: "1000",
mykey: 'fatLast1Y',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Fatturati ultimi 2 Anni",
table: "productinfos",
label: 'Fatturati ultimi 2 Anni',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "fatLast2Y",
debounce: "1000",
mykey: 'fatLast2Y',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Venduti",
table: "productinfos",
label: 'Venduti',
table: 'productinfos',
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "totVen",
debounce: "1000", type: costanti.FieldType.number,
},
{
editOn: false,
label: "Venduti Ultimi 3 Mesi",
table: "productinfos",
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "vLast3M",
debounce: "1000",
mykey: 'totVen',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Venduti Ultimi 6 Mesi",
table: "productinfos",
label: 'Venduti Ultimi 3 Mesi',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "vLast6M",
debounce: "1000",
mykey: 'vLast3M',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Venduti Ultimo Anno",
table: "productinfos",
label: 'Venduti Ultimi 6 Mesi',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "vLast1Y",
debounce: "1000",
mykey: 'vLast6M',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: "Venduti Ultimi 2 Anni",
table: "productinfos",
label: 'Venduti Ultimo Anno',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "vLast2Y",
debounce: "1000",
mykey: 'vLast1Y',
debounce: '1000',
type: costanti.FieldType.number,
},
{
editOn: false,
label: 'Venduti Ultimi 2 Anni',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: 'vLast2Y',
debounce: '1000',
type: costanti.FieldType.number,
},
@@ -209,101 +211,102 @@ export default defineComponent({
type: costanti.FieldType.number,
},*/
];
return arrlist
return arrlist;
}
function getArrListDescrizioni(): IRecFields[] {
const arrlist: IRecFields[] = [
{
editOn: true,
label: "Descrizione Sinossi per Catalogo",
label: 'Descrizione Sinossi per Catalogo',
title: myproduct.value?.productInfo?.name,
table: "productinfos",
table: 'productinfos',
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "descr_trafiletto_catalogo",
debounce: "1000",
mykey: 'descr_trafiletto_catalogo',
debounce: '1000',
type: costanti.FieldType.editor_nohtml,
dense: true,
showall: true,
},
{
editOn: true,
label: "Descrizione breve macro",
label: 'Descrizione breve macro',
title: myproduct.value?.productInfo?.name,
table: "productinfos",
table: 'productinfos',
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "descrizione_breve_macro",
mykey: 'descrizione_breve_macro',
maxlength: 650,
debounce: "1000",
debounce: '1000',
type: costanti.FieldType.editor_nohtml,
dense: true,
showall: true,
},
{
editOn: true,
label: "Descrizione Estesa",
table: "productinfos",
label: 'Descrizione Estesa',
table: 'productinfos',
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "descrizione_completa_macro",
maxlength: props.scheda?.testo_bottom?.maxlength ? props.scheda?.testo_bottom?.maxlength : 10000,
debounce: "1000",
mykey: 'descrizione_completa_macro',
maxlength: props.scheda?.testo_bottom?.maxlength
? props.scheda?.testo_bottom?.maxlength
: 10000,
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
showall: true,
},
{
editOn: true,
label: "Link a gruppomacro.com",
table: "productinfos",
label: 'Link a gruppomacro.com',
table: 'productinfos',
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "link_macro",
debounce: "1000",
mykey: 'link_macro',
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
showall: true,
},
]
return arrlist
];
return arrlist;
}
function getArrListScheda(): IRecFields[] {
const arrlist: IRecFields[] = [
{
editOn: true,
label: "Verifica",
table: "products",
id: myproduct.value._id,
rec: myproduct.value,
mykey: "validaprod",
debounce: "1000",
type: costanti.FieldType.verifica,
dense: true,
},
{
editOn: true,
label: "Titolo",
table: "productinfos",
label: 'Titolo',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
mykey: "name",
debounce: "1000",
mykey: 'name',
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
},
{
editOn: true,
label: "SottoTitolo",
table: "productinfos",
label: 'Verifica',
table: 'products',
id: myproduct.value._id,
rec: myproduct.value,
mykey: 'validaprod',
debounce: '1000',
type: costanti.FieldType.verifica,
dense: true,
},
{
editOn: true,
label: 'SottoTitolo',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "sottotitolo",
debounce: "1000",
mykey: 'sottotitolo',
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
},
@@ -320,153 +323,174 @@ export default defineComponent({
},*/
{
editOn: false,
label: "Pubblicazione",
table: "productinfos",
label: 'Pubblicazione',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "date_pub",
debounce: "1000",
mykey: 'date_pub',
debounce: '1000',
type: costanti.FieldType.onlydate,
dense: true,
},
{
editOn: false,
label: "Stato",
table: "productinfos",
label: 'ISBN',
table: 'products',
id: myproduct.value._id,
rec: myproduct.value,
mykey: 'isbn',
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
},
{
editOn: false,
label: 'Stato',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "idStatoProdotto",
debounce: "1000",
mykey: 'idStatoProdotto',
debounce: '1000',
type: costanti.FieldType.select,
jointable: 't_web_statiprodottos',
dense: true,
},
{
editOn: true,
label: "Argomento",
table: "productinfos",
label: 'Argomento',
table: 'productinfos',
id: myproduct.value.productInfo?._id,
rec: myproduct.value.productInfo,
mykey: "idCatProds",
debounce: "1000",
mykey: 'idCatProds',
debounce: '1000',
type: costanti.FieldType.multiselect,
jointable: 'catprtotali',
dense: true,
},
{
editOn: true,
label: "Pagine",
table: "arrvariazioni",
label: 'Pagine',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "pagine",
debounce: "0",
mykey: 'pagine',
debounce: '0',
type: costanti.FieldType.number,
dense: true,
},
{
editOn: true,
label: "Misure",
table: "arrvariazioni",
label: 'Misure',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "misure",
debounce: "1000",
mykey: 'misure',
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
},
{
editOn: true,
label: "Edizione",
table: "arrvariazioni",
label: 'Edizione',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "edizione",
debounce: "1000",
mykey: 'edizione',
debounce: '1000',
type: costanti.FieldType.string,
dense: true,
},
{
editOn: false,
label: "Tipologia",
table: "arrvariazioni",
label: 'Tipologia',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "idTipologia",
debounce: "1000",
mykey: 'idTipologia',
debounce: '1000',
type: costanti.FieldType.select,
jointable: 't_web_tipologies',
dense: true,
},
{
editOn: true,
label: "Formato",
table: "arrvariazioni",
label: 'Formato',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "idTipoFormato",
debounce: "1000",
mykey: 'idTipoFormato',
debounce: '1000',
type: costanti.FieldType.select,
jointable: 't_web_tipiformatos',
dense: true,
},
{
editOn: true,
label: "Prezzo",
table: "arrvariazioni",
label: 'Prezzo',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "price",
debounce: "0",
mykey: 'price',
debounce: '0',
type: costanti.FieldType.number,
dense: true,
},
{
editOn: true,
label: "Prezzo Scontato",
table: "arrvariazioni",
label: 'Prezzo Scontato',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "sale_price",
debounce: "0",
mykey: 'sale_price',
debounce: '0',
type: costanti.FieldType.number,
dense: true,
},
{
editOn: false,
label: "Magazzino",
table: "arrvariazioni",
label: 'Magazzino',
table: 'arrvariazioni',
id: myproduct.value._id,
rec: myproduct.value,
mykey: "quantita",
debounce: "0",
mykey: 'quantita',
debounce: '0',
type: costanti.FieldType.number,
dense: true,
},
{
editOn: false,
label: "Aggiornato (da GM) il",
table: "productinfos",
label: 'Aggiornato (da GM) il',
table: 'productinfos',
id: myproduct.value.productInfo._id,
rec: myproduct.value.productInfo,
mykey: "date_updated_fromGM",
debounce: "1000",
mykey: 'date_updated_fromGM',
debounce: '1000',
type: costanti.FieldType.onlydate,
dense: true,
},
]
return arrlist
{
editOn: false,
label: 'Dati estratti dal Web',
table: 'products',
id: myproduct.value._id,
rec: myproduct.value,
mykey: 'scraped',
debounce: '1000',
type: costanti.FieldType.boolean,
dense: true,
},
];
return arrlist;
}
function updateproductmodif(element: any) {
console.log('CSCHEDAPRODOTTO updateproductmodif ', element)
emit('updateproductmodif', element)
console.log('CSCHEDAPRODOTTO updateproductmodif ', element);
emit('updateproductmodif', element);
}
async function updateFieldsDataToGM(data: any) {
@@ -479,7 +503,7 @@ export default defineComponent({
const sku = myproduct.value.productInfo.sku;
if (!sku) {
throw new Error("SKU non disponibile per il prodotto.");
throw new Error('SKU non disponibile per il prodotto.');
}
// Aggiorna il campo nel database utilizzando setGM_FieldOf_T_Web_Articoli
@@ -491,8 +515,13 @@ export default defineComponent({
console.log(`Record aggiornato con successo. Risultato:`, result);
} catch (error) {
console.error(`Errore durante l'aggiornamento del record:`, error.message);
throw new Error(`Errore durante l'aggiornamento del record: ${error.message}`);
console.error(
`Errore durante l'aggiornamento del record:`,
error.message
);
throw new Error(
`Errore durante l'aggiornamento del record: ${error.message}`
);
} finally {
loading.value = false; // Disattiva lo stato di caricamento
updatetogm.value = false; // Indica che l'aggiornamento è terminato
@@ -503,19 +532,25 @@ export default defineComponent({
}
function updateRecordToGM() {
console.log('myproduct.value.productInfo.catprods', myproduct.value.productInfo.catprods)
console.log(
'myproduct.value.productInfo.catprods',
myproduct.value.productInfo.catprods
);
let mydata = {
ListaArgomenti: products.getArrayidArgomentoByArridCatProds(myproduct.value.productInfo.idCatProds)
}
console.log('devo salvare mydata', mydata)
updateFieldsDataToGM(mydata)
ListaArgomenti: products.getArrayidArgomentoByArridCatProds(
myproduct.value.productInfo.idCatProds
),
};
console.log('devo salvare mydata', mydata);
updateFieldsDataToGM(mydata);
}
async function updateproduct(load?: boolean) {
myproduct.value = await products.getProductById(myproduct.value._id, load)
myproduct.value = await products.getProductById(
myproduct.value._id,
load
);
}
/*async function refreshDataFromGM() {
@@ -535,28 +570,64 @@ export default defineComponent({
async function refreshSingleBookFromGM(options: any) {
if (myproduct.value) {
loading.value = true
await globalStore.updateAllBookFromGM_T_Web_Articoli({ sku: myproduct.value.productInfo.sku!, isbn: myproduct.value.productInfo.code, ...options })
loading.value = true;
await globalStore
.updateAllBookFromGM_T_Web_Articoli({
sku: myproduct.value.productInfo.sku!,
isbn: myproduct.value.productInfo.code,
...options,
})
.then((ris) => {
if (ris) {
if (ris.error) {
tools.showNegativeNotif($q, ris.error)
tools.showNegativeNotif($q, ris.error);
} else {
updateproduct(false)
updateproduct(false);
// console.log('product AGGIORNATO:', myproduct.value)
tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK'))
tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK'));
}
loading.value = false
loading.value = false;
}
})
.catch((e) => {
console.error('Errore aggiornamento singolo libro:', e);
tools.showNegativeNotif($q, t('dbgm.updateLocalDb_ERROR'));
loading.value = false;
});
}
}
async function scrapingBook(update: boolean, aggiornasoloSeVuoti: boolean) {
const options = {
update,
aggiornasoloSeVuoti,
}
const myparam = { product_id: myproduct.value._id, options };
loading.value = true;
onMounted(mounted)
const dataupdated = await globalStore
.scrapingBook(myparam)
.then((dataupdated) => {
if (dataupdated) {
tools.showPositiveNotif($q, t('dbgm.scrapingOkUpdated'));
}
return dataupdated;
})
.catch((e) => {
console.error('Errore aggiornamento singolo libro:', e);
tools.showNegativeNotif($q, t('dbgm.updateLocalDb_ERROR'));
loading.value = false;
});
if (dataupdated) {
updateproductmodif()
}
loading.value = false;
}
onMounted(mounted);
return {
tools,
@@ -576,7 +647,8 @@ export default defineComponent({
loading,
updateRecordToGM,
refreshSingleBookFromGM,
scrapingBook,
// refreshDataFromGM,
}
}
})
};
},
});