фикс фото в ленте

This commit is contained in:
Professional 2025-05-22 00:09:16 +07:00
parent 0281ba1054
commit e458c8e137

View File

@ -34,7 +34,7 @@
<img :src="photo.url" <img :src="photo.url"
class="d-block w-100 user-photo" class="d-block w-100 user-photo"
:alt="'Фото ' + currentUserToSwipe.name + ' ' + (index + 1)" :alt="'Фото ' + currentUserToSwipe.name + ' ' + (index + 1)"
@error="onImageError($event, currentUserToSwipe, photo._id)"> @error="onImageError($event, currentUserToSwipe, photo)"> <!-- MODIFIED: pass photo object -->
</div> </div>
</div> </div>
<button v-if="currentUserToSwipe.photos.length > 1" class="carousel-control-prev" type="button" :data-bs-target="`#carouselUserPhotos-${currentUserToSwipe._id}`" data-bs-slide="prev"> <button v-if="currentUserToSwipe.photos.length > 1" class="carousel-control-prev" type="button" :data-bs-target="`#carouselUserPhotos-${currentUserToSwipe._id}`" data-bs-slide="prev">
@ -222,25 +222,33 @@ const formatGender = (gender) => {
return ''; // Возвращаем пустую строку, если пол не указан, чтобы не было "Пол не указан" return ''; // Возвращаем пустую строку, если пол не указан, чтобы не было "Пол не указан"
}; };
const onImageError = (event, userOnError, photoIdOnError) => { const onImageError = (event, userOnError, photoWithError) => { // MODIFIED: signature and content
console.warn("Не удалось загрузить изображение:", event.target.src, "для пользователя:", userOnError.name, "фото ID:", photoIdOnError); console.warn(
const userInSuggestions = suggestions.value.find(u => u._id === userOnError._id); "SwipeView: Не удалось загрузить изображение.",
if (userInSuggestions && userInSuggestions.photos) { {
const photoIndex = userInSuggestions.photos.findIndex(p => p._id === photoIdOnError); src: event.target.src,
if (photoIndex > -1) { user: userOnError.name,
// Вместо удаления можно установить флаг ошибки или заменить URL на заглушку photo_id: photoWithError._id,
// userInSuggestions.photos.splice(photoIndex, 1); photo_url: photoWithError.url,
// Если просто убрать фото из массива, и оно было единственным, карусель исчезнет. event_target_attributes: {
// Лучше обработать это в UI, показав заглушку для этого конкретного слайда или скрыв слайд. naturalWidth: event.target.naturalWidth,
// Пока просто выводим ошибку и позволяем Bootstrap обработать битую картинку (покажет alt текст). naturalHeight: event.target.naturalHeight,
event.target.style.display = 'none'; // Скрываем битое изображение complete: event.target.complete,
// Можно добавить заглушку на место битого изображения, если это один слайд из многих },
} errorEventDetails: event
// Если после ошибки не осталось фото, показываем общую заглушку
if (!userInSuggestions.photos.some(p => p.url)) {
userInSuggestions.mainPhotoUrl = null; // Это для старой логики с одним фото, нужно будет обновить
}
} }
);
// For debugging, let's NOT hide the image for now.
// This will show the browser's default broken image icon.
// event.target.style.display = 'none'; // MODIFIED: Commented out for debugging
// The logic to update userInSuggestions.mainPhotoUrl is outdated.
// const userInSuggestions = suggestions.value.find(u => u._id === userOnError._id);
// if (userInSuggestions && userInSuggestions.photos) {
// if (!userInSuggestions.photos.some(p => p.url)) {
// // userInSuggestions.mainPhotoUrl = null; // Outdated line
// }
// }
}; };
</script> </script>