Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
fix: 缩略图加载状态处理异常
HoshinoSuzumi8f8230d8619f
diff --git a/app/components/MasonryPhotoItem.vue b/app/components/MasonryPhotoItem.client.vuesimilarity index 88%rename from app/components/MasonryPhotoItem.vuerename to app/components/MasonryPhotoItem.client.vueindex 9b9e85a4..744f1843 100644--- a/app/components/MasonryPhotoItem.vue+++ b/app/components/MasonryPhotoItem.client.vue@@ -25,6 +25,7 @@ const DEFAULT_WIDTH = 280const isLoading = ref(true)const actualHeight = ref(0)const photoRef = ref<HTMLElement>()+const mainImageRef = ref<HTMLImageElement>()const isVisible = ref(false)// Computed@@ -68,6 +69,19 @@ const handleImageError = () => {console.warn(`Failed to load image: ${props.photo.thumbnailUrl}`)}+// Check if image is already loaded (cached)+const checkImageLoaded = (img: HTMLImageElement) => {+ if (img.complete && img.naturalHeight !== 0) {+ // Create a synthetic event for consistency+ const syntheticEvent = new Event('load')+ Object.defineProperty(syntheticEvent, 'target', {+ value: img,+ enumerable: true+ })+ handleImageLoad(syntheticEvent)+ }+}+const formatDate = (date: string | Date): string => {if (!date) return ''const d = new Date(date)@@ -133,8 +147,17 @@ onMounted(() => {const aspectRatio = img.naturalHeight / img.naturalWidthactualHeight.value = Math.round(DEFAULT_WIDTH * (props.photo.aspectRatio || aspectRatio))}+ // Update loading state after preload completes+ isLoading.value = false+ }+ img.onerror = () => {+ // Even if preload fails, we should stop loading state+ isLoading.value = false}img.src = props.photo.thumbnailUrl+ } else {+ // If no thumbnail URL, stop loading immediately+ isLoading.value = false}// Set up intersection observer for visibility tracking@@ -167,6 +190,11 @@ onMounted(() => {observer.disconnect()})}++ // Check if main image is already loaded from cache+ if (mainImageRef.value) {+ checkImageLoaded(mainImageRef.value)+ }})})</script>@@ -192,7 +220,7 @@ onMounted(() => {<!-- Thumbhash 组件占位符 --><divv-if="isLoading && photo.thumbnailHash"- class="w-full absolute inset-0"+ class="w-full h-full absolute inset-0"><Thumbhash:thumbhash="photo.thumbnailHash"@@ -204,11 +232,12 @@ onMounted(() => {<!-- Loading placeholder (fallback when no thumbhash) --><divv-if="isLoading && !photo.thumbnailHash"- class="w-full bg-gray-200 dark:bg-gray-700 animate-pulse"+ class="w-full h-full bg-gray-200 dark:bg-gray-700 animate-pulse absolute inset-0"/><!-- Main image --><img+ ref="mainImageRef"v-show="!isLoading":src="photo.thumbnailUrl || ''":alt="photo.title || photo.description || 'Photo'"diff --git a/app/pages/index.vue b/app/pages/index.vueindex f1a6dc9c..12b395bc 100644--- a/app/pages/index.vue+++ b/app/pages/index.vue@@ -3,7 +3,7 @@ const { data } = useFetch('/api/photos')</script><template>- <div class="min-h-screen p-2 pt-1 bg-gray-50 dark:bg-gray-900">+ <div class="h-svh p-2 pt-1 bg-gray-50 dark:bg-gray-900"><MasonryRoot:photos="data as Photo[]":columns="'auto'"diff --git a/types/index.d.ts b/types/index.d.tsnew file mode 100644index 00000000..e69de29b