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: 完成首页、加载页、仪表盘,重构 HeaderItem,优化照片库样式

HoshinoSuzumiceabb6e6846e
diff --git a/.gitignore b/.gitignore
index d07fa4cd..d7ba1c57 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,9 @@
.cache
dist
+# Date
+data
+
# Wrangler
.wrangler
diff --git a/app/app.vue b/app/app.vue
index fae9193c..117a8d1c 100644
--- a/app/app.vue
+++ b/app/app.vue
@@ -1,3 +1,6 @@
+<script setup lang="ts">
+</script>
+
<template>
<UApp>
<NuxtLayout>
@@ -6,4 +9,5 @@
</UApp>
</template>
-<style></style>
+<style>
+</style>
diff --git a/app/assets/images/avatar.webp b/app/assets/images/avatar.webp
new file mode 100644
index 00000000..1e65fa7e
Binary files /dev/null and b/app/assets/images/avatar.webp differ
diff --git a/app/components/loader/Avatar.vue b/app/components/loader/Avatar.vue
new file mode 100644
index 00000000..50ac496e
--- /dev/null
+++ b/app/components/loader/Avatar.vue
@@ -0,0 +1,32 @@
+<script lang="ts" setup></script>
+
+<template>
+ <div class="relative size-20">
+ <div
+ class="absolute inset-0 rounded-full border-3 border-transparent border-x-primary border-y-secondary animate-spin"
+ ></div>
+
+ <div class="absolute inset-1 rounded-full overflow-hidden">
+ <img
+ class="w-full h-full object-cover"
+ src="~/assets/images/avatar.webp"
+ alt="Loading..."
+ />
+ </div>
+ </div>
+</template>
+
+<style scoped>
+@keyframes spin {
+ from {
+ transform: rotate(0deg);
+ }
+ to {
+ transform: rotate(360deg);
+ }
+}
+
+.animate-spin {
+ animation: spin 0.8s linear infinite;
+}
+</style>
diff --git a/app/components/masonry/HeaderItem.vue b/app/components/masonry/HeaderItem.vue
index 0be2cd05..af2d3867 100644
--- a/app/components/masonry/HeaderItem.vue
+++ b/app/components/masonry/HeaderItem.vue
@@ -1,10 +1,9 @@
<script lang="ts" setup>
+import avatarImage from '~/assets/images/avatar.webp'
+
defineProps<{
stats?: {
total: number
- withDates: number
- withTitles: number
- withExif: number
dateRange: {
start: Date | undefined
end: Date | undefined
@@ -12,59 +11,69 @@ defineProps<{
}
dateRangeText?: string
}>()
+
+const handleOpenLogin = () => {
+ window.location.href = '/api/auth/github'
+ console.log('Login button clicked')
+}
</script>
<template>
- <div
- class="inline-block w-full align-top break-inside-avoid mb-4 select-auto"
- >
- <div class="text-center py-8">
- <h1 class="text-4xl font-bold text-gray-900 dark:text-white mb-2">
- Photo Gallery
- </h1>
- <div class="text-gray-600 dark:text-gray-400 space-y-1">
- <p class="text-lg">{{ stats?.total }} 张照片</p>
- <div class="text-sm space-y-1">
- <p v-if="dateRangeText">时间跨度: {{ dateRangeText }}</p>
- <p>
- {{ stats?.withDates }} 张包含拍摄时间 ·
- {{ stats?.withExif }} 张包含 EXIF 数据
- </p>
- </div>
- </div>
+ <div class="inline-block w-full align-top break-inside-avoid mb-4">
+ <div class="flex flex-col items-center p-4 pb-2 gap-2">
<AuthState>
<template #default="{ loggedIn, user, clear }">
- <div
- v-if="loggedIn"
- class="text-gray-600 dark:text-gray-400 flex flex-col items-center"
- >
- Logged in as {{ user?.username || user?.email }}
- <div class="gap-3">
- <NuxtLink
+ <div class="flex flex-col items-center gap-2">
+ <div class="relative mx-auto">
+ <div
+ v-if="loggedIn"
+ class="absolute -bottom-0.5 -right-0.5 bg-amber-500 text-white rounded-full flex items-center justify-center size-5 text-xs drop-shadow-lg drop-shadow-amber-500/30"
+ >
+ <Icon name="tabler:star-filled" />
+ </div>
+ <img
+ :src="avatarImage"
+ class="size-12 rounded-full object-cover"
+ :class="!loggedIn && 'cursor-pointer'"
+ alt="Timothy's Avatar"
+ @click="!loggedIn && handleOpenLogin()"
+ />
+ </div>
+ <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-2">
+ TimoYin's mems
+ </h1>
+ </div>
+ <div class="text-gray-600 dark:text-gray-400 space-y-1 text-center">
+ <p class="text-xs font-medium">
+ <span v-if="dateRangeText">{{ dateRangeText }}, 共</span>
+ {{ stats?.total }} 张照片
+ </p>
+ <p class="font-[Pacifico]">Mems rest within the lens.</p>
+ </div>
+ <div class="text-center">
+ <div class="flex items-center gap-2">
+ <UButton
+ v-if="loggedIn"
+ size="sm"
+ color="info"
+ variant="soft"
+ icon="tabler:dashboard"
to="/dashboard"
- class="ml-2 text-blue-500"
>
- Dashboard
- </NuxtLink>
- <button
+ 仪表盘
+ </UButton>
+ <UButton
+ v-if="loggedIn"
+ size="sm"
+ color="error"
+ variant="soft"
+ icon="tabler:logout"
@click="clear"
- class="ml-2 text-blue-500"
>
- Logout
- </button>
+ 登出
+ </UButton>
</div>
</div>
- <div v-else>
- <a
- href="/api/auth/github"
- class="text-blue-500"
- >
- Login
- </a>
- </div>
- </template>
- <template #placeholder>
- <button disabled>Loading...</button>
</template>
</AuthState>
</div>
diff --git a/app/components/masonry/PhotoItem.client.vue b/app/components/masonry/PhotoItem.client.vue
index 92fd62d1..77dd4afc 100644
--- a/app/components/masonry/PhotoItem.client.vue
+++ b/app/components/masonry/PhotoItem.client.vue
@@ -14,7 +14,6 @@ const emit = defineEmits<{
// Constants
const ITEM_GAP = 4
-const DEFAULT_WIDTH = 280
// Reactive state
const isLoading = ref(true)
@@ -22,13 +21,17 @@ const actualHeight = ref(0)
const photoRef = ref<HTMLElement>()
const mainImageRef = ref<HTMLImageElement>()
const isVisible = ref(false)
+const containerWidth = ref(0)
// Computed
const containerHeight = computed(() => {
+ // Get the actual container width to calculate proper aspect ratio
+ const currentWidth = containerWidth.value || 280
+
// Use actual dimensions from photo data if available
if (props.photo.width && props.photo.height) {
const aspectRatio = props.photo.height / props.photo.width
- return Math.round(DEFAULT_WIDTH * aspectRatio)
+ return Math.round(currentWidth * aspectRatio)
}
// Fallback to calculated height if image has loaded
@@ -36,8 +39,8 @@ const containerHeight = computed(() => {
return actualHeight.value
}
- // Default fallback height
- return 280
+ // Default fallback height based on current width
+ return Math.round(currentWidth * 1.2) // 1.2 is a reasonable default aspect ratio
})
// Methods
@@ -48,7 +51,8 @@ const handleImageLoad = (event: Event) => {
// Update actual height based on loaded image dimensions
if (img.naturalWidth && img.naturalHeight) {
const aspectRatio = img.naturalHeight / img.naturalWidth
- actualHeight.value = Math.round(DEFAULT_WIDTH * aspectRatio)
+ const currentWidth = containerWidth.value || 280
+ actualHeight.value = Math.round(currentWidth * aspectRatio)
}
}
@@ -127,14 +131,35 @@ const formatExposureTime = (
// Preload image on mount to get dimensions
onMounted(() => {
+ // Get container width
+ nextTick(() => {
+ if (photoRef.value) {
+ containerWidth.value = photoRef.value.offsetWidth
+
+ // Set up resize observer to track width changes
+ const resizeObserver = new ResizeObserver(() => {
+ if (photoRef.value) {
+ containerWidth.value = photoRef.value.offsetWidth
+ }
+ })
+
+ resizeObserver.observe(photoRef.value)
+
+ onUnmounted(() => {
+ resizeObserver.disconnect()
+ })
+ }
+ })
+
// Preload thumbnail image
if (props.photo.thumbnailUrl) {
const img = new Image()
img.onload = () => {
if (img.naturalWidth && img.naturalHeight) {
const aspectRatio = img.naturalHeight / img.naturalWidth
+ const currentWidth = containerWidth.value || 280
actualHeight.value = Math.round(
- DEFAULT_WIDTH * (props.photo.aspectRatio || aspectRatio),
+ currentWidth * (props.photo.aspectRatio || aspectRatio),
)
}
// Update loading state after preload completes
@@ -192,7 +217,7 @@ onMounted(() => {
<template>
<div
ref="photoRef"
- class="inline-block w-full align-top break-inside-avoid transition-all duration-300 cursor-pointer"
+ class="inline-block w-full align-top break-inside-avoid transition-all duration-300 cursor-pointer select-none"
:style="{
marginBottom: `${ITEM_GAP}px`,
}"
@@ -200,12 +225,12 @@ onMounted(() => {
>
<div
class="relative group overflow-hidden transition-all duration-300"
- :style="{ height: `${containerHeight}px` }"
>
<!-- Thumbhash 组件占位符 -->
<div
v-if="isLoading && photo.thumbnailHash"
- class="w-full h-full absolute inset-0"
+ class="w-full absolute inset-0"
+ :style="{ aspectRatio: `${photo.width || 1} / ${photo.height || 1}` }"
>
<Thumbhash
:thumbhash="photo.thumbnailHash"
@@ -217,7 +242,8 @@ onMounted(() => {
<!-- Loading placeholder (fallback when no thumbhash) -->
<div
v-if="isLoading && !photo.thumbnailHash"
- class="w-full h-full bg-gray-200 dark:bg-gray-700 animate-pulse absolute inset-0"
+ class="w-full bg-gray-200 dark:bg-gray-700 animate-pulse"
+ :style="{ aspectRatio: `${photo.width || 1} / ${photo.height || 1.2}` }"
/>
<!-- Main image -->
@@ -226,7 +252,7 @@ onMounted(() => {
v-show="!isLoading"
:src="photo.thumbnailUrl || ''"
:alt="photo.title || photo.description || 'Photo'"
- class="w-full h-auto object-cover transition-transform duration-300 group-hover:scale-105"
+ class="w-full h-auto object-cover transition-transform duration-300 group-hover:scale-105 block"
@load="handleImageLoad"
@error="handleImageError"
loading="lazy"
@@ -264,14 +290,14 @@ onMounted(() => {
</div>
<div
v-if="photo.tags?.length"
- class="opacity-80 mt-1 flex items-center gap-1"
+ class="mt-1 flex items-center gap-1"
>
<UBadge
v-for="tag in photo.tags"
:key="tag"
size="sm"
color="neutral"
- class="bg-white/20 backdrop-blur-3xl"
+ class="bg-white/20 text-white/80 backdrop-blur-3xl"
>
{{ tag }}
</UBadge>
diff --git a/app/components/masonry/Root.vue b/app/components/masonry/Root.vue
index 40b17cd4..64be67ba 100644
--- a/app/components/masonry/Root.vue
+++ b/app/components/masonry/Root.vue
@@ -12,6 +12,7 @@ const props = withDefaults(defineProps<Props>(), {
const FIRST_SCREEN_ITEMS_COUNT = 30
const COLUMN_GAP = 4
const AUTO_COLUMN_WIDTH = 280
+const MIN_COLUMN_COUNT = 2
// Reactive state
const masonryContainer = ref<HTMLElement>()
@@ -22,15 +23,12 @@ const dateRange = ref<string>()
const visiblePhotos = ref(new Set<number>())
// Composables
-const isMobile = computed(() => {
- if (typeof window === 'undefined') return false
- return window.innerWidth < 768
-})
+const isMobile = useMediaQuery('(max-width: 768px)')
// Computed
const columnCount = computed(() => {
if (props.columns === 'auto') {
- if (!containerWidth.value) return 1
+ if (!containerWidth.value) return MIN_COLUMN_COUNT
const availableWidth = containerWidth.value - (isMobile.value ? 16 : 32)
const maxColumns = isMobile.value ? 2 : 6
@@ -38,24 +36,24 @@ const columnCount = computed(() => {
(availableWidth + COLUMN_GAP) / (AUTO_COLUMN_WIDTH + COLUMN_GAP),
)
- return Math.min(Math.max(calculatedColumns, 1), maxColumns)
+ return Math.min(Math.max(calculatedColumns, MIN_COLUMN_COUNT), maxColumns)
}
return props.columns
})
const photoStats = computed(() => {
- const totalPhotos = props.photos.length
- const photosWithDates = props.photos.filter((p) => p.dateTaken).length
- const photosWithTitles = props.photos.filter((p) => p.title).length
- const photosWithExif = props.photos.filter((p) => p.exif).length
+ const totalPhotos = props.photos?.length || 0
+ const photosWithDates = props.photos?.filter((p) => p.dateTaken).length || 0
+ const photosWithTitles = props.photos?.filter((p) => p.title).length || 0
+ const photosWithExif = props.photos?.filter((p) => p.exif).length || 0
// Get date range of all photos
const allDates = props.photos
- .map((p) => p.dateTaken)
+ ?.map((p) => p?.dateTaken)
.filter((date): date is string => Boolean(date))
.map((date) => new Date(date))
- .sort((a, b) => a.getTime() - b.getTime())
+ .sort((a, b) => a.getTime() - b.getTime()) || []
const dateRange =
allDates.length > 0
@@ -210,10 +208,21 @@ const isViewerOpen = ref(false)
:is-mobile="isMobile"
/>
+ <!-- 移动端时 HeaderItem 显示在瀑布流容器外 -->
+ <div
+ v-if="isMobile"
+ class="px-4 py-2"
+ >
+ <MasonryHeaderItem
+ :stats="photoStats"
+ :date-range-text
+ />
+ </div>
+
<!-- Masonry Container -->
<div
- class="p-1 lg:px-0 lg:pb-0"
- :style="{ userSelect: 'none' }"
+ class="lg:px-0 lg:pb-0"
+ :class="isMobile ? 'px-1 pb-1' : 'p-1'"
>
<!-- Masonry Grid -->
<div
@@ -224,7 +233,9 @@ const isViewerOpen = ref(false)
columnGap: `${COLUMN_GAP}px`,
}"
>
+ <!-- 非移动端时 HeaderItem 显示在瀑布流内 -->
<MasonryHeaderItem
+ v-if="!isMobile"
:stats="photoStats"
:date-range-text
/>
@@ -238,10 +249,12 @@ const isViewerOpen = ref(false)
:hasAnimated
:first-screen-items="FIRST_SCREEN_ITEMS_COUNT"
@visibility-change="handleVisibilityChange"
- @open-viewer="idx => {
- viewerIndex = idx
- isViewerOpen = true
- }"
+ @open-viewer="
+ (idx) => {
+ viewerIndex = idx
+ isViewerOpen = true
+ }
+ "
/>
</div>
</div>
diff --git a/app/components/photo/InfoPanel.vue b/app/components/photo/InfoPanel.vue
index 9a4a6caf..ffcaf4be 100644
--- a/app/components/photo/InfoPanel.vue
+++ b/app/components/photo/InfoPanel.vue
@@ -2,7 +2,6 @@
import { ref, computed } from 'vue'
import { motion, AnimatePresence } from 'motion-v'
import type { NeededExif } from '../../../shared/types/photo'
-import { useMediaQuery } from '~/composables/useMediaQuery'
interface Props {
currentPhoto: Photo
diff --git a/app/components/photo/Viewer.vue b/app/components/photo/Viewer.vue
index ef012629..bfee9372 100644
--- a/app/components/photo/Viewer.vue
+++ b/app/components/photo/Viewer.vue
@@ -14,7 +14,6 @@ import ProgressiveImage from './ProgressiveImage.vue'
import GalleryThumbnail from './GalleryThumbnail.vue'
import InfoPanel from './InfoPanel.vue'
import type { LoadingIndicatorRef } from './LoadingIndicator.vue'
-import { useMediaQuery } from '~/composables/useMediaQuery'
interface Props {
photos: Photo[]
@@ -108,39 +107,6 @@ const handleBlobSrcChange = (blobSrc: string | null) => {
currentBlobSrc.value = blobSrc
}
-// Keyboard navigation
-// const handleKeyDown = (event: KeyboardEvent) => {
-// if (!props.isOpen) return
-
-// switch (event.key) {
-// case 'ArrowLeft':
-// event.preventDefault()
-// handlePrevious()
-// break
-// case 'ArrowRight':
-// event.preventDefault()
-// handleNext()
-// break
-// case 'Escape':
-// event.preventDefault()
-// emit('close')
-// break
-// case 'i':
-// case 'I':
-// event.preventDefault()
-// showExifPanel.value = !showExifPanel.value
-// break
-// }
-// }
-
-// onMounted(() => {
-// document.addEventListener('keypress', handleKeyDown)
-// })
-
-// onUnmounted(() => {
-// document.removeEventListener('keypress', handleKeyDown)
-// })
-
defineShortcuts({
escape: () => {
emit('close')
diff --git a/app/composables/useMediaQuery.ts b/app/composables/useMediaQuery.ts
deleted file mode 100644
index b50bed4d..00000000
--- a/app/composables/useMediaQuery.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import { ref, onMounted, onUnmounted } from 'vue'
-
-/**
- * 媒体查询 composable
- * @param query CSS 媒体查询字符串
- * @returns 是否匹配媒体查询的响应式引用
- */
-export function useMediaQuery(query: string) {
- const matches = ref(false)
- let mediaQuery: MediaQueryList | null = null
-
- const updateMatches = () => {
- if (mediaQuery) {
- matches.value = mediaQuery.matches
- }
- }
-
- onMounted(() => {
- if (typeof window !== 'undefined') {
- mediaQuery = window.matchMedia(query)
- matches.value = mediaQuery.matches
-
- // 监听媒体查询变化
- if (mediaQuery.addEventListener) {
- mediaQuery.addEventListener('change', updateMatches)
- } else {
- // 兼容旧版浏览器
- mediaQuery.addListener(updateMatches)
- }
- }
- })
-
- onUnmounted(() => {
- if (mediaQuery) {
- if (mediaQuery.removeEventListener) {
- mediaQuery.removeEventListener('change', updateMatches)
- } else {
- // 兼容旧版浏览器
- mediaQuery.removeListener(updateMatches)
- }
- }
- })
-
- return matches
-}
diff --git a/app/layouts/dashboard.vue b/app/layouts/dashboard.vue
index 50abf6bf..5a39a7e5 100644
--- a/app/layouts/dashboard.vue
+++ b/app/layouts/dashboard.vue
@@ -3,20 +3,15 @@ import type { NavigationMenuItem } from '@nuxt/ui'
const items = ref<NavigationMenuItem[]>([
{
- label: 'Dashboard',
+ label: '仪表盘',
icon: 'tabler:dashboard',
to: '/dashboard',
},
{
- label: 'Photos',
+ label: '照片库',
icon: 'tabler:photo-cog',
to: '/dashboard/photos',
},
- {
- label: 'Workers',
- icon: 'tabler:automatic-gearbox',
- to: '/dashboard/workers',
- },
])
const { loggedIn, user } = useUserSession()
@@ -40,7 +35,7 @@ const handleLogin = () => {
to="/"
class="text-lg font-medium text-nowrap"
>
- Timothy Yin's Photos
+ TimoYin's mems
</NuxtLink>
</div>
<UNavigationMenu
diff --git a/app/pages/dashboard/index.vue b/app/pages/dashboard/index.vue
index ceb8b2ae..eddbe2ba 100644
--- a/app/pages/dashboard/index.vue
+++ b/app/pages/dashboard/index.vue
@@ -2,14 +2,210 @@
definePageMeta({
layout: 'dashboard',
})
+
+interface SystemHealth {
+ uptime: number
+ memory: {
+ used: number
+ total: number
+ }
+ processing: {
+ active: boolean
+ queued: number
+ }
+}
+
+const { data: photos, refresh: refreshPhotos } = await useFetch('/api/photos', {
+ server: false,
+})
+
+const { data: healthStatus, refresh: refreshHealth } =
+ await useFetch<SystemHealth>('/api/health/system', {
+ server: false,
+ })
+
+const isLoading = ref(false)
+
+const refreshData = async () => {
+ isLoading.value = true
+ try {
+ await Promise.all([refreshPhotos(), refreshHealth()])
+ } finally {
+ isLoading.value = false
+ }
+}
+
+// 定期刷新状态
+const refreshInterval = setInterval(refreshData, 30000)
+
+onBeforeUnmount(() => {
+ clearInterval(refreshInterval)
+})
</script>
<template>
- <div>
- Dashboard Index
+ <div class="flex flex-col gap-6 h-full p-4">
+ <div class="flex items-center justify-between">
+ <h1 class="text-2xl font-bold">仪表板概览</h1>
+ <UButton
+ icon="i-tabler-refresh"
+ variant="outline"
+ :loading="isLoading"
+ @click="refreshData"
+ >
+ 刷新
+ </UButton>
+ </div>
+
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
+ <!-- 总照片数量 -->
+ <UCard>
+ <div class="flex items-center justify-between">
+ <div>
+ <p class="text-sm text-neutral-500 dark:text-neutral-400">
+ 总照片数量
+ </p>
+ <p class="text-2xl font-bold">{{ photos?.length || 0 }}</p>
+ </div>
+ <UIcon
+ name="i-tabler-photo"
+ class="w-8 h-8 text-info"
+ />
+ </div>
+ </UCard>
+
+ <!-- 系统内存使用 -->
+ <UCard>
+ <div class="flex items-center justify-between">
+ <div>
+ <p class="text-sm text-neutral-500 dark:text-neutral-400">
+ 内存使用率
+ </p>
+ <p class="text-2xl font-bold">
+ {{
+ healthStatus?.memory
+ ? Math.round(
+ (healthStatus.memory.used / healthStatus.memory.total) *
+ 100,
+ )
+ : 0
+ }}%
+ </p>
+ </div>
+ <UIcon
+ name="i-tabler-cpu"
+ class="w-8 h-8 text-success"
+ />
+ </div>
+ </UCard>
+
+ <!-- 系统运行时间 -->
+ <UCard>
+ <div class="flex items-center justify-between">
+ <div>
+ <p class="text-sm text-neutral-500 dark:text-neutral-400">
+ 运行时间
+ </p>
+ <p class="text-2xl font-bold">
+ {{
+ healthStatus?.uptime
+ ? Math.round(healthStatus.uptime / 3600)
+ : 0
+ }}h
+ </p>
+ </div>
+ <UIcon
+ name="i-tabler-clock"
+ class="w-8 h-8 text-warning-500"
+ />
+ </div>
+ </UCard>
+
+ <!-- 系统状态 -->
+ <UCard>
+ <div class="flex items-center justify-between">
+ <div>
+ <p class="text-sm text-neutral-500 dark:text-neutral-400">
+ 系统状态
+ </p>
+ <p class="text-2xl font-bold">
+ <UBadge
+ :color="
+ healthStatus?.processing?.active !== false
+ ? 'success'
+ : 'warning'
+ "
+ variant="solid"
+ >
+ {{
+ healthStatus?.processing?.active !== false ? '正常' : '待机'
+ }}
+ </UBadge>
+ </p>
+ </div>
+ <UIcon
+ name="i-tabler-heart"
+ class="w-8 h-8 text-error"
+ />
+ </div>
+ </UCard>
+ </div>
+
+ <!-- 系统信息 -->
+ <UCard>
+ <template #header>
+ <h2 class="text-lg font-semibold">系统信息</h2>
+ </template>
+
+ <div class="grid grid-cols-2 gap-4">
+ <div>
+ <p class="text-sm text-neutral-500 dark:text-neutral-400">应用版本</p>
+ <p class="text-lg font-bold">ChronoFrame dev</p>
+ </div>
+ <div>
+ <p class="text-sm text-neutral-500 dark:text-neutral-400">最后更新</p>
+ <p class="text-lg font-bold">
+ {{ new Date().toLocaleDateString('zh-CN') }}
+ </p>
+ </div>
+ </div>
+ </UCard>
+
+ <!-- 最近照片 -->
+ <UCard v-if="photos?.length">
+ <template #header>
+ <h2 class="text-lg font-semibold">最近照片</h2>
+ </template>
+
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
+ <div
+ v-for="photo in photos.slice(0, 12)"
+ :key="photo.id"
+ class="flex items-center gap-3 p-3 bg-neutral-50 dark:bg-neutral-800 rounded-lg"
+ >
+ <div
+ class="w-12 h-12 bg-neutral-200 dark:bg-neutral-700 rounded flex items-center justify-center relative"
+ >
+ <img
+ :src="photo.thumbnailUrl || ''"
+ alt="Photo thumbnail"
+ class="w-full h-full rounded"
+ />
+ </div>
+ <div class="flex-1 min-w-0">
+ <p class="font-medium truncate">{{ photo.title || photo.id }}</p>
+ <p class="text-sm text-neutral-500">
+ {{
+ photo.dateTaken
+ ? new Date(photo.dateTaken).toLocaleDateString('zh-CN')
+ : '未知日期'
+ }}
+ </p>
+ </div>
+ </div>
+ </div>
+ </UCard>
</div>
</template>
-<style scoped>
-
-</style>
+<style scoped></style>
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vue
index 6a227e96..02cf5ba5 100644
--- a/app/pages/dashboard/photos.vue
+++ b/app/pages/dashboard/photos.vue
@@ -13,17 +13,17 @@ const { data, status, refresh } = useFetch('/api/photos')
const uploadImage = async (file: File) => {
const formData = new FormData()
formData.append('file', file)
-
+
try {
const response = await $fetch('/api/photos', {
method: 'PUT',
- body: formData
+ body: formData,
})
-
+
return response
} catch (error: any) {
console.error('上传请求失败:', error)
-
+
// 提供更详细的错误信息
if (error.response?.status === 401) {
throw new Error('未授权,请重新登录')
@@ -40,6 +40,7 @@ const uploadImage = async (file: File) => {
// 处理状态
const processingFiles = ref<Set<string>>(new Set())
const toast = useToast()
+const selectedFiles = ref<File[]>([])
// 状态检查间隔
let statusInterval: NodeJS.Timeout | null = null
@@ -76,29 +77,29 @@ const checkProcessingStatus = async () => {
}
return
}
-
+
try {
const response = await $fetch('/api/photos/status')
const currentPhotoCount = data.value?.length || 0
-
+
// 简单检查:如果照片数量增加了,说明有照片处理完成
if (response.recentPhotos?.length > currentPhotoCount) {
// 刷新照片列表
await refresh()
-
+
// 清空处理中的文件列表
processingFiles.value.clear()
-
+
// 停止状态检查
if (statusInterval) {
clearInterval(statusInterval)
statusInterval = null
}
-
+
toast.add({
title: '照片处理完成',
description: '您的照片已成功处理并上传',
- color: 'success'
+ color: 'success',
})
}
} catch (error) {
@@ -117,32 +118,26 @@ const validateFile = (file: File): { valid: boolean; error?: string } => {
// error: `不支持的文件格式: ${file.type}。请选择 JPEG、PNG 或 HEIC 格式的图片。`
// }
// }
-
+
// 检查文件大小 (128MB 限制)
const maxSize = 128 * 1024 * 1024 // 128MB
if (file.size > maxSize) {
return {
valid: false,
- error: `文件太大: ${(file.size / 1024 / 1024).toFixed(2)}MB。最大支持 128MB。`
+ error: `文件太大: ${(file.size / 1024 / 1024).toFixed(2)}MB。最大支持 128MB。`,
}
}
-
+
return { valid: true }
}
-const handleFileUpload = async (files: unknown) => {
- // 处理 UFileUpload 的输出格式
- let fileList: File[] = []
-
- if (files && Array.isArray(files)) {
- fileList = files.filter((f): f is File => f instanceof File)
- } else if (files instanceof File) {
- fileList = [files]
- } else {
- console.warn('无效的文件类型:', files)
+const handleUpload = async () => {
+ const fileList = selectedFiles.value
+
+ if (fileList.length === 0) {
return
}
-
+
for (const file of fileList) {
// 验证文件
const validation = validateFile(file)
@@ -150,23 +145,23 @@ const handleFileUpload = async (files: unknown) => {
toast.add({
title: '文件验证失败',
description: validation.error,
- color: 'error'
+ color: 'error',
})
continue
}
-
+
const fileName = file.name
processingFiles.value.add(fileName)
-
+
toast.add({
title: '开始处理照片',
description: `正在后台处理 ${fileName},请稍候...`,
- color: 'info'
+ color: 'info',
})
-
+
try {
await uploadImage(file)
-
+
// 开始状态检查
if (!statusInterval) {
statusInterval = setInterval(checkProcessingStatus, 2000)
@@ -176,11 +171,14 @@ const handleFileUpload = async (files: unknown) => {
toast.add({
title: '上传失败',
description: `${fileName}: ${error.message}`,
- color: 'error'
+ color: 'error',
})
console.error('上传错误:', error)
}
}
+
+ // 清空选中的文件
+ selectedFiles.value = []
}
const handleDelete = async (photoId: string) => {
@@ -200,29 +198,39 @@ onUnmounted(() => {
<template>
<div class="flex flex-col gap-4 h-full p-4">
- <!-- 处理状态指示器 -->
- <div v-if="processingFiles.size > 0" class="bg-blue-50 border border-blue-200 rounded-lg p-4">
- <div class="flex items-center gap-2">
- <UIcon name="i-heroicons-arrow-path" class="animate-spin text-blue-500" />
- <span class="text-blue-700 font-medium">
- 正在后台处理 {{ processingFiles.size }} 个文件...
- </span>
- </div>
- <p class="text-sm text-blue-600 mt-1">
- 处理完成后会自动刷新列表,您可以继续浏览其他页面
- </p>
- </div>
-
- <UFileUpload
- label="上传照片"
- description="支持 JPEG、PNG、HEIC 格式,最大 128MB"
- layout="list"
- size="xl"
- accept="image/jpeg,image/png,image/heic,image/heif"
- multiple
- @update:model-value="handleFileUpload"
+ <UAlert
+ v-if="processingFiles.size > 0"
+ title="照片正在处理"
+ :description="`正在后台处理 ${processingFiles.size} 个文件...`"
+ icon="svg-spinners:270-ring"
+ variant="soft"
+ color="info"
/>
- <div class="border border-neutral-300 rounded overflow-hidden">
+
+ <div class="relative">
+ <UFileUpload
+ v-model="selectedFiles"
+ label="选择照片"
+ description="支持 JPEG、PNG、HEIC 格式,最大 128MB"
+ layout="list"
+ size="xl"
+ accept="image/jpeg,image/png,image/heic,image/heif"
+ multiple
+ />
+ <UButton
+ class="absolute top-3.5 right-3.5"
+ variant="soft"
+ size="lg"
+ icon="tabler:upload"
+ :disabled="selectedFiles.length === 0"
+ @click="handleUpload"
+ >
+ 开始上传
+ </UButton>
+ </div>
+ <div
+ class="border border-neutral-300 dark:border-neutral-800 rounded overflow-hidden"
+ >
<UTable
:data="data as Photo[]"
:columns="columns"
@@ -230,7 +238,8 @@ onUnmounted(() => {
sticky
class="h-[600px]"
:ui="{
- separator: 'bg-(--ui-color-neutral-200)',
+ separator:
+ 'bg-(--ui-color-neutral-200) dark:bg-(--ui-color-neutral-700)',
}"
>
<template #actions-cell="{ row }">
diff --git a/app/pages/dashboard/workers.vue b/app/pages/dashboard/workers.vue
deleted file mode 100644
index 3c0fa244..00000000
--- a/app/pages/dashboard/workers.vue
+++ /dev/null
@@ -1,251 +0,0 @@
-<script lang="ts" setup>
-definePageMeta({
- layout: 'dashboard',
-})
-
-interface ProcessingStatus {
- recentPhotos: any[]
- timestamp: string
-}
-
-interface SystemHealth {
- uptime: number
- memory: {
- used: number
- total: number
- }
- processing: {
- active: boolean
- queued: number
- }
-}
-
-const { data: recentStatus, refresh: refreshRecent } =
- await useFetch<ProcessingStatus>('/api/photos/status', {
- server: false,
- })
-
-const { data: healthStatus, refresh: refreshHealth } =
- await useFetch<SystemHealth>('/api/health/system', {
- server: false,
- })
-
-const isLoading = ref(false)
-
-const refreshData = async () => {
- isLoading.value = true
- try {
- await Promise.all([refreshRecent(), refreshHealth()])
- } finally {
- isLoading.value = false
- }
-}
-
-const triggerTestProcessing = async () => {
- isLoading.value = true
- try {
- await $fetch('/api/test/photo-processing', {
- method: 'POST'
- })
-
- await refreshData()
- useToast().add({
- title: '测试处理启动',
- description: '后台照片处理测试已开始',
- color: 'success',
- })
- } catch (error) {
- useToast().add({
- title: '测试失败',
- description: '无法启动测试处理',
- color: 'error',
- })
- } finally {
- isLoading.value = false
- }
-}
-
-// 定期刷新状态
-const refreshInterval = setInterval(refreshData, 3000)
-
-onBeforeUnmount(() => {
- clearInterval(refreshInterval)
-})
-</script>
-
-<template>
- <div class="flex flex-col gap-6 h-full p-4">
- <div class="flex items-center justify-between">
- <h1 class="text-2xl font-bold">后台处理监控</h1>
- <div class="flex gap-2">
- <UButton
- icon="i-tabler-refresh"
- variant="outline"
- :loading="isLoading"
- @click="refreshData"
- >
- 刷新
- </UButton>
- <UButton
- icon="i-tabler-test-pipe"
- variant="outline"
- color="primary"
- :loading="isLoading"
- @click="triggerTestProcessing"
- >
- 测试处理
- </UButton>
- </div>
- </div>
-
- <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
- <!-- 最近处理的照片数量 -->
- <UCard>
- <div class="flex items-center justify-between">
- <div>
- <p class="text-sm text-gray-500 dark:text-gray-400">
- 最近处理照片
- </p>
- <p class="text-2xl font-bold">{{ recentStatus?.recentPhotos?.length || 0 }}</p>
- </div>
- <UIcon
- name="i-tabler-photo"
- class="w-8 h-8 text-blue-500"
- />
- </div>
- </UCard>
-
- <!-- 系统内存使用 -->
- <UCard>
- <div class="flex items-center justify-between">
- <div>
- <p class="text-sm text-gray-500 dark:text-gray-400">
- 内存使用率
- </p>
- <p class="text-2xl font-bold">
- {{ healthStatus?.memory ? Math.round((healthStatus.memory.used / healthStatus.memory.total) * 100) : 0 }}%
- </p>
- </div>
- <UIcon
- name="i-tabler-cpu"
- class="w-8 h-8 text-green-500"
- />
- </div>
- </UCard>
-
- <!-- 处理队列状态 -->
- <UCard>
- <div class="flex items-center justify-between">
- <div>
- <p class="text-sm text-gray-500 dark:text-gray-400">队列任务</p>
- <p class="text-2xl font-bold">{{ healthStatus?.processing?.queued || 0 }}</p>
- </div>
- <UIcon
- name="i-tabler-list"
- class="w-8 h-8 text-yellow-500"
- />
- </div>
- </UCard>
-
- <!-- 系统运行时间 -->
- <UCard>
- <div class="flex items-center justify-between">
- <div>
- <p class="text-sm text-gray-500 dark:text-gray-400">
- 运行时间
- </p>
- <p class="text-2xl font-bold">
- {{ healthStatus?.uptime ? Math.round(healthStatus.uptime / 3600) : 0 }}h
- </p>
- </div>
- <UIcon
- name="i-tabler-clock"
- class="w-8 h-8 text-purple-500"
- />
- </div>
- </UCard>
- </div>
-
- <!-- 后台处理配置 -->
- <UCard>
- <template #header>
- <h2 class="text-lg font-semibold">后台处理配置</h2>
- </template>
-
- <div class="grid grid-cols-2 gap-4">
- <div>
- <p class="text-sm text-gray-500 dark:text-gray-400">处理模式</p>
- <p class="text-lg font-bold">异步后台处理</p>
- </div>
- <div>
- <p class="text-sm text-gray-500 dark:text-gray-400">
- 响应时间
- </p>
- <p class="text-lg font-bold text-green-600">
- &lt; 50ms
- </p>
- </div>
- </div>
- </UCard>
-
- <!-- 系统状态 -->
- <UCard>
- <template #header>
- <h2 class="text-lg font-semibold">系统状态</h2>
- </template>
-
- <div class="flex items-center gap-3">
- <UBadge
- :color="healthStatus?.processing?.active !== false ? 'success' : 'warning'"
- variant="solid"
- >
- {{ healthStatus?.processing?.active !== false ? '正常运行' : '待机' }}
- </UBadge>
- <span class="text-sm text-gray-500 dark:text-gray-400">
- 后台处理系统{{ healthStatus?.processing?.active !== false ? '正在运行' : '处于待机状态' }}
- </span>
- </div>
-
- <div class="mt-4 space-y-2">
- <div class="flex justify-between text-sm">
- <span>最后更新:</span>
- <span class="font-medium">
- {{ recentStatus?.timestamp ? new Date(recentStatus.timestamp).toLocaleString('zh-CN') : '未知' }}
- </span>
- </div>
- <div class="flex justify-between text-sm">
- <span>处理性能:</span>
- <span class="font-medium text-green-600">
- 高效非阻塞
- </span>
- </div>
- </div>
- </UCard>
-
- <!-- 最近处理的照片 -->
- <UCard v-if="recentStatus?.recentPhotos?.length">
- <template #header>
- <h2 class="text-lg font-semibold">最近处理的照片</h2>
- </template>
-
- <div class="space-y-2">
- <div
- v-for="photo in recentStatus.recentPhotos.slice(0, 5)"
- :key="photo.id"
- class="flex justify-between items-center p-2 bg-gray-50 dark:bg-gray-800 rounded"
- >
- <div>
- <p class="font-medium">{{ photo.title || photo.id }}</p>
- <p class="text-sm text-gray-500">{{ photo.fileSize ? (photo.fileSize / 1024 / 1024).toFixed(2) + ' MB' : '未知大小' }}</p>
- </div>
- <div class="text-right">
- <p class="text-sm text-gray-500">{{ photo.lastModified ? new Date(photo.lastModified).toLocaleString('zh-CN') : '未知时间' }}</p>
- <UBadge color="success" variant="soft">已完成</UBadge>
- </div>
- </div>
- </div>
- </UCard>
- </div>
-</template>
-
-<style scoped></style>
diff --git a/app/pages/index.vue b/app/pages/index.vue
index 7db5dc8c..4ce47576 100644
--- a/app/pages/index.vue
+++ b/app/pages/index.vue
@@ -1,14 +1,58 @@
<script lang="ts" setup>
+import { motion } from 'motion-v'
const { data } = useFetch('/api/photos')
</script>
<template>
- <div class="h-svh p-2 pt-1 bg-gray-50 dark:bg-gray-900">
+ <div class="h-svh px-1">
<ClientOnly>
<MasonryRoot
:photos="data as Photo[]"
:columns="'auto'"
/>
+ <template #fallback>
+ <div
+ class="fixed inset-0 flex flex-col gap-4 items-center justify-center"
+ >
+ <LoaderAvatar />
+ <span class="loading-scan-wrapper">
+ <span class="text-base font-medium loading-scan-text">LOADING</span>
+ </span>
+ </div>
+ </template>
</ClientOnly>
</div>
</template>
+
+<style scoped>
+.loading-scan-wrapper {
+ display: inline-block;
+ position: relative;
+}
+.loading-scan-text {
+ display: inline-block;
+ background: linear-gradient(
+ 90deg,
+ #fff 0%,
+ #fff 30%,
+ rgba(255, 255, 255, 0.3) 50%,
+ #fff 70%,
+ #fff 100%
+ );
+ background-size: 200% 100%;
+ background-position: 200% 0;
+ -webkit-background-clip: text;
+ -webkit-text-fill-color: transparent;
+ background-clip: text;
+ color: transparent;
+ animation: scan-x-text 1.2s linear infinite;
+}
+@keyframes scan-x-text {
+ 0% {
+ background-position: 200% 0;
+ }
+ 100% {
+ background-position: -200% 0;
+ }
+}
+</style>
diff --git a/nuxt.config.ts b/nuxt.config.ts
index 5f1303b7..1498e334 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -14,6 +14,7 @@ export default defineNuxtConfig({
'@nuxt/test-utils',
'motion-v/nuxt',
'nuxt-auth-utils',
+ '@vueuse/nuxt',
],
css: ['~/assets/css/tailwind.css'],
@@ -42,4 +43,8 @@ export default defineNuxtConfig({
vite: {
plugins: [tailwindcss() as any],
},
-})
+
+ colorMode: {
+ preference: 'dark'
+ }
+})
\ No newline at end of file
diff --git a/package.json b/package.json
index b7a92ebd..f458615b 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
"@nuxthub/core": "0.9.0",
"@tailwindcss/vite": "^4.1.12",
"@vingle/bmp-js": "^0.2.5",
+ "@vueuse/nuxt": "13.8.0",
"better-sqlite3": "^12.2.0",
"cloudflare": "^4.5.0",
"db0": "^0.3.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6f6a4583..73d6abd8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -35,6 +35,9 @@ importers:
'@vingle/bmp-js':
specifier: ^0.2.5
version: 0.2.5
+ '@vueuse/nuxt':
+ specifier: 13.8.0
better-sqlite3:
specifier: ^12.2.0
version: 12.2.0
@@ -3177,6 +3180,11 @@ packages:
peerDependencies:
vue: ^3.5.0
+ '@vueuse/[email protected]':
+ resolution: {integrity: sha512-rmBcgpEpxY0ZmyQQR94q1qkUcHREiLxQwNyWrtjMDipD0WTH/JBcAt0gdcn2PsH0SA76ec291cHFngmyaBhlxA==}
+ peerDependencies:
+ vue: ^3.5.0
+
'@vueuse/[email protected]':
resolution: {integrity: sha512-Na5p0ONLepNV/xCBi8vBMuzCOZh9CFT/OHnrUlABWXgWTWSHM3wrVaLS1xvAijPLU5B1ysyJDDW/hKak80oLGA==}
peerDependencies:
@@ -3228,6 +3236,15 @@ packages:
'@vueuse/[email protected]':
resolution: {integrity: sha512-8okFhS/1ite8EwUdZZfvTYowNTfXmVCOrBFlA31O0HD8HKXhY+WtTRyF0LwbpJfoFPc+s9anNJIXMVrvP7UTZg==}
+ '@vueuse/[email protected]':
+ resolution: {integrity: sha512-BYMp3Gp1kBUPv7AfQnJYP96mkX7g7cKdTIgwv/Jgd+pfQhz678naoZOAcknRtPLP4cFblDDW7rF4e3KFa+PfIA==}
+
+ '@vueuse/[email protected]':
+ resolution: {integrity: sha512-RpD/CWl6nJ6q92+EpPCsnwlq/N7YqTm1TRV9SY7ERt3WRaMzkIyMfYMGOonpGRG2Y0XSHK9aiWi8+QpoB1YKDw==}
+ peerDependencies:
+ nuxt: ^3.0.0 || ^4.0.0-0
+ vue: ^3.5.0
+
'@vueuse/[email protected]':
resolution: {integrity: sha512-LHpC8711VFZlDaYUXEBbFBCQ7GS3dVU9mjOhhMhXP6txTV4EhYQg/KGnQuvt/sPAtoUKq7VVUnL6mVtFoL42sA==}
@@ -3239,6 +3256,11 @@ packages:
peerDependencies:
vue: ^3.5.0
+ '@vueuse/[email protected]':
+ resolution: {integrity: sha512-x4nfM0ykW+RmNJ4/1IzZsuLuWWrNTxlTWUiehTGI54wnOxIgI9EDdu/O5S77ac6hvQ3hk2KpOVFHaM0M796Kbw==}
+ peerDependencies:
+ vue: ^3.5.0
+
'@whatwg-node/[email protected]':
resolution: {integrity: sha512-LOtTn+JgJvX8WfBVJtF08TGrdjuFzGJc4mkP8EdDI8ADbvO7kiexYep1o8dwnt0okb0jYclCDXF13xU7Ge4zSw==}
engines: {node: '>=18.0.0'}
@@ -10910,6 +10932,13 @@ snapshots:
'@vueuse/shared': 13.7.0([email protected]([email protected]))
vue: 3.5.19([email protected])
+ dependencies:
+ '@types/web-bluetooth': 0.0.21
+ '@vueuse/metadata': 13.8.0
+ '@vueuse/shared': 13.8.0([email protected]([email protected]))
+ vue: 3.5.19([email protected])
+
dependencies:
'@vueuse/core': 13.7.0([email protected]([email protected]))
@@ -10927,6 +10956,19 @@ snapshots:
'@vueuse/[email protected]': {}
+ '@vueuse/[email protected]': {}
+
+ dependencies:
+ '@nuxt/kit': 3.18.1([email protected])
+ '@vueuse/core': 13.8.0([email protected]([email protected]))
+ '@vueuse/metadata': 13.8.0
+ local-pkg: 1.1.2
+ vue: 3.5.19([email protected])
+ transitivePeerDependencies:
+ - magicast
+
dependencies:
@@ -10944,6 +10986,10 @@ snapshots:
dependencies:
vue: 3.5.19([email protected])
+ dependencies:
+ vue: 3.5.19([email protected])
+
'@whatwg-node/[email protected]':
dependencies:
'@whatwg-node/promise-helpers': 1.3.2