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: reuse dashboard capture heatmap in cloud site overview
Timothy Yin2861122d5996
diff --git a/apps/cloud/app/pages/sites/[siteId]/overview.vue b/apps/cloud/app/pages/sites/[siteId]/overview.vueindex 5d5b3b9a..c52d9672 100644--- a/apps/cloud/app/pages/sites/[siteId]/overview.vue+++ b/apps/cloud/app/pages/sites/[siteId]/overview.vue@@ -1,4 +1,5 @@<script setup lang="ts">+import DashboardCaptureHeatmap from '#console/components/DashboardCaptureHeatmap.vue'import {CheckCircle2,Images,@@ -106,6 +107,9 @@ const actions = computed(() => ["/></section>+ <CfCard class="cf-dashboard-panel min-w-0">+ <DashboardCaptureHeatmap :photos="photos" />+ </CfCard><div class="cf-dashboard-columns"><CfCard class="cf-dashboard-panel"><div class="cf-dashboard-section-heading">diff --git a/packages/console/app/components/DashboardCaptureHeatmap.vue b/packages/console/app/components/DashboardCaptureHeatmap.vuenew file mode 100644index 00000000..fe5e0cf8--- /dev/null+++ b/packages/console/app/components/DashboardCaptureHeatmap.vue@@ -0,0 +1,215 @@+<script setup lang="ts">+import '#gallery/assets/css/heatmap.css'+import type { CalendarItem } from '#gallery/components/ui/CalendarHeatmap/Heatmap'+const props = defineProps<{ photos: Array<{ dateTaken?: string | null }> }>()+const photos = computed(() => props.photos)+const dayjs = useDayjs()+const selectedYear = ref<number | 'recent'>('recent')+// 获取所有有照片的年份+const availableYears = computed(() => {+ if (!photos.value || photos.value.length === 0) return []++ const years = new Set<number>()+ photos.value.forEach((photo) => {+ if (photo.dateTaken) {+ const year = dayjs(photo.dateTaken).year()+ years.add(year)+ }+ })++ return Array.from(years).sort((a, b) => b - a) // 降序排列,最新年份在前+})++const heatmapData = computed(() => {+ if (!photos.value || photos.value.length === 0) return []++ const dateCountMap = new Map<string, number>()++ // 计算起止范围+ let start, end+ if (selectedYear.value === 'recent') {+ start = dayjs().subtract(1, 'year')+ end = dayjs().add(1, 'day') // 包含今天+ } else {+ start = dayjs(`${selectedYear.value}-01-01`).startOf('year')+ end = dayjs(`${selectedYear.value}-01-01`).endOf('year')+ }++ photos.value.forEach((photo) => {+ if (!photo.dateTaken) return+ const photoDate = dayjs(photo.dateTaken)++ if (photoDate.isBetween(start, end, 'day', '[]')) {+ const date = photoDate.format('YYYY-MM-DD')+ dateCountMap.set(date, (dateCountMap.get(date) || 0) + 1)+ }+ })++ return Array.from(dateCountMap.entries()).map(([date, count]) => ({+ date,+ count,+ }))+})++const heatmapStartDate = computed(() => {+ if (selectedYear.value === 'recent') {+ return dayjs().subtract(1, 'year').toDate()+ }+ return dayjs(`${selectedYear.value}-01-01`).startOf('year').toDate()+})++const heatmapEndDate = computed(() => {+ if (selectedYear.value === 'recent') {+ return dayjs().add(1, 'day').toDate()+ }+ return dayjs(`${selectedYear.value}-01-01`).endOf('year').toDate()+})++const yearOptions = computed(() => {+ const options: Array<{ label: string; value: number | 'recent' }> = [+ {+ label: $t('common.heatmap.legend.recentlyYear'),+ value: 'recent' as const,+ },+ ]++ availableYears.value.forEach((year) => {+ options.push({ label: year.toString(), value: year })+ })++ return options+})+</script>+<template>+ <div class="heatmap-container">+ <ClientOnly>+ <CalendarHeatmap+ theme="blue"+ :values="heatmapData"+ :start-date="heatmapStartDate"+ :end-date="heatmapEndDate"+ :round="3"+ :tooltip-formatter="+ (item: CalendarItem) => {+ return $t('common.heatmap.tooltip.data', [+ $dayjs(item.date).format('LL'),+ item.count || 0,+ ])+ }+ "+ :tooltip-no-data-formatter="+ (date: Date) =>+ $t('common.heatmap.tooltip.noData', [$dayjs(date).format('LL')])+ "+ :locale="{+ months: [+ $t('common.months.jan'),+ $t('common.months.feb'),+ $t('common.months.mar'),+ $t('common.months.apr'),+ $t('common.months.may'),+ $t('common.months.jun'),+ $t('common.months.jul'),+ $t('common.months.aug'),+ $t('common.months.sep'),+ $t('common.months.oct'),+ $t('common.months.nov'),+ $t('common.months.dec'),+ ],+ days: [+ $t('common.days.sun'),+ $t('common.days.mon'),+ $t('common.days.tue'),+ $t('common.days.wed'),+ $t('common.days.thu'),+ $t('common.days.fri'),+ $t('common.days.sat'),+ ],+ less: $t('common.heatmap.legend.less'),+ more: $t('common.heatmap.legend.more'),+ }"+ :dark-mode="$colorMode.value === 'dark'"+ >+ <template #vch__legend-left>+ <USelectMenu+ v-model="selectedYear"+ :items="yearOptions"+ :disabled="yearOptions.length <= 1"+ :search-input="false"+ value-key="value"+ size="xs"+ variant="soft"+ class="w-24"+ />+ </template>+ </CalendarHeatmap>+ <template #placeholder>+ <div class="flex items-center justify-center h-[164.5px]">+ <Icon+ name="svg-spinners:180-ring-with-bg"+ class="size-8 opacity-50"+ mode="svg"+ />+ </div>+ </template>+ </ClientOnly>+ </div>+</template>+<style>+.heatmap-container {+ overflow-x: auto;+ overflow-y: hidden;+ min-width: 100%;+ -webkit-overflow-scrolling: touch;+ scrollbar-width: thin;+ scrollbar-color: rgba(0, 0, 0, 0.2) transparent;+}++.heatmap-container::-webkit-scrollbar {+ height: 4px;+}++.heatmap-container::-webkit-scrollbar-track {+ background: rgba(0, 0, 0, 0.05);+ border-radius: 2px;+}++.heatmap-container::-webkit-scrollbar-thumb {+ background: rgba(0, 0, 0, 0.2);+ border-radius: 2px;+}++.heatmap-container::-webkit-scrollbar-thumb:hover {+ background: rgba(0, 0, 0, 0.3);+}++/* 暗色模式下的滚动条样式 */+.dark .heatmap-container::-webkit-scrollbar-track {+ background: rgba(255, 255, 255, 0.05);+}++.dark .heatmap-container::-webkit-scrollbar-thumb {+ background: rgba(255, 255, 255, 0.2);+}++.dark .heatmap-container::-webkit-scrollbar-thumb:hover {+ background: rgba(255, 255, 255, 0.3);+}++.heatmap-container .vch__container {+ min-width: 720px;+}++.vch__day__label,+.vch__month__label,+.vch__legend {+ font-size: var(--text-xs);+ font-weight: var(--font-weight-medium);+ color: var(--color-neutral-500);+}++.vch__day__label,+.vch__month__label {+ font-size: var(--text-xs);+}+</style>diff --git a/packages/console/app/pages/dashboard/index.vue b/packages/console/app/pages/dashboard/index.vueindex 55640803..e10f1a62 100644--- a/packages/console/app/pages/dashboard/index.vue+++ b/packages/console/app/pages/dashboard/index.vue@@ -1,7 +1,5 @@<script lang="ts" setup>-import '#gallery/assets/css/heatmap.css'-import type { CalendarItem } from '#gallery/components/ui/CalendarHeatmap/Heatmap'-+import DashboardCaptureHeatmap from '#console/components/DashboardCaptureHeatmap.vue'definePageMeta({layout: 'dashboard',})@@ -10,7 +8,6 @@ useHead({title: () => $t('title.dashboard'),})-const dayjs = useDayjs()const appTitle = useSettingRef('app:title')const appSlogan = useSettingRef('app:slogan')const { photos } = usePhotos()@@ -20,9 +17,6 @@ const { data: dashboardStats, refresh: refreshStats } =const isLoading = ref(false)-// 年份选择器相关状态-const selectedYear = ref<number | 'recent'>('recent')-const refreshData = async () => {isLoading.value = truetry {@@ -214,81 +208,6 @@ const queueSuccessColor = computed(() => {return 'error'})-// 获取所有有照片的年份-const availableYears = computed(() => {- if (!photos.value || photos.value.length === 0) return []-- const years = new Set<number>()- photos.value.forEach((photo) => {- if (photo.dateTaken) {- const year = dayjs(photo.dateTaken).year()- years.add(year)- }- })-- return Array.from(years).sort((a, b) => b - a) // 降序排列,最新年份在前-})--const heatmapData = computed(() => {- if (!photos.value || photos.value.length === 0) return []-- const dateCountMap = new Map<string, number>()-- // 计算起止范围- let start, end- if (selectedYear.value === 'recent') {- start = dayjs().subtract(1, 'year')- end = dayjs().add(1, 'day') // 包含今天- } else {- start = dayjs(`${selectedYear.value}-01-01`).startOf('year')- end = dayjs(`${selectedYear.value}-01-01`).endOf('year')- }-- photos.value.forEach((photo) => {- if (!photo.dateTaken) return- const photoDate = dayjs(photo.dateTaken)-- if (photoDate.isBetween(start, end, 'day', '[]')) {- const date = photoDate.format('YYYY-MM-DD')- dateCountMap.set(date, (dateCountMap.get(date) || 0) + 1)- }- })-- return Array.from(dateCountMap.entries()).map(([date, count]) => ({- date,- count,- }))-})--const heatmapStartDate = computed(() => {- if (selectedYear.value === 'recent') {- return dayjs().subtract(1, 'year').toDate()- }- return dayjs(`${selectedYear.value}-01-01`).startOf('year').toDate()-})--const heatmapEndDate = computed(() => {- if (selectedYear.value === 'recent') {- return dayjs().add(1, 'day').toDate()- }- return dayjs(`${selectedYear.value}-01-01`).endOf('year').toDate()-})--const yearOptions = computed(() => {- const options: Array<{ label: string; value: number | 'recent' }> = [- {- label: $t('common.heatmap.legend.recentlyYear'),- value: 'recent' as const,- },- ]-- availableYears.value.forEach((year) => {- options.push({ label: year.toString(), value: year })- })-- return options-})-const onShareSite = () => {const discussionParams = new URLSearchParams({category: 'showcases',@@ -352,81 +271,7 @@ const onShareSite = () => {<!-- 左侧 --><div class="min-w-0 space-y-4 lg:col-span-3"><UCard>- <div class="heatmap-container">- <ClientOnly>- <CalendarHeatmap- theme="blue"- :values="heatmapData"- :start-date="heatmapStartDate"- :end-date="heatmapEndDate"- :round="3"- :tooltip-formatter="- (item: CalendarItem) => {- return $t('common.heatmap.tooltip.data', [- $dayjs(item.date).format('LL'),- item.count || 0,- ])- }- "- :tooltip-no-data-formatter="- (date: Date) =>- $t('common.heatmap.tooltip.noData', [- $dayjs(date).format('LL'),- ])- "- :locale="{- months: [- $t('common.months.jan'),- $t('common.months.feb'),- $t('common.months.mar'),- $t('common.months.apr'),- $t('common.months.may'),- $t('common.months.jun'),- $t('common.months.jul'),- $t('common.months.aug'),- $t('common.months.sep'),- $t('common.months.oct'),- $t('common.months.nov'),- $t('common.months.dec'),- ],- days: [- $t('common.days.sun'),- $t('common.days.mon'),- $t('common.days.tue'),- $t('common.days.wed'),- $t('common.days.thu'),- $t('common.days.fri'),- $t('common.days.sat'),- ],- less: $t('common.heatmap.legend.less'),- more: $t('common.heatmap.legend.more'),- }"- :dark-mode="$colorMode.value === 'dark'"- >- <template #vch__legend-left>- <USelectMenu- v-model="selectedYear"- :items="yearOptions"- :disabled="yearOptions.length <= 1"- :search-input="false"- value-key="value"- size="xs"- variant="soft"- class="w-24"- />- </template>- </CalendarHeatmap>- <template #placeholder>- <div class="flex items-center justify-center h-[164.5px]">- <Icon- name="svg-spinners:180-ring-with-bg"- class="size-8 opacity-50"- mode="svg"- />- </div>- </template>- </ClientOnly>- </div>+ <DashboardCaptureHeatmap :photos="photos" /></UCard><DashboardRecentActivity /></div>@@ -740,62 +585,3 @@ const onShareSite = () => {</template></UDashboardPanel></template>--<style>-.heatmap-container {- overflow-x: auto;- overflow-y: hidden;- min-width: 100%;- -webkit-overflow-scrolling: touch;- scrollbar-width: thin;- scrollbar-color: rgba(0, 0, 0, 0.2) transparent;-}--.heatmap-container::-webkit-scrollbar {- height: 4px;-}--.heatmap-container::-webkit-scrollbar-track {- background: rgba(0, 0, 0, 0.05);- border-radius: 2px;-}--.heatmap-container::-webkit-scrollbar-thumb {- background: rgba(0, 0, 0, 0.2);- border-radius: 2px;-}--.heatmap-container::-webkit-scrollbar-thumb:hover {- background: rgba(0, 0, 0, 0.3);-}--/* 暗色模式下的滚动条样式 */-.dark .heatmap-container::-webkit-scrollbar-track {- background: rgba(255, 255, 255, 0.05);-}--.dark .heatmap-container::-webkit-scrollbar-thumb {- background: rgba(255, 255, 255, 0.2);-}--.dark .heatmap-container::-webkit-scrollbar-thumb:hover {- background: rgba(255, 255, 255, 0.3);-}--.heatmap-container .vch__container {- min-width: 720px;-}--.vch__day__label,-.vch__month__label,-.vch__legend {- font-size: var(--text-xs);- font-weight: var(--font-weight-medium);- color: var(--color-neutral-500);-}--.vch__day__label,-.vch__month__label {- font-size: var(--text-xs);-}-</style>