Fix upload documents

This commit is contained in:
Vladimir 2026-07-05 18:36:12 +03:00
parent f3143b4651
commit ed6d311335

View File

@ -27,7 +27,7 @@
accept=".pdf,.doc,.docx,.jpg,.png" accept=".pdf,.doc,.docx,.jpg,.png"
@select="onFileSelect" @select="onFileSelect"
@uploader="saveDealDoc" @uploader="saveDealDoc"
@clear="selectedFile = null" @clear="selectedFile = null; thumbnailPreview = null"
> >
<template #header="{ chooseCallback, uploadCallback, clearCallback, files }"> <template #header="{ chooseCallback, uploadCallback, clearCallback, files }">
<div class="flex flex-wrap gap-2"> <div class="flex flex-wrap gap-2">
@ -42,7 +42,10 @@
<template #content="{ files }"> <template #content="{ files }">
<div v-if="files && files.length > 0" class="flex items-center justify-between gap-2 p-2"> <div v-if="files && files.length > 0" class="flex items-center justify-between gap-2 p-2">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<img :src="defaultDocIcon" alt="" width="32" height="32"> <div v-if="thumbnailPreview" class="w-10 h-14 rounded overflow-hidden border flex-shrink-0">
<img :src="thumbnailPreview" alt="Превью" class="w-full h-full object-cover" />
</div>
<img v-else :src="defaultDocIcon" alt="" width="32" height="32">
<span class="text-sm">{{ files[0].name }}</span> <span class="text-sm">{{ files[0].name }}</span>
</div> </div>
<Button @click="onUploadClick" size="small" outlined severity="success"> <Button @click="onUploadClick" size="small" outlined severity="success">
@ -106,6 +109,7 @@ const toast = useToast();
// Реактивные переменные для названия и файла // Реактивные переменные для названия и файла
const documentName = ref(''); const documentName = ref('');
const selectedFile = ref(null); const selectedFile = ref(null);
const thumbnailPreview = ref(null);
const fileUploadRef = ref(null); const fileUploadRef = ref(null);
const onUploadClick = () => { const onUploadClick = () => {
@ -114,9 +118,21 @@ const onUploadClick = () => {
} }
}; };
// Событие выбора файла // Событие выбора файла сразу генерируем preview
const onFileSelect = (event) => { const onFileSelect = async (event) => {
selectedFile.value = event.files[0]; selectedFile.value = event.files[0];
thumbnailPreview.value = null;
if (selectedFile.value) {
try {
const result = await generateThumbnail(selectedFile.value);
if (result) {
thumbnailPreview.value = URL.createObjectURL(result.blob);
}
} catch (e) {
console.error('[DocAddModal] Preview generation error:', e);
}
}
}; };