前端实现列表紧凑显示
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
* @typedef {Object} PhotoCardProps
|
||||
* @property {import('$lib/api/types').Photo} photo
|
||||
* @property {(photoId: number, previewSrc: string) => void} [onUpgradeQuality]
|
||||
* @property {boolean} borderLess
|
||||
*/
|
||||
|
||||
/** @type {PhotoCardProps} */
|
||||
let { photo, onUpgradeQuality } = $props();
|
||||
let { photo, onUpgradeQuality, borderLess } = $props();
|
||||
|
||||
// 使用 $derived 确保响应式更新
|
||||
let previewSrc = $derived(`/api/v1/photo/${photo.id}/preview`);
|
||||
@@ -27,7 +28,7 @@
|
||||
</script>
|
||||
|
||||
<a href={resolve(`/photo/${photo.id}`)} class="photo-card">
|
||||
<div class="photo-wrapper">
|
||||
<div class="photo-wrapper" class:photo-borderless={borderLess}>
|
||||
{#if photo.mimeType?.startsWith('video/')}
|
||||
<div class="video-indicator">🎬</div>
|
||||
<div class="photo-placeholder">
|
||||
@@ -48,71 +49,82 @@
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="photo-name">{photo.fileName}</p>
|
||||
<p class="photo-name" class:photo-name-hide={borderLess}>{photo.fileName}</p>
|
||||
</a>
|
||||
|
||||
<style>
|
||||
.photo-card {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
.photo-card {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.photo-wrapper {
|
||||
position: relative;
|
||||
aspect-ratio: 1;
|
||||
background: linear-gradient(135deg, var(--color-bg-tertiary) 0%, var(--color-border) 100%);
|
||||
border-radius: var(--radius-md);
|
||||
overflow: hidden;
|
||||
margin-bottom: var(--space-sm);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
.photo-wrapper {
|
||||
position: relative;
|
||||
aspect-ratio: 1;
|
||||
background: linear-gradient(135deg, var(--color-bg-tertiary) 0%, var(--color-border) 100%);
|
||||
border-radius: var(--radius-md);
|
||||
overflow: hidden;
|
||||
margin-bottom: var(--space-sm);
|
||||
box-shadow: var(--shadow-sm);
|
||||
transition: border-radius 0.25s ease-out, margin-bottom 0.25s ease-out;
|
||||
}
|
||||
|
||||
.photo-wrapper img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform var(--transition-slow);
|
||||
background: var(--color-border);
|
||||
}
|
||||
.photo-borderless {
|
||||
border-radius: 0;
|
||||
margin-bottom: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.photo-card:hover .photo-wrapper img {
|
||||
transform: scale(1.08);
|
||||
}
|
||||
.photo-wrapper img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform var(--transition-slow);
|
||||
background: var(--color-border);
|
||||
}
|
||||
|
||||
.photo-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
padding: var(--space-md);
|
||||
text-align: center;
|
||||
word-break: break-word;
|
||||
}
|
||||
.photo-card:hover .photo-wrapper img {
|
||||
transform: scale(1.08);
|
||||
}
|
||||
|
||||
.video-indicator {
|
||||
position: absolute;
|
||||
top: var(--space-sm);
|
||||
right: var(--space-sm);
|
||||
background: var(--color-overlay-dark);
|
||||
color: var(--color-text-inverse);
|
||||
padding: 0.35rem var(--space-sm);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-sm);
|
||||
z-index: 1;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
.photo-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
padding: var(--space-md);
|
||||
text-align: center;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.photo-name {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text);
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding: 0 var(--space-xs);
|
||||
}
|
||||
.video-indicator {
|
||||
position: absolute;
|
||||
top: var(--space-sm);
|
||||
right: var(--space-sm);
|
||||
background: var(--color-overlay-dark);
|
||||
color: var(--color-text-inverse);
|
||||
padding: 0.35rem var(--space-sm);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-sm);
|
||||
z-index: 1;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.photo-name {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text);
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding: 0 var(--space-xs);
|
||||
transition: visibility var(--transition-slow) cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
.photo-name-hide {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -13,6 +13,7 @@
|
||||
* @property {(photoId: number, previewSrc: string) => void} [onUpgradeQuality]
|
||||
* @property {HTMLDivElement | null} [scrollContainer]
|
||||
* @property {HTMLDivElement | null} [loadMoreTrigger]
|
||||
* @property {boolean} borderLess
|
||||
*/
|
||||
|
||||
/** @type {PhotoGridProps} */
|
||||
@@ -24,7 +25,8 @@
|
||||
totalPhotos = 0,
|
||||
onUpgradeQuality,
|
||||
scrollContainer = $bindable(null),
|
||||
loadMoreTrigger = $bindable(null)
|
||||
loadMoreTrigger = $bindable(null),
|
||||
borderLess
|
||||
} = $props();
|
||||
|
||||
function getVisiblePhotos() {
|
||||
@@ -36,9 +38,9 @@
|
||||
<Empty message={m.no_photos()} icon="📷" />
|
||||
{:else}
|
||||
<div class="photo-scroll-container" bind:this={scrollContainer}>
|
||||
<div class="photo-grid">
|
||||
<div class="photo-grid" class:photo-grid-borderless={borderLess}>
|
||||
{#each getVisiblePhotos() as photo (photo.id)}
|
||||
<PhotoCard {photo} {onUpgradeQuality} />
|
||||
<PhotoCard {photo} {onUpgradeQuality} {borderLess} />
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -59,62 +61,67 @@
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.photo-scroll-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scroll-behavior: smooth;
|
||||
min-height: 400px;
|
||||
}
|
||||
.photo-scroll-container {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scroll-behavior: smooth;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.photo-scroll-container::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
.photo-scroll-container::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.photo-scroll-container::-webkit-scrollbar-track {
|
||||
background: var(--color-bg-tertiary);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.photo-scroll-container::-webkit-scrollbar-track {
|
||||
background: var(--color-bg-tertiary);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.photo-scroll-container::-webkit-scrollbar-thumb {
|
||||
background: var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.photo-scroll-container::-webkit-scrollbar-thumb {
|
||||
background: var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
.photo-scroll-container::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--color-text-tertiary);
|
||||
}
|
||||
.photo-scroll-container::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--color-text-tertiary);
|
||||
}
|
||||
|
||||
.photo-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: var(--space-md);
|
||||
padding-bottom: var(--space-xl);
|
||||
}
|
||||
.photo-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||
gap: var(--space-md);
|
||||
padding-bottom: var(--space-xl);
|
||||
transition: gap 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.photo-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
}
|
||||
}
|
||||
.photo-grid-borderless {
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.load-more-trigger,
|
||||
.loading-trigger {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
.photo-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
.loading-more {
|
||||
display: inline-block;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-base);
|
||||
}
|
||||
.load-more-trigger,
|
||||
.loading-trigger {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
}
|
||||
|
||||
.load-complete {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
color: var(--color-success);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
.loading-more {
|
||||
display: inline-block;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-base);
|
||||
}
|
||||
|
||||
.load-complete {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
color: var(--color-success);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
</style>
|
||||
|
||||
95
web/src/lib/components/ui/SegmentedControl.svelte
Normal file
95
web/src/lib/components/ui/SegmentedControl.svelte
Normal file
@@ -0,0 +1,95 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} ToggleOptionItem
|
||||
* @property {string} value - 选项值
|
||||
* @property {string} label - 显示文字
|
||||
* @property {string} [icon] - 图标(emoji 或文字图标)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} SegmentedControlProps
|
||||
* @property {string} value - 当前选中的值
|
||||
* @property {(value: string) => void} onchange
|
||||
* @property {ToggleOptionItem[]} options - 选项列表
|
||||
* @property {'small' | 'medium' | 'large'} [size]
|
||||
*/
|
||||
|
||||
/** @type {SegmentedControlProps} */
|
||||
let { value, onchange, options, size = 'medium' } = $props();
|
||||
</script>
|
||||
|
||||
<div class="segmented-control size-{size}" role="group">
|
||||
{#each options as option (option.value)}
|
||||
<button
|
||||
type="button"
|
||||
class="option"
|
||||
class:active={value === option.value}
|
||||
onclick={() => onchange(option.value)}
|
||||
aria-pressed={value === option.value}
|
||||
>
|
||||
{#if option.icon}
|
||||
<span class="icon">{option.icon}</span>
|
||||
{/if}
|
||||
<span class="label">{option.label}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.segmented-control {
|
||||
display: inline-flex;
|
||||
background: var(--color-bg-tertiary);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 2px;
|
||||
gap: 2px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.option {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: var(--space-xs);
|
||||
padding: 0.375rem 0.75rem;
|
||||
border: none;
|
||||
border-radius: calc(var(--radius-md) - 2px);
|
||||
background: transparent;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: var(--font-weight-medium);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.option:hover:not(:disabled) {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.option.active {
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 1em;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
/* Sizes */
|
||||
.size-small .option {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: var(--font-size-xs);
|
||||
}
|
||||
|
||||
.size-medium .option {
|
||||
padding: 0.375rem 0.75rem;
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.size-large .option {
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: var(--font-size-base);
|
||||
}
|
||||
</style>
|
||||
@@ -4,3 +4,4 @@ export { default as Container } from './Container.svelte';
|
||||
export { default as Grid } from './Grid.svelte';
|
||||
export { default as Empty } from './Empty.svelte';
|
||||
export { default as Loading } from './Loading.svelte';
|
||||
export { default as SegmentedControl } from './SegmentedControl.svelte';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { albums, back, photo_count, loading } from '$lib/paraglide/messages';
|
||||
import { resolve } from '$app/paths';
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
import { Container, PageHeader, BackLink, PhotoGrid, Empty } from '$lib/components';
|
||||
import { Container, PageHeader, BackLink, PhotoGrid, Empty, SegmentedControl } from '$lib/components';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
let hasMore = $derived(data.hasMore ?? false);
|
||||
|
||||
// 所有已加载的照片(支持分页追加)
|
||||
/** @type {import('$lib/api/types').Photo[]} */
|
||||
let allPhotos = $state([]);
|
||||
|
||||
// 分批加载配置 - 前端虚拟滚动
|
||||
@@ -36,6 +37,13 @@
|
||||
// 已升级质量的图片 ID 集合,避免重复升级
|
||||
let upgradedPhotoIds = new SvelteSet();
|
||||
|
||||
let viewMode = $state('card');
|
||||
|
||||
const viewOptions = [
|
||||
{ value: 'card', label: '卡片', icon: '🖼️' },
|
||||
{ value: 'borderless', label: '紧凑', icon: '📐' }
|
||||
];
|
||||
|
||||
// 监听数据变化,重置状态
|
||||
$effect(() => {
|
||||
if (data.photos) {
|
||||
@@ -143,11 +151,22 @@
|
||||
<Container size="wide">
|
||||
<PageHeader
|
||||
title={album?.name || loading()}
|
||||
subtitle={album ? photo_count({ count: data.totalPhotos || allPhotos.length }) : undefined}
|
||||
>
|
||||
<BackLink href={resolve('/')} text={back()} />
|
||||
</PageHeader>
|
||||
|
||||
{#if album && allPhotos.length > 0}
|
||||
<div class="subtitle-bar">
|
||||
<span class="photo-count">{photo_count({ count: data.totalPhotos || allPhotos.length })}</span>
|
||||
<SegmentedControl
|
||||
value={viewMode}
|
||||
onchange={(v) => viewMode = v}
|
||||
options={viewOptions}
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if !album || (allPhotos.length === 0 && !hasMore)}
|
||||
<Empty message={m.no_photos()} icon="📷" />
|
||||
{:else}
|
||||
@@ -160,6 +179,21 @@
|
||||
onUpgradeQuality={upgradePhotoQuality}
|
||||
bind:scrollContainer
|
||||
bind:loadMoreTrigger
|
||||
borderLess={viewMode === 'borderless'}
|
||||
/>
|
||||
{/if}
|
||||
</Container>
|
||||
</Container>
|
||||
|
||||
<style>
|
||||
.subtitle-bar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
.photo-count {
|
||||
font-size: var(--font-size-base);
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user