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
feat: 优化LivePhoto处理逻辑,增加视频预加载和错feat: 改进LivePhoto视频播放逻辑,增加预加载和错误重试机制;优化状态指示器样式和上传队列管理,统一状态颜色
cuijianzhuangb735fafa8bc1
diff --git a/app/components/masonry/item/Photo.vue b/app/components/masonry/item/Photo.vueindex 2119bd13..0eaac9d8 100644--- a/app/components/masonry/item/Photo.vue+++ b/app/components/masonry/item/Photo.vue@@ -120,10 +120,15 @@ const handleMouseLeave = () => {const playLivePhotoVideo = () => {if (!videoRef.value || !videoBlobUrl.value) return+ // 预加载视频以确保流畅播放+ if (videoRef.value.readyState < 2) {+ videoRef.value.load()+ }+// 确保视频从头开始播放videoRef.value.currentTime = 0- // 优化的播放逻辑:先设置状态,然后播放+ // 添加播放前的准备动画isVideoPlaying.value = true// Provide haptic feedback on mobile when starting playback@@ -131,27 +136,49 @@ const playLivePhotoVideo = () => {navigator.vibrate(50) // Short vibration for start}- // 立即尝试播放,使用更好的错误处理- const playPromise = videoRef.value.play()-- if (playPromise !== undefined) {- playPromise- .then(() => {- // 播放成功,确保状态正确- if (videoRef.value && !videoRef.value.paused) {- isVideoPlaying.value = true- }- })- .catch((error: any) => {- console.warn('Failed to play LivePhoto video:', error)- isVideoPlaying.value = false-- // 如果是因为用户交互策略导致的失败,可以尝试重新处理- if (error.name === 'NotAllowedError') {- console.log('Video play blocked by browser policy')- }- })- }+ // 延迟播放以确保动画状态已设置+ nextTick(() => {+ if (!videoRef.value || !isVideoPlaying.value) return++ // 设置视频播放属性+ videoRef.value.muted = true // 确保静音播放+ videoRef.value.playsInline = true++ // 立即尝试播放,使用更好的错误处理+ const playPromise = videoRef.value.play()++ if (playPromise !== undefined) {+ playPromise+ .then(() => {+ // 播放成功,确保状态正确+ if (videoRef.value && !videoRef.value.paused) {+ // 视频播放成功,状态已正确设置+ }+ })+ .catch((error: any) => {+ console.warn('Failed to play LivePhoto video:', error)+ isVideoPlaying.value = false++ // 如果是因为用户交互策略导致的失败,尝试重新加载+ if (error.name === 'NotAllowedError') {+ console.log('Video play blocked by browser policy, retrying...')+ if (videoRef.value) {+ videoRef.value.load()+ setTimeout(() => {+ if (videoRef.value && isVideoPlaying.value) {+ const retryPromise = videoRef.value.play()+ if (retryPromise !== undefined) {+ retryPromise.catch(() => {+ isVideoPlaying.value = false+ })+ }+ }+ }, 100)+ }+ }+ })+ }+ })}const handleVideoEnded = () => {@@ -492,7 +519,7 @@ onUnmounted(() => {@error="handleImageError"/>- <!-- LivePhoto video with motion transition -->+ <!-- LivePhoto video with enhanced motion transition --><motion.videov-if="photo.isLivePhoto && videoBlobUrl"ref="videoRef"@@ -502,16 +529,27 @@ onUnmounted(() => {mutedplaysinlinepreload="metadata"- :initial="{ opacity: 0 }"+ :initial="{+ opacity: 0,+ scale: 1.02+ }":animate="{opacity: isVideoPlaying ? 1 : 0,+ scale: isVideoPlaying ? 1 : 1.02,}":transition="{- duration: 0.4,- ease: [0.25, 0.1, 0.25, 1],- delay: isVideoPlaying ? 0.1 : 0, // Slight delay when fading in video+ duration: isVideoPlaying ? 0.3 : 0.2,+ ease: isVideoPlaying ? [0.23, 1, 0.32, 1] : [0.25, 0.46, 0.45, 0.94],+ delay: isVideoPlaying ? 0.05 : 0,}"@ended="handleVideoEnded"+ @loadeddata="() => {+ // 视频加载完成后预热+ if (videoRef && !isVideoPlaying) {+ videoRef.currentTime = 0.1+ videoRef.pause()+ }+ }"/></div>diff --git a/app/components/photo/LivePhotoIndicator.vue b/app/components/photo/LivePhotoIndicator.vueindex 485dcfec..2a2883e0 100644--- a/app/components/photo/LivePhotoIndicator.vue+++ b/app/components/photo/LivePhotoIndicator.vue@@ -34,26 +34,27 @@ const displayText = computed(() => {if (state.retryCount && state.retryCount > 0) {return `重试中 ${state.retryCount}/3`}- return '处理中...'+ return '处理中'}if (state?.error) {- return '处理失败'+ return '失败'}- return $t('ui.livePhoto')+ // 确保显示"实况"文字+ return '实况'})-// 计算颜色样式+// 计算颜色样式 - 更贴近iOS原生设计const colorClass = computed(() => {switch (indicatorState.value) {case 'playing':- return 'text-yellow-300 bg-yellow-300/20 border-yellow-300/30'+ return 'text-white bg-black/30 border-white/40 shadow-lg'case 'processing':- return 'text-blue-300 bg-blue-300/20 border-blue-300/30'+ return 'text-blue-300 bg-black/40 border-blue-300/50 shadow-lg'case 'error':- return 'text-red-300 bg-red-300/20 border-red-300/30'+ return 'text-red-300 bg-black/40 border-red-300/50 shadow-lg'case 'ready':default:- return 'text-white bg-black/40 border-white/20'+ return 'text-white bg-black/30 border-white/30 shadow-md'}})</script>@@ -61,64 +62,70 @@ const colorClass = computed(() => {<template><motion.divv-if="photo.isLivePhoto"- class="backdrop-blur-md rounded-full pl-1 pr-1.5 py-1 text-[13px] font-bold flex items-center gap-0.5 leading-0 select-none border transition-all duration-300"+ class="relative backdrop-blur-lg rounded-full px-2 py-1 text-[12px] font-medium flex items-center gap-1 leading-none select-none border-0 transition-all duration-300 overflow-hidden":class="colorClass":animate="{- scale: isVideoPlaying ? 1.08 : indicatorState === 'processing' ? 1.02 : 1,- rotate: indicatorState === 'error' ? [0, -2, 2, 0] : 0,+ scale: isVideoPlaying ? 1.05 : indicatorState === 'processing' ? 1.02 : 1,+ opacity: isVideoPlaying ? 0.95 : 1,}":transition="{- duration: indicatorState === 'error' ? 0.5 : 0.3,- ease: indicatorState === 'error' ? 'easeInOut' : 'easeOut',+ duration: 0.2,+ ease: 'easeOut',}">- <!-- 处理中状态 -->+ <!-- 简洁的播放状态光效 --><motion.div- v-if="processingState?.isProcessing"- class="size-[17px] relative"- :animate="{ rotate: 360 }"- :transition="{ duration: 1, repeat: Infinity, ease: 'linear' }"- >- <Icon- name="tabler:loader"- class="size-[17px]"- />- </motion.div>-- <!-- 错误状态 -->- <motion.div- v-else-if="processingState?.error"- class="size-[17px]"- :animate="{ scale: [1, 1.1, 1] }"- :transition="{ duration: 0.6, repeat: Infinity }"- >- <Icon- name="tabler:alert-circle"- class="size-[17px]"- />- </motion.div>-- <!-- 播放中状态 -->- <motion.div- v-else-if="isVideoPlaying"- class="size-[17px]"- :animate="{ scale: [1, 1.1, 1] }"- :transition="{ duration: 0.8, repeat: Infinity }"- >- <Icon- name="tabler:player-play-filled"- class="size-[17px]"- />- </motion.div>-- <!-- 正常状态 -->- <Icon- v-else- name="tabler:live-photo"- class="size-[17px]"+ v-if="isVideoPlaying"+ class="absolute inset-0 rounded-full bg-white/10"+ :animate="{+ opacity: [0.3, 0.1, 0.3]+ }"+ :transition="{ duration: 2, repeat: Infinity, ease: 'easeInOut' }"/>-- <span class="truncate">{{ displayText }}</span>+ <!-- 内容区域 - 简化设计 -->+ <div class="relative z-10 flex items-center gap-1">+ <!-- 简化的图标显示 -->+ <motion.div+ class="size-[14px] relative flex items-center justify-center"+ :animate="{+ rotate: processingState?.isProcessing ? 360 : 0,+ }"+ :transition="{+ duration: processingState?.isProcessing ? 1 : 0.2,+ repeat: processingState?.isProcessing ? Infinity : 0,+ ease: 'linear'+ }"+ >+ <!-- 处理中状态 -->+ <Icon+ v-if="processingState?.isProcessing"+ name="tabler:loader-2"+ class="size-[14px]"+ />++ <!-- 错误状态 -->+ <motion.div+ v-else-if="processingState?.error"+ :animate="{ scale: [1, 1.1, 1] }"+ :transition="{ duration: 1, repeat: Infinity }"+ >+ <Icon+ name="tabler:exclamation-mark"+ class="size-[14px]"+ />+ </motion.div>++ <!-- 播放中/正常状态 - 统一使用实况图标 -->+ <Icon+ v-else+ name="tabler:live-photo"+ class="size-[14px]"+ :class="{ 'opacity-90': isVideoPlaying }"+ />+ </motion.div>++ <span class="truncate">{{ displayText }}</span>+ </div><!-- 进度条 --><motion.divdiff --git a/app/components/upload/UploadAnimationCard.vue b/app/components/upload/UploadAnimationCard.vueindex b0cf23ee..142e127d 100644--- a/app/components/upload/UploadAnimationCard.vue+++ b/app/components/upload/UploadAnimationCard.vue@@ -48,15 +48,15 @@ const fileIcon = computed(() => {const statusColor = computed(() => {switch (props.uploadingFile.status) {case 'preparing':- return 'blue'+ return 'primary'case 'uploading':- return 'blue'+ return 'primary'case 'processing':- return 'purple'+ return 'info'case 'completed':- return 'green'+ return 'success'case 'error':- return 'red'+ return 'error'default:return 'neutral'}@@ -145,7 +145,13 @@ const formatBytes = (bytes: number) => {><divclass="w-10 h-10 rounded-lg flex items-center justify-center"- :class="`bg-${statusColor}-100 dark:bg-${statusColor}-900/30`"+ :class="{+ 'bg-blue-100 dark:bg-blue-900/30': statusColor === 'primary',+ 'bg-green-100 dark:bg-green-900/30': statusColor === 'success',+ 'bg-red-100 dark:bg-red-900/30': statusColor === 'error',+ 'bg-blue-100 dark:bg-blue-900/30': statusColor === 'info',+ 'bg-neutral-100 dark:bg-neutral-900/30': statusColor === 'neutral'+ }"><Icon:name="fileIcon"@@ -367,14 +373,50 @@ const formatBytes = (bytes: number) => {<AnimatePresence><motion.divv-if="uploadingFile.status === 'completed'"- :initial="{ opacity: 0, scale: 0.9 }"- :animate="{ opacity: 1, scale: 1 }"- :exit="{ opacity: 0, scale: 0.9 }"- :transition="{ duration: 0.3, delay: 0.1 }"- class="mt-3 flex items-center gap-2 text-green-600 dark:text-green-400"+ :initial="{ opacity: 0, scale: 0.8, y: 10 }"+ :animate="{+ opacity: 1,+ scale: [0.8, 1.1, 1],+ y: 0,+ backgroundColor: ['rgba(34, 197, 94, 0)', 'rgba(34, 197, 94, 0.1)', 'rgba(34, 197, 94, 0)']+ }"+ :exit="{ opacity: 0, scale: 0.9, y: -10 }"+ :transition="{+ duration: 0.6,+ ease: 'backOut',+ backgroundColor: { duration: 1.2, ease: 'easeInOut' }+ }"+ class="mt-3 flex items-center gap-2 text-green-600 dark:text-green-400 rounded-lg p-2 -m-2">- <Icon name="tabler:check-circle" class="w-4 h-4" />- <span class="text-sm font-medium">上传完成</span>+ <motion.div+ :animate="{ rotate: [0, 360] }"+ :transition="{ duration: 0.5, delay: 0.1 }"+ >+ <Icon name="tabler:check-circle" class="w-4 h-4" />+ </motion.div>+ <span class="text-sm font-medium">处理完成</span>++ <!-- 庆祝粒子效果 -->+ <motion.div+ v-for="i in 3"+ :key="`particle-${i}`"+ class="absolute w-1 h-1 bg-green-500 rounded-full pointer-events-none"+ :style="{+ left: `${20 + i * 10}px`,+ top: `${10 + i * 5}px`+ }"+ :animate="{+ y: [-5, -15, -5],+ x: [0, (i - 2) * 10, 0],+ opacity: [0, 1, 0],+ scale: [0, 1.5, 0]+ }"+ :transition="{+ duration: 1,+ delay: 0.2 + i * 0.1,+ ease: 'easeOut'+ }"+ /></motion.div></AnimatePresence></motion.div>diff --git a/app/components/upload/UploadQueueContainer.vue b/app/components/upload/UploadQueueContainer.vueindex 458076aa..c3de6390 100644--- a/app/components/upload/UploadQueueContainer.vue+++ b/app/components/upload/UploadQueueContainer.vue@@ -1,6 +1,6 @@<script lang="ts" setup>import { motion, AnimatePresence } from 'motion-v'-import { computed, ref } from 'vue'+import { computed, ref, watch } from 'vue'interface UploadFile {file: File@@ -72,9 +72,9 @@ const overallProgress = computed(() => {// 计算状态颜色const statusColor = computed(() => {- if (stats.value.error > 0) return 'red'- if (stats.value.active > 0) return 'blue'- if (stats.value.completed > 0 && stats.value.active === 0) return 'green'+ if (stats.value.error > 0) return 'error'+ if (stats.value.active > 0) return 'primary'+ if (stats.value.completed > 0 && stats.value.active === 0) return 'success'return 'neutral'})@@ -93,6 +93,8 @@ const clearCompletedFiles = () => {const clearAllFiles = () => {emit('clearAll')}++// 统一的完成处理逻辑,避免重复通知</script><template>@@ -120,12 +122,12 @@ const clearAllFiles = () => {<!-- 状态指示器 --><motion.divclass="w-3 h-3 rounded-full"- :class="{- 'bg-blue-500': statusColor === 'blue',- 'bg-green-500': statusColor === 'green',- 'bg-red-500': statusColor === 'red',- 'bg-neutral-400': statusColor === 'neutral'- }"+ :class="{+ 'bg-blue-500': statusColor === 'primary',+ 'bg-green-500': statusColor === 'success',+ 'bg-red-500': statusColor === 'error',+ 'bg-neutral-400': statusColor === 'neutral'+ }":animate="{scale: stats.active > 0 ? [1, 1.2, 1] : 1,opacity: stats.active > 0 ? [0.7, 1, 0.7] : 1diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex 838fa75c..d14ffeb0 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -281,12 +281,7 @@ const startTaskStatusCheck = (taskId: number, fileId: string) => {clearInterval(intervalId)statusIntervals.value.delete(taskId)- // 显示错误提示- toast.add({- title: '照片处理失败',- description: `照片 ${uploadingFile.fileName} 处理失败: ${response.errorMessage || '未知错误'}`,- color: 'error',- })+ // 错误信息已在上传组件中显示,不需要额外通知// 失败的任务不自动移除,让用户查看错误信息}} catch (error) {