feat: reimport pdf

This commit is contained in:
2026-01-22 21:23:46 +01:00
parent 981fabcc27
commit 4f0ca67dc4
13 changed files with 1068 additions and 14 deletions

View File

@@ -327,13 +327,32 @@ function updateOperationsGroup(categorie, updatedGroupOperations) {
if (!updated.data) updated.data = {}
if (!updated.data.recapitulatif_operations) updated.data.recapitulatif_operations = []
// Reconstruire la liste complete des operations
// 1. Filtrer toutes les operations de cette categorie
const otherOperations = updated.data.recapitulatif_operations.filter(op => op.categorie !== categorie)
// Reconstruire la liste en preservant l'ordre original
const newOperations = []
let updatedIndex = 0
// 2. Combiner avec les operations mises a jour
updated.data.recapitulatif_operations = [...otherOperations, ...updatedGroupOperations]
// Parcourir les operations originales et remplacer celles de la categorie modifiee
for (const op of updated.data.recapitulatif_operations) {
if (op.categorie === categorie) {
// Remplacer par les operations mises a jour (dans l'ordre)
if (updatedIndex < updatedGroupOperations.length) {
newOperations.push(updatedGroupOperations[updatedIndex])
updatedIndex++
}
// Si on a supprime des operations, on ne les ajoute pas
} else {
// Garder les operations des autres categories telles quelles
newOperations.push(op)
}
}
// Ajouter les nouvelles operations si on en a ajoute
while (updatedIndex < updatedGroupOperations.length) {
newOperations.push(updatedGroupOperations[updatedIndex])
updatedIndex++
}
updated.data.recapitulatif_operations = newOperations
emit('update:data', updated)
}

View File

@@ -113,6 +113,10 @@ const props = defineProps({
type: File,
default: null
},
url: {
type: String,
default: null
},
fileName: {
type: String,
default: 'document.pdf'
@@ -131,14 +135,26 @@ const baseScale = ref(1)
let pdfDoc = null
let renderTask = null
async function loadPdf(file) {
if (!file) return
async function loadPdf(source) {
if (!source) return
isLoading.value = true
error.value = null
try {
const arrayBuffer = await file.arrayBuffer()
let arrayBuffer
// Support URL
if (typeof source === 'string') {
const response = await fetch(source)
if (!response.ok) throw new Error('Erreur lors du chargement du PDF')
arrayBuffer = await response.arrayBuffer()
}
// Support File
else {
arrayBuffer = await source.arrayBuffer()
}
const loadingTask = pdfjsLib.getDocument({ data: arrayBuffer })
pdfDoc = await loadingTask.promise
@@ -251,9 +267,10 @@ function onWheel(e) {
}
}
watch(() => props.file, async (newFile) => {
if (newFile) {
await loadPdf(newFile)
watch([() => props.file, () => props.url], async ([newFile, newUrl]) => {
const source = newUrl || newFile
if (source) {
await loadPdf(source)
} else {
pdfDoc = null
totalPages.value = 0