fix : correction du téléchargement du bon de réception pour Chrome

This commit is contained in:
tristan
2026-02-02 08:05:00 +01:00
parent 1ce6357c1d
commit 086279f962
4 changed files with 70 additions and 42 deletions
@@ -73,8 +73,14 @@ const printReceipt = async () => {
return
}
// Ouvre l'onglet tout de suite pour éviter le blocage popup de Chrome
const previewWindow = window.open('', '_blank')
if (previewWindow) {
previewWindow.opener = null
}
await saveWeight()
await printPdf(`/receptions/${receptionStore.current.id}/receipt`)
await printPdf(`/receptions/${receptionStore.current.id}/receipt`, previewWindow)
// Laisse le temps a la boite de dialogue d'impression de s'ouvrir.
await new Promise((resolve) => setTimeout(resolve, 600))
+11 -9
View File
@@ -5,7 +5,7 @@ export const usePdfPrinter = () => {
const receptionStore = useReceptionStore()
const currentReception = receptionStore.current
const printPdf = async (url: string): Promise<void> => {
const printPdf = async (url: string, previewWindow?: Window | null): Promise<void> => {
const blob = await api.getBlob(url);
const pdfBlob = blob.type === 'application/pdf'
@@ -16,15 +16,17 @@ export const usePdfPrinter = () => {
const filename = `${currentReception.identificationNumber}_${currentReception.supplier.name}_${currentReception.licensePlate}.pdf`;
const a = document.createElement('a');
a.href = blobUrl;
a.download = filename;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
a.remove();
if (previewWindow) {
previewWindow.location.replace(blobUrl)
}
// L'ouverture dans un nouvel onglet déclenche un 2e PDF sans le nom personnalisé.
const a = document.createElement('a')
a.href = blobUrl
a.download = filename
a.style.display = 'none'
document.body.appendChild(a)
a.click()
a.remove()
setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000);
}