Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

feat(reaction): add reaction confetti effect

HoshinoSuzumi4b99fff9d418
diff --git a/app/components/photo/ReactionConfetti.vue b/app/components/photo/ReactionConfetti.vue
new file mode 100644
index 00000000..50602a9c
--- /dev/null
+++ b/app/components/photo/ReactionConfetti.vue
@@ -0,0 +1,94 @@
+<script setup lang="ts">
+import { motion } from 'motion-v'
+
+interface Props {
+ iconName: string
+ triggerCount: number
+}
+
+const props = defineProps<Props>()
+
+// 生成礼花粒子的配置
+interface Particle {
+ id: number
+ angle: number
+ distance: number
+ delay: number
+ duration: number
+ rotation: number
+ scale: number
+}
+
+const particles = computed<Particle[]>(() => {
+ if (props.triggerCount === 0) return []
+
+ const count = 18 // 礼花数量
+ const result: Particle[] = []
+
+ for (let i = 0; i < count; i++) {
+ const angle = (360 / count) * i
+ const distance = 80 + Math.random() * 40 // 随机距离 80-120px
+ const delay = Math.random() * 0.15 // 随机延迟,增加到 0.15
+ const duration = 1.2 + Math.random() * 0.4 // 随机持续时间,增加到 1.2-1.6 秒
+ const rotation = Math.random() * 360 - 180 // 减少旋转幅度到 -180~180 度
+ const scale = 0.7 + Math.random() * 0.3 // 随机缩放 0.7-1.0
+
+ result.push({
+ id: props.triggerCount * 100 + i,
+ angle,
+ distance,
+ delay,
+ duration,
+ rotation,
+ scale
+ })
+ }
+
+ return result
+})
+
+// 计算粒子的最终位置
+const getParticlePosition = (angle: number, distance: number) => {
+ const radian = (angle * Math.PI) / 180
+ return {
+ x: Math.cos(radian) * distance,
+ y: Math.sin(radian) * distance
+ }
+}
+</script>
+
+<template>
+ <div class="absolute inset-0 pointer-events-none overflow-visible flex items-center justify-center z-[9999]">
+ <motion.div
+ v-for="particle in particles"
+ :key="particle.id"
+ :initial="{
+ x: 0,
+ y: 0,
+ scale: 0,
+ opacity: 1,
+ rotate: 0
+ }"
+ :animate="{
+ x: getParticlePosition(particle.angle, particle.distance).x,
+ y: getParticlePosition(particle.angle, particle.distance).y,
+ scale: [0, particle.scale * 1.1, particle.scale, 0],
+ opacity: [0, 1, 1, 0],
+ rotate: particle.rotation,
+ transition: {
+ duration: particle.duration,
+ delay: particle.delay,
+ ease: [0.25, 0.46, 0.45, 0.94]
+ }
+ }"
+ class="absolute z-[9999]"
+ style="transform-origin: center"
+ >
+ <Icon
+ :name="iconName"
+ class="text-[24px]"
+ mode="svg"
+ />
+ </motion.div>
+ </div>
+</template>
diff --git a/app/components/photo/ReactionPicker.vue b/app/components/photo/ReactionPicker.vue
index d46da9e7..980adb4c 100644
--- a/app/components/photo/ReactionPicker.vue
+++ b/app/components/photo/ReactionPicker.vue
@@ -16,7 +16,7 @@ interface Props {
const props = defineProps<Props>()
const emit = defineEmits<{
- select: [id: string]
+ select: [id: string, iconName: string]
close: []
}>()
@@ -52,7 +52,10 @@ const formatCount = (count?: number): string => {
}
const handleSelect = (id: string) => {
- emit('select', id)
+ const reaction = reactions.value.find(r => r.id === id)
+ if (reaction) {
+ emit('select', id, reaction.iconName)
+ }
}
</script>
diff --git a/app/components/photo/Viewer.vue b/app/components/photo/Viewer.vue
index 5f60587c..2c2c7e96 100644
--- a/app/components/photo/Viewer.vue
+++ b/app/components/photo/Viewer.vue
@@ -11,6 +11,7 @@ import ProgressiveImage from './ProgressiveImage.vue'
import GalleryThumbnail from './GalleryThumbnail.vue'
import InfoPanel from './InfoPanel.vue'
import ReactionPicker from './ReactionPicker.vue'
+import ReactionConfetti from './ReactionConfetti.vue'
import type { LoadingIndicatorRef } from './LoadingIndicator.vue'
interface Props {
@@ -25,12 +26,12 @@ const emit = defineEmits<{
indexChange: [index: number]
}>()
-// Refs
+const toast = useToast()
+
const containerRef = ref<HTMLDivElement>()
const swiperRef = ref<SwiperType>()
const loadingIndicatorRef = ref<LoadingIndicatorRef>()
-// State
const isImageZoomed = ref(false)
const showExifPanel = ref(false)
const showShareModal = ref(false)
@@ -39,22 +40,23 @@ const zoomLevel = ref(0)
const showZoomLevel = ref(false)
const zoomLevelTimer = ref<NodeJS.Timeout | null>(null)
-// Reaction state
const showReactionPicker = ref(false)
const selectedReaction = ref<string | null>(null)
const reactionCounts = ref<Record<string, number>>({})
const isLoadingReaction = ref(false)
+const confettiIcon = ref<string | null>(null)
+const confettiTriggerCount = ref(0)
// 表态图标映射
const reactionIcons: Record<string, string> = {
- 'like': 'fluent-emoji-flat:thumbs-up',
- 'love': 'fluent-emoji-flat:red-heart',
- 'amazing': 'fluent-emoji-flat:smiling-face-with-heart-eyes',
- 'funny': 'fluent-emoji-flat:face-with-tears-of-joy',
- 'wow': 'fluent-emoji-flat:face-with-open-mouth',
- 'sad': 'fluent-emoji-flat:crying-face',
- 'fire': 'fluent-emoji-flat:fire',
- 'sparkle': 'fluent-emoji-flat:sparkles',
+ like: 'fluent-emoji-flat:thumbs-up',
+ love: 'fluent-emoji-flat:red-heart',
+ amazing: 'fluent-emoji-flat:smiling-face-with-heart-eyes',
+ funny: 'fluent-emoji-flat:face-with-tears-of-joy',
+ wow: 'fluent-emoji-flat:face-with-open-mouth',
+ sad: 'fluent-emoji-flat:crying-face',
+ fire: 'fluent-emoji-flat:fire',
+ sparkle: 'fluent-emoji-flat:sparkles',
}
const currentReactionIcon = computed(() => {
@@ -63,13 +65,16 @@ const currentReactionIcon = computed(() => {
// 计算总表态数
const totalReactions = computed(() => {
- return Object.values(reactionCounts.value).reduce((sum, count) => sum + count, 0)
+ return Object.values(reactionCounts.value).reduce(
+ (sum, count) => sum + count,
+ 0,
+ )
})
// 加载照片表态数据
const loadPhotoReactions = async (photoId: string) => {
try {
- const data = await $fetch(`/api/photos/${photoId}/reactions`) as any
+ const data = (await $fetch(`/api/photos/${photoId}/reactions`)) as any
selectedReaction.value = data.userReaction || null
reactionCounts.value = data.reactions || {}
} catch (error) {
@@ -117,6 +122,8 @@ watch(
// Reset reaction state
showReactionPicker.value = false
selectedReaction.value = null
+ confettiIcon.value = null
+ confettiTriggerCount.value = 0
// Reset LivePhoto state
isLivePhotoHovering.value = false
@@ -394,12 +401,16 @@ const handleLivePhotoVideoEnded = () => {
}
}
+const clearConfetti = useDebounceFn(() => {
+ confettiIcon.value = null
+}, 1600)
+
// Reaction handlers
-const handleReactionSelect = async (reactionId: string) => {
+const handleReactionSelect = async (reactionId: string, iconName: string) => {
if (!currentPhoto.value) return
-
+
isLoadingReaction.value = true
-
+
try {
if (selectedReaction.value === reactionId) {
// 取消表态
@@ -417,30 +428,48 @@ const handleReactionSelect = async (reactionId: string) => {
if (oldReaction && reactionCounts.value[oldReaction] !== undefined) {
reactionCounts.value[oldReaction]--
}
-
+
// 添加或更新表态
await $fetch(`/api/photos/${currentPhoto.value.id}/reactions`, {
method: 'POST',
body: { reactionType: reactionId },
})
-
+
selectedReaction.value = reactionId
// 增加计数
- reactionCounts.value[reactionId] = (reactionCounts.value[reactionId] || 0) + 1
+ reactionCounts.value[reactionId] =
+ (reactionCounts.value[reactionId] || 0) + 1
+
+ // 触发礼花效果
+ confettiIcon.value = iconName
+ confettiTriggerCount.value++
+
+ // 在动画完成后清除 confetti
+ clearConfetti()
}
} catch (error: any) {
console.error('Failed to update reaction:', error)
-
+
// 显示错误提示
if (error?.statusCode === 429) {
- alert('操作过于频繁,请稍后再试')
+ toast.add({
+ icon: 'tabler:alert-circle',
+ title: '表态失败',
+ description: '操作过于频繁,请稍后再试',
+ color: 'warning',
+ })
} else {
- alert('表态失败,请稍后重试')
+ toast.add({
+ icon: 'tabler:alert-circle',
+ title: '表态失败',
+ description: error instanceof Error ? error.message : '未知错误',
+ color: 'warning',
+ })
}
} finally {
isLoadingReaction.value = false
}
-
+
showReactionPicker.value = false
}
@@ -456,7 +485,7 @@ watch(
loadPhotoReactions(newPhotoId)
}
},
- { immediate: true }
+ { immediate: true },
)
defineShortcuts({
@@ -782,11 +811,11 @@ const swiperModules = [Navigation, Keyboard, Virtual]
:initial="{ opacity: 0, scale: 0.8, y: 20 }"
:animate="{ opacity: 1, scale: 1, y: 0 }"
:exit="{ opacity: 0, scale: 0.8, y: 20 }"
- :transition="{
- type: 'spring',
- stiffness: 300,
+ :transition="{
+ type: 'spring',
+ stiffness: 300,
damping: 20,
- delay: 0.1
+ delay: 0.1,
}"
class="absolute bottom-4 right-4 z-20"
>
@@ -800,50 +829,74 @@ const swiperModules = [Navigation, Keyboard, Virtual]
@close="showReactionPicker = false"
/>
+ <!-- 礼花效果 -->
+ <ReactionConfetti
+ v-if="confettiIcon"
+ :icon-name="confettiIcon"
+ :trigger-count="confettiTriggerCount"
+ />
+
<!-- 表态按钮 -->
<motion.button
type="button"
:initial="{ scale: 0.8, opacity: 0 }"
- :animate="{
- scale: showReactionPicker ? 0.92 : 1,
+ :animate="{
+ scale: showReactionPicker ? 0.92 : 1,
opacity: 1,
- transition: showReactionPicker
+ transition: showReactionPicker
? { duration: 0.2, ease: [0.25, 0.1, 0.25, 1] }
- : { type: 'spring', stiffness: 300, damping: 25, mass: 0.8 }
+ : {
+ type: 'spring',
+ stiffness: 300,
+ damping: 25,
+ mass: 0.8,
+ },
+ }"
+ :while-hover="{
+ scale: showReactionPicker ? 0.95 : 1.05,
}"
- :while-hover="{ scale: showReactionPicker ? 0.95 : 1.05 }"
:while-tap="{ scale: 0.88 }"
:class="[
'pointer-events-auto flex items-center justify-center gap-2',
'px-4 h-11 rounded-full',
'backdrop-blur-xl border shadow-lg',
'transition-all duration-200',
- selectedReaction
- ? 'bg-blue-500/90 border-blue-400/50 text-white shadow-blue-500/30'
+ selectedReaction
+ ? 'bg-blue-500/90 border-blue-400/50 text-white shadow-blue-500/30'
: 'bg-white/90 dark:bg-neutral-800/90 border-neutral-200/50 dark:border-white/10 text-neutral-700 dark:text-white/80 shadow-black/10 dark:shadow-black/30',
- 'hover:shadow-xl'
+ 'hover:shadow-xl',
]"
@click="toggleReactionPicker"
>
- <Icon
- v-if="selectedReaction && currentReactionIcon"
+ <Icon
+ v-if="selectedReaction && currentReactionIcon"
:name="currentReactionIcon"
class="text-xl leading-none select-none"
/>
- <Icon
+ <Icon
v-else
name="tabler:mood-smile"
class="text-xl"
/>
<div class="flex flex-col items-start gap-0.5">
<span class="text-sm font-medium leading-none">
- {{ selectedReaction ? $t('viewer.reaction.change') : $t('viewer.reaction.add') }}
+ {{
+ selectedReaction
+ ? $t('viewer.reaction.change')
+ : $t('viewer.reaction.add')
+ }}
</span>
- <span
+ <span
v-if="totalReactions > 0"
class="text-[10px] leading-none opacity-70"
>
- {{ $t('viewer.reaction.count', { count: totalReactions }, totalReactions) }}
+ {{
+ $t(
+ 'viewer.reaction.count',
+ { count: totalReactions },
+ totalReactions,
+ )
+ }}
</span>
</div>
</motion.button>