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(share): add photo sharing functionality with social media integration and share modal

HoshinoSuzumi4699fd384cb7
diff --git a/app/components/photo/ShareModal.vue b/app/components/photo/ShareModal.vue
new file mode 100644
index 00000000..817b8c77
--- /dev/null
+++ b/app/components/photo/ShareModal.vue
@@ -0,0 +1,299 @@
+<script lang="ts" setup>
+import { motion, AnimatePresence } from 'motion-v'
+
+interface Props {
+ isOpen: boolean
+ photo: Photo
+}
+
+const props = defineProps<Props>()
+const emit = defineEmits<{
+ close: []
+}>()
+
+const toast = useToast()
+
+const shareUrl = computed(() => {
+ if (typeof window !== 'undefined') {
+ return `${window.location.origin}/${props.photo.id}`
+ }
+ return ''
+})
+
+const shareText = computed(() => {
+ const title = props.photo.title || $t('ui.action.share.fallback.photoTitle')
+ const description = props.photo.description || ''
+ return `${$t('ui.action.share.text.prefix')} ${title}${description ? ' - ' + description : ''}`
+})
+
+const shareTextAndUrl = computed(() => {
+ return `${shareText.value}\n${shareUrl.value}`
+})
+
+// Social media share functions
+const shareToTwitter = () => {
+ const text = encodeURIComponent(shareText.value)
+ const url = encodeURIComponent(shareUrl.value)
+ window.open(
+ `https://twitter.com/intent/tweet?text=${text}&url=${url}`,
+ '_blank',
+ )
+}
+
+const shareToTelegram = () => {
+ window.open(
+ `https://t.me/share/url?url=${encodeURIComponent(shareUrl.value)}&text=${encodeURIComponent(shareText.value)}`,
+ '_blank',
+ )
+}
+
+const shareToWeibo = () => {
+ const text = encodeURIComponent(shareText.value)
+ const url = encodeURIComponent(shareUrl.value)
+ window.open(
+ `https://service.weibo.com/share/share.php?url=${url}&title=${text}`,
+ '_blank',
+ )
+}
+
+const shareToFacebook = () => {
+ const url = encodeURIComponent(shareUrl.value)
+ window.open(`https://www.facebook.com/sharer/sharer.php?u=${url}`, '_blank')
+}
+
+const shareToWhatsApp = () => {
+ const text = encodeURIComponent(`${shareText.value}\n${shareUrl.value}`)
+ window.open(`https://wa.me/?text=${text}`, '_blank')
+}
+
+const shareToLinkedIn = () => {
+ const url = encodeURIComponent(shareUrl.value)
+ const title = encodeURIComponent(shareText.value)
+ window.open(
+ `https://www.linkedin.com/sharing/share-offsite/?url=${url}&title=${title}`,
+ '_blank',
+ )
+}
+
+// Copy functions
+const copyLink = async () => {
+ try {
+ await navigator.clipboard.writeText(shareTextAndUrl.value)
+ toast.add({
+ title: $t('ui.action.share.success.linkCopied'),
+ color: 'success',
+ icon: 'tabler:check',
+ duration: 3000,
+ })
+ } catch (error) {
+ toast.add({
+ title: $t('ui.action.share.error.linkCopyFailed'),
+ description: (error as Error)?.message || 'Unknown error',
+ color: 'error',
+ icon: 'tabler:x',
+ duration: 3000,
+ })
+ }
+}
+
+// Native share (for mobile devices)
+const nativeShare = async () => {
+ if (navigator.share) {
+ try {
+ await navigator.share({
+ title: shareText.value,
+ url: shareUrl.value,
+ })
+ } catch (error) {
+ console.error($t('ui.action.share.error.nativeShareFailed'), error)
+ }
+ }
+}
+
+// Check if native share is available
+const canNativeShare = computed(() => {
+ return typeof window !== 'undefined' && navigator.share
+})
+
+// Social media platforms data
+const socialPlatforms = computed(() => [
+ {
+ name: $t('ui.action.share.platforms.twitter'),
+ icon: 'tabler:brand-twitter',
+ color: 'text-blue-500',
+ action: shareToTwitter,
+ },
+ {
+ name: $t('ui.action.share.platforms.telegram'),
+ icon: 'tabler:brand-telegram',
+ color: 'text-blue-400',
+ action: shareToTelegram,
+ },
+ {
+ name: $t('ui.action.share.platforms.weibo'),
+ icon: 'tabler:brand-weibo',
+ color: 'text-red-500',
+ action: shareToWeibo,
+ },
+ {
+ name: $t('ui.action.share.platforms.facebook'),
+ icon: 'tabler:brand-facebook',
+ color: 'text-blue-600',
+ action: shareToFacebook,
+ },
+ {
+ name: $t('ui.action.share.platforms.whatsapp'),
+ icon: 'tabler:brand-whatsapp',
+ color: 'text-green-500',
+ action: shareToWhatsApp,
+ },
+ {
+ name: $t('ui.action.share.platforms.linkedin'),
+ icon: 'tabler:brand-linkedin',
+ color: 'text-blue-700',
+ action: shareToLinkedIn,
+ },
+])
+
+// Close modal when clicking outside
+const handleBackdropClick = (event: MouseEvent) => {
+ if (event.target === event.currentTarget) {
+ emit('close')
+ }
+}
+
+// Keyboard shortcuts
+defineShortcuts({
+ escape: () => {
+ emit('close')
+ },
+})
+</script>
+
+<template>
+ <Teleport to="body">
+ <AnimatePresence>
+ <motion.div
+ v-if="isOpen"
+ :initial="{ opacity: 0 }"
+ :animate="{ opacity: 1 }"
+ :exit="{ opacity: 0 }"
+ :transition="{ duration: 0.2 }"
+ class="fixed inset-0 z-[60] flex items-center justify-center bg-black/50 backdrop-blur-sm"
+ @click="handleBackdropClick"
+ >
+ <motion.div
+ :initial="{ opacity: 0, scale: 0.95, y: 20 }"
+ :animate="{ opacity: 1, scale: 1, y: 0 }"
+ :exit="{ opacity: 0, scale: 0.95, y: 20 }"
+ :transition="{
+ type: 'spring',
+ duration: 0.3,
+ bounce: 0.1,
+ }"
+ class="relative mx-4 w-full max-w-md overflow-hidden rounded-2xl border border-white/10 bg-white/90 shadow-2xl backdrop-blur-2xl dark:bg-neutral-900/90"
+ @click.stop
+ >
+ <!-- Header -->
+ <div
+ class="flex items-center justify-between border-b border-white/10 p-4"
+ >
+ <div class="flex items-center gap-2">
+ <Icon
+ name="tabler:share-3"
+ class="size-5 text-neutral-700 dark:text-neutral-300"
+ />
+ <h3
+ class="text-lg font-semibold text-neutral-900 dark:text-white"
+ >
+ {{ $t('ui.action.share.title') }}
+ </h3>
+ </div>
+ <UButton
+ size="sm"
+ variant="ghost"
+ color="neutral"
+ icon="tabler:x"
+ @click="emit('close')"
+ />
+ </div>
+
+ <!-- Content -->
+ <div
+ v-if="photo"
+ class="p-4"
+ >
+ <!-- Native Share (Mobile) -->
+ <div
+ v-if="canNativeShare"
+ class="mb-4"
+ >
+ <UButton
+ block
+ size="lg"
+ color="info"
+ variant="soft"
+ icon="tabler:share-2"
+ @click="nativeShare"
+ >
+ {{ $t('ui.action.share.actions.nativeShare') }}
+ </UButton>
+ </div>
+
+ <div class="space-y-4">
+ <!-- Share URL Display -->
+ <div
+ class="rounded-lg border border-neutral-200/50 bg-neutral-50/50 p-3 dark:border-neutral-700/50 dark:bg-neutral-800/50"
+ >
+ <label
+ class="mb-1 block text-xs font-medium text-neutral-600 dark:text-neutral-400"
+ >
+ {{ $t('ui.action.share.actions.shareUrl') }}
+ </label>
+ <div class="flex items-center gap-2">
+ <input
+ :value="shareUrl"
+ readonly
+ class="flex-1 truncate bg-transparent text-sm text-neutral-800 dark:text-neutral-200 resize-none"
+ />
+ <UButton
+ size="xs"
+ variant="ghost"
+ color="neutral"
+ icon="tabler:copy"
+ @click="copyLink"
+ />
+ </div>
+ </div>
+ <!-- Social Platforms Grid -->
+ <div class="grid grid-cols-3 gap-3">
+ <button
+ v-for="platform in socialPlatforms"
+ :key="platform.name"
+ type="button"
+ class="flex flex-col items-center justify-center gap-2 rounded-xl border border-neutral-200/50 bg-white/50 p-4 transition-all hover:scale-105 hover:border-neutral-300/50 hover:bg-white/70 dark:border-neutral-700/50 dark:bg-neutral-800/50 dark:hover:border-neutral-600/50 dark:hover:bg-neutral-700/50"
+ @click="platform.action"
+ >
+ <Icon
+ :name="platform.icon"
+ class="size-6"
+ :class="platform.color"
+ />
+ <span
+ class="text-xs font-medium text-neutral-700 dark:text-neutral-300"
+ >
+ {{ platform.name }}
+ </span>
+ </button>
+ </div>
+ </div>
+ </div>
+ </motion.div>
+ </motion.div>
+ </AnimatePresence>
+ </Teleport>
+</template>
+
+<style scoped>
+/* 确保模态框在最顶层 */
+</style>
diff --git a/app/components/photo/Viewer.vue b/app/components/photo/Viewer.vue
index 53f744ce..c778a9cb 100644
--- a/app/components/photo/Viewer.vue
+++ b/app/components/photo/Viewer.vue
@@ -32,6 +32,7 @@ const loadingIndicatorRef = ref<LoadingIndicatorRef>()
// State
const isImageZoomed = ref(false)
const showExifPanel = ref(false)
+const showShareModal = ref(false)
const currentBlobSrc = ref<string | null>(null)
const zoomLevel = ref(0)
const showZoomLevel = ref(false)
@@ -69,6 +70,7 @@ watch(
if (!isOpen) {
isImageZoomed.value = false
showExifPanel.value = false
+ showShareModal.value = false
currentBlobSrc.value = null
zoomLevel.value = 0
showZoomLevel.value = false
@@ -473,12 +475,24 @@ const swiperModules = [Navigation, Keyboard, Virtual]
<GlassButton
v-if="isMobile"
icon="tabler:info-circle"
- :class="!showExifPanel ? '' : 'bg-black/20 hover:bg-black/30 text-white'"
+ :class="
+ !showExifPanel
+ ? ''
+ : 'bg-black/20 hover:bg-black/30 text-white'
+ "
size="sm"
rounded
@click="showExifPanel = !showExifPanel"
/>
+ <!-- 分享按钮 -->
+ <GlassButton
+ icon="tabler:share-3"
+ size="sm"
+ rounded
+ @click="showShareModal = true"
+ />
+
<!-- 关闭按钮 -->
<GlassButton
icon="tabler:x"
@@ -705,6 +719,14 @@ const swiperModules = [Navigation, Keyboard, Virtual]
</div>
</motion.div>
</AnimatePresence>
+
+ <!-- Share Modal -->
+ <PhotoShareModal
+ v-if="currentPhoto"
+ :is-open="showShareModal"
+ :photo="currentPhoto"
+ @close="showShareModal = false"
+ />
</Teleport>
</template>
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index 2671978a..67e3e38c 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -49,6 +49,45 @@
},
"globe": {
"tooltip": "Globe"
+ },
+ "share": {
+ "tooltip": "Share Photo",
+ "title": "Share Photo",
+ "tabs": {
+ "social": "Social Share",
+ "advanced": "Advanced Share"
+ },
+ "platforms": {
+ "twitter": "Twitter",
+ "telegram": "Telegram",
+ "weibo": "Weibo",
+ "facebook": "Facebook",
+ "whatsapp": "WhatsApp",
+ "linkedin": "LinkedIn"
+ },
+ "actions": {
+ "nativeShare": "Use System Share",
+ "copyLink": "Copy Link",
+ "copyImage": "Copy Image",
+ "downloadImage": "Download Original",
+ "generateShareImage": "Generate Share Image",
+ "shareUrl": "Share URL"
+ },
+ "success": {
+ "linkCopied": "Link copied to clipboard",
+ "imageCopied": "Image copied to clipboard"
+ },
+ "error": {
+ "copyNotSupported": "Copy not supported in this browser",
+ "shareFailed": "Share failed",
+ "nativeShareFailed": "Native share failed"
+ },
+ "fallback": {
+ "photoTitle": "Beautiful Photo"
+ },
+ "text": {
+ "prefix": "Check out this photo:"
+ }
}
},
"stats": {
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index c9c38323..0ebdc7d7 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -49,6 +49,45 @@
},
"globe": {
"tooltip": "グローブ"
+ },
+ "share": {
+ "tooltip": "写真を共有",
+ "title": "写真を共有",
+ "tabs": {
+ "social": "ソーシャル共有",
+ "advanced": "高度な共有"
+ },
+ "platforms": {
+ "twitter": "Twitter",
+ "telegram": "Telegram",
+ "weibo": "Weibo",
+ "facebook": "Facebook",
+ "whatsapp": "WhatsApp",
+ "linkedin": "LinkedIn"
+ },
+ "actions": {
+ "nativeShare": "システム共有を使用",
+ "copyLink": "リンクをコピー",
+ "copyImage": "画像をコピー",
+ "downloadImage": "オリジナルをダウンロード",
+ "generateShareImage": "共有画像を生成",
+ "shareUrl": "共有URL"
+ },
+ "success": {
+ "linkCopied": "リンクをクリップボードにコピーしました",
+ "imageCopied": "画像をクリップボードにコピーしました"
+ },
+ "error": {
+ "copyNotSupported": "このブラウザではコピー機能がサポートされていません",
+ "shareFailed": "共有に失敗しました",
+ "nativeShareFailed": "ネイティブ共有に失敗しました"
+ },
+ "fallback": {
+ "photoTitle": "美しい写真"
+ },
+ "text": {
+ "prefix": "この写真をご覧ください:"
+ }
}
},
"stats": {
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index a664c5d1..94dcf450 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -53,6 +53,45 @@
},
"globe": {
"tooltip": "地球仪"
+ },
+ "share": {
+ "tooltip": "分享照片",
+ "title": "分享照片",
+ "tabs": {
+ "social": "社交分享",
+ "advanced": "高级分享"
+ },
+ "platforms": {
+ "twitter": "Twitter",
+ "telegram": "Telegram",
+ "weibo": "微博",
+ "facebook": "Facebook",
+ "whatsapp": "WhatsApp",
+ "linkedin": "LinkedIn"
+ },
+ "actions": {
+ "nativeShare": "使用系统分享",
+ "copyLink": "复制链接",
+ "copyImage": "复制图片",
+ "downloadImage": "下载原图",
+ "generateShareImage": "生成分享图片",
+ "shareUrl": "分享链接"
+ },
+ "success": {
+ "linkCopied": "链接已复制到剪贴板",
+ "imageCopied": "图片已复制到剪贴板"
+ },
+ "error": {
+ "copyNotSupported": "当前浏览器不支持复制功能",
+ "shareFailed": "分享失败",
+ "nativeShareFailed": "原生分享失败"
+ },
+ "fallback": {
+ "photoTitle": "美丽的照片"
+ },
+ "text": {
+ "prefix": "来看看这张照片:"
+ }
}
},
"stats": {
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index da9454fb..c316137d 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -53,6 +53,45 @@
},
"globe": {
"tooltip": "地球儀"
+ },
+ "share": {
+ "tooltip": "分享相片",
+ "title": "分享相片",
+ "tabs": {
+ "social": "社交分享",
+ "advanced": "進階分享"
+ },
+ "platforms": {
+ "twitter": "Twitter",
+ "telegram": "Telegram",
+ "weibo": "微博",
+ "facebook": "Facebook",
+ "whatsapp": "WhatsApp",
+ "linkedin": "LinkedIn"
+ },
+ "actions": {
+ "nativeShare": "使用系統分享",
+ "copyLink": "複製連結",
+ "copyImage": "複製圖片",
+ "downloadImage": "下載原圖",
+ "generateShareImage": "產生分享圖片",
+ "shareUrl": "分享連結"
+ },
+ "success": {
+ "linkCopied": "連結已複製到剪貼簿",
+ "imageCopied": "圖片已複製到剪貼簿"
+ },
+ "error": {
+ "copyNotSupported": "目前瀏覽器不支援複製功能",
+ "shareFailed": "分享失敗",
+ "nativeShareFailed": "原生分享失敗"
+ },
+ "fallback": {
+ "photoTitle": "美麗的相片"
+ },
+ "text": {
+ "prefix": "來看看這張相片:"
+ }
}
},
"stats": {
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index d475c33d..e5b65ab9 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -53,6 +53,45 @@
},
"globe": {
"tooltip": "地球儀"
+ },
+ "share": {
+ "tooltip": "分享相片",
+ "title": "分享相片",
+ "tabs": {
+ "social": "社群分享",
+ "advanced": "進階分享"
+ },
+ "platforms": {
+ "twitter": "Twitter",
+ "telegram": "Telegram",
+ "weibo": "微博",
+ "facebook": "Facebook",
+ "whatsapp": "WhatsApp",
+ "linkedin": "LinkedIn"
+ },
+ "actions": {
+ "nativeShare": "使用系統分享",
+ "copyLink": "複製連結",
+ "copyImage": "複製圖片",
+ "downloadImage": "下載原圖",
+ "generateShareImage": "產生分享圖片",
+ "shareUrl": "分享連結"
+ },
+ "success": {
+ "linkCopied": "連結已複製到剪貼簿",
+ "imageCopied": "圖片已複製到剪貼簿"
+ },
+ "error": {
+ "copyNotSupported": "目前瀏覽器不支援複製功能",
+ "shareFailed": "分享失敗",
+ "nativeShareFailed": "原生分享失敗"
+ },
+ "fallback": {
+ "photoTitle": "美麗的相片"
+ },
+ "text": {
+ "prefix": "來看看這張相片:"
+ }
}
},
"stats": {