- Catalogo: qualità di stampa, margini. ora è 300 DPI.

This commit is contained in:
Surya Paolo
2024-12-05 14:13:19 +01:00
parent 1cb5e6f1ad
commit 5c20e75b6a
20 changed files with 359 additions and 51 deletions

View File

@@ -4,15 +4,16 @@ import axios, {
import { Api } from '@api'
import * as Types from '@src/store/Api/ApiTypes'
async function sendRequest(url: string, method: string, mydata: any) {
// if (process.env.DEBUG) console.log('sendRequest', method, url)
async function sendRequest(url: string, method: string, mydata: any, myformdata?: any, responsedata?: any) {
console.log('sendRequest', method, url, mydata)
let request
if (method === 'GET') request = Api.get(url, mydata)
else if (method === 'POST') request = Api.post(url, mydata)
else if (method === 'DELETE') request = Api.Delete(url, mydata)
else if (method === 'PUT') request = Api.put(url, mydata)
else if (method === 'PATCH') request = Api.patch(url, mydata)
if (method === 'GET') request = Api.get(url, mydata, responsedata)
else if (method === 'POST') request = Api.post(url, mydata, responsedata)
else if (method === 'postFormData') request = Api.postFormData(url, myformdata, responsedata)
else if (method === 'DELETE') request = Api.Delete(url, mydata, responsedata)
else if (method === 'PUT') request = Api.put(url, mydata, responsedata)
else if (method === 'PATCH') request = Api.patch(url, mydata, responsedata)
// @ts-ignore
const req: Promise<Types.AxiosSuccess | Types.AxiosError> = request

View File

@@ -47,7 +47,7 @@ export const addAuthHeaders = () => {
// delete axiosInstance.defaults.headers.Authorization
//}
async function Request(type: string, path: string, payload: any): Promise<Types.AxiosSuccess | Types.AxiosError | undefined> {
async function Request(type: string, path: string, payload: any, responsedata?: any): Promise<Types.AxiosSuccess | Types.AxiosError | undefined> {
let ricevuto = false
const userStore = useUserStore()
@@ -65,6 +65,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
'x-auth': userStore.x_auth_token,
'x-refrtok': userStore.refreshToken,
},
...responsedata,
})
ricevuto = true
// console.log('Request Response: ', response)
@@ -119,10 +120,12 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
'x-auth': userStore.x_auth_token,
'x-refrtok': userStore.refreshToken,
},
...responsedata,
})
ricevuto = true
return new Types.AxiosSuccess(response.data, response.status)
} else if (type === 'postFormData') {
console.log('postFormData', payload)
response = await axiosInstance.post(path, payload, {
baseURL: globalStore.getServerHost(),
headers: {
@@ -130,6 +133,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
'x-auth': userStore.x_auth_token,
'x-refrtok': userStore.refreshToken,
},
...responsedata,
})
ricevuto = true
return new Types.AxiosSuccess(response.data, response.status)

View File

@@ -37,43 +37,43 @@ function ReceiveResponsefromServer(tablesync: string, nametab: string, method: s
// const algoliaApi = new AlgoliaSearch()
export const Api = {
async post(path: string, payload?: any) {
async post(path: string, payload?: any, responsedata?: any) {
const globalStore = useGlobalStore()
globalStore.connData.downloading_server = 1
globalStore.connData.uploading_server = 1
return Request('post', path, payload)
return Request('post', path, payload, responsedata)
},
async postFormData(path: string, payload?: any) {
async postFormData(path: string, payload?: any, responsedata?: any) {
const globalStore = useGlobalStore()
globalStore.connData.uploading_server = 1
globalStore.connData.downloading_server = 1
return Request('postFormData', path, payload)
return Request('postFormData', path, payload, responsedata)
},
async get(path: string, payload?: any) {
async get(path: string, payload?: any, responsedata?: any) {
const globalStore = useGlobalStore()
globalStore.connData.downloading_server = 1
globalStore.connData.uploading_server = 0
return Request('get', path, payload)
return Request('get', path, payload, responsedata)
},
async put(path: string, payload?: any) {
async put(path: string, payload?: any, responsedata?: any) {
const globalStore = useGlobalStore()
globalStore.connData.uploading_server = 1
return Request('put', path, payload)
return Request('put', path, payload, responsedata)
},
async patch(path: string, payload?: any) {
async patch(path: string, payload?: any, responsedata?: any) {
const globalStore = useGlobalStore()
globalStore.connData.uploading_server = 1
return Request('patch', path, payload)
return Request('patch', path, payload, responsedata)
},
async Delete(path: string, payload: any) {
async Delete(path: string, payload: any, responsedata?: any) {
const globalStore = useGlobalStore()
globalStore.connData.uploading_server = 1
return Request('delete', path, payload)
return Request('delete', path, payload, responsedata)
},
async checkSession({ token, refresh_token }: any) {
@@ -131,7 +131,7 @@ export const Api = {
},
async SendReqBase(url: string, method: string, mydata: any, setAuthToken = false, evitaloop = false): Promise<Types.AxiosSuccess | Types.AxiosError> {
async SendReqBase(url: string, method: string, mydata: any, setAuthToken = false, evitaloop = false, myformdata?: any, responsedata?: any): Promise<Types.AxiosSuccess | Types.AxiosError> {
const mydataout = {
...mydata,
keyappid: process.env.PAO_APP_ID,
@@ -145,7 +145,7 @@ export const Api = {
userStore.setServerCode(tools.EMPTY)
userStore.setResStatus(0)
return new Promise((resolve, reject) => sendRequest(url, method, mydataout)
return new Promise((resolve, reject) => sendRequest(url, method, mydataout, myformdata, responsedata)
.then((res) => {
setTimeout(() => {
if (method === 'get') {
@@ -245,10 +245,12 @@ export const Api = {
setAuthToken = false,
evitaloop = false,
retryCount = 3,
retryDelay = 5000
retryDelay = 5000,
myformdata?: any,
responsedata?: any,
): Promise<Types.AxiosSuccess | Types.AxiosError> {
try {
const response = await this.SendReqBase(url, method, mydata, setAuthToken, evitaloop);
const response = await this.SendReqBase(url, method, mydata, setAuthToken, evitaloop, myformdata, responsedata);
return response;
} catch (error: any) {
if (retryCount > 0) {
@@ -262,7 +264,9 @@ export const Api = {
setAuthToken,
evitaloop,
retryCount - 1,
retryDelay
retryDelay,
myformdata,
responsedata,
);
}
throw error;

View File

@@ -380,16 +380,24 @@ export const tools = {
SelectListFormatPDF: [
{ label: 'a4 (mm)', value: [210, 297] },
{ label: '22,60 x 31,26 (in mm)', value: [226.0, 312.6] },
{ label: '22,60 x 31,31 (in mm)', value: [226.0, 313.1] },
{ label: '22,60 x 31,20 (in mm)', value: [226.0, 312.0] },
{ label: '22,60 x 31,10 (in mm)', value: [226.0, 311.0] },
],
SelectListScalePDF: [
{ label: 'Normale (100 DPI)', value: 1 },
{ label: 'Medio (200 PDI)', value: 2 },
{ label: 'Alto (300 PDI)', value: 3 },
{ label: 'Normale (72 DPI)', value: 1 },
{ label: 'Medio (144 PDI)', value: 2 },
{ label: 'Medio-Alta (180 PDI)', value: 2.5 },
{ label: 'Medio-Alta2 (201 PDI)', value: 2.8 },
{ label: 'Alto (216 PDI)', value: 3 },
{ label: 'Alto2 (288 PDI)', value: 4 },
],
SelectListQualityPDF: [
{ label: 'Bassa (1 scale)', value: 1 },
{ label: 'Bassa-Norm (1.5 scale)', value: 1.5 },
{ label: 'Normale (2 scale)', value: 2 },
{ label: 'Normale2.5 (2.5 scale)', value: 2.5 },
{ label: 'Media (3 scale)', value: 3 },
{ label: 'Elevata (4 scale)', value: 4 },
],
@@ -8629,6 +8637,20 @@ export const tools = {
},
removeFileExtension(filename: string) {
// Trova l'ultima occorrenza del punto nel nome del file
const lastDotIndex = filename.lastIndexOf('.');
// Se non c'è un punto o il punto è all'inizio del nome file,
// restituisci il nome file originale
if (lastDotIndex === -1 || lastDotIndex === 0) {
return filename;
}
// Altrimenti, restituisci la parte del nome file prima dell'ultimo punto
return filename.substring(0, lastDotIndex);
},
removeescape(inputString: string): string {
return inputString.replace('\\', '').replace(/"/g, '')
},

View File

@@ -2283,6 +2283,56 @@ export const useGlobalStore = defineStore('GlobalStore', {
})
},
async execConvertPDF(paramquery: any) {
// console.log('paramquery', paramquery)
return Api.SendReq('/admin/convert-pdf', 'postFormData', {}, false, false, 1, 5000, paramquery, { responseType: 'blob' })
.then((res) => {
return res.data
}).catch((error) => {
return false
})
},
async convertPdf(pdfFile: any, width: string, height: string, compressione: string) {
try {
if (!pdfFile) {
console.error('No PDF file selected');
return;
}
const filenameToDownload = tools.removeFileExtension(pdfFile.name) + '-output.pdf'
const formData = new FormData();
if (pdfFile instanceof File) {
formData.append('pdf', pdfFile);
}
formData.append('width', width); // Dimensione del PDF in cm
formData.append('height', height); // Dimensione del PDF in cm
formData.append('compressione', compressione);
const response = await this.execConvertPDF(formData)
if (response) {
const blob = new Blob([response], { type: 'application/pdf' });
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', filenameToDownload);
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(downloadUrl);
} else {
console.error('No data returned from the server.');
}
} catch (error) {
console.error('Error converting PDF:', error);
}
},
async saveServerMysql(paramquery: any) {
return Api.SendReq('/admin/mysql', 'POST', paramquery)
.then((res) => {