前端实现列表紧凑显示
This commit is contained in:
@@ -5,10 +5,11 @@
|
|||||||
* @typedef {Object} PhotoCardProps
|
* @typedef {Object} PhotoCardProps
|
||||||
* @property {import('$lib/api/types').Photo} photo
|
* @property {import('$lib/api/types').Photo} photo
|
||||||
* @property {(photoId: number, previewSrc: string) => void} [onUpgradeQuality]
|
* @property {(photoId: number, previewSrc: string) => void} [onUpgradeQuality]
|
||||||
|
* @property {boolean} borderLess
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @type {PhotoCardProps} */
|
/** @type {PhotoCardProps} */
|
||||||
let { photo, onUpgradeQuality } = $props();
|
let { photo, onUpgradeQuality, borderLess } = $props();
|
||||||
|
|
||||||
// 使用 $derived 确保响应式更新
|
// 使用 $derived 确保响应式更新
|
||||||
let previewSrc = $derived(`/api/v1/photo/${photo.id}/preview`);
|
let previewSrc = $derived(`/api/v1/photo/${photo.id}/preview`);
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a href={resolve(`/photo/${photo.id}`)} class="photo-card">
|
<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/')}
|
{#if photo.mimeType?.startsWith('video/')}
|
||||||
<div class="video-indicator">🎬</div>
|
<div class="video-indicator">🎬</div>
|
||||||
<div class="photo-placeholder">
|
<div class="photo-placeholder">
|
||||||
@@ -48,7 +49,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<p class="photo-name">{photo.fileName}</p>
|
<p class="photo-name" class:photo-name-hide={borderLess}>{photo.fileName}</p>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -66,6 +67,13 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin-bottom: var(--space-sm);
|
margin-bottom: var(--space-sm);
|
||||||
box-shadow: var(--shadow-sm);
|
box-shadow: var(--shadow-sm);
|
||||||
|
transition: border-radius 0.25s ease-out, margin-bottom 0.25s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.photo-borderless {
|
||||||
|
border-radius: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.photo-wrapper img {
|
.photo-wrapper img {
|
||||||
@@ -114,5 +122,9 @@
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
padding: 0 var(--space-xs);
|
padding: 0 var(--space-xs);
|
||||||
|
transition: visibility var(--transition-slow) cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
}
|
||||||
|
.photo-name-hide {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* @property {(photoId: number, previewSrc: string) => void} [onUpgradeQuality]
|
* @property {(photoId: number, previewSrc: string) => void} [onUpgradeQuality]
|
||||||
* @property {HTMLDivElement | null} [scrollContainer]
|
* @property {HTMLDivElement | null} [scrollContainer]
|
||||||
* @property {HTMLDivElement | null} [loadMoreTrigger]
|
* @property {HTMLDivElement | null} [loadMoreTrigger]
|
||||||
|
* @property {boolean} borderLess
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @type {PhotoGridProps} */
|
/** @type {PhotoGridProps} */
|
||||||
@@ -24,7 +25,8 @@
|
|||||||
totalPhotos = 0,
|
totalPhotos = 0,
|
||||||
onUpgradeQuality,
|
onUpgradeQuality,
|
||||||
scrollContainer = $bindable(null),
|
scrollContainer = $bindable(null),
|
||||||
loadMoreTrigger = $bindable(null)
|
loadMoreTrigger = $bindable(null),
|
||||||
|
borderLess
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
function getVisiblePhotos() {
|
function getVisiblePhotos() {
|
||||||
@@ -36,9 +38,9 @@
|
|||||||
<Empty message={m.no_photos()} icon="📷" />
|
<Empty message={m.no_photos()} icon="📷" />
|
||||||
{:else}
|
{:else}
|
||||||
<div class="photo-scroll-container" bind:this={scrollContainer}>
|
<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)}
|
{#each getVisiblePhotos() as photo (photo.id)}
|
||||||
<PhotoCard {photo} {onUpgradeQuality} />
|
<PhotoCard {photo} {onUpgradeQuality} {borderLess} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -90,6 +92,11 @@
|
|||||||
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
||||||
gap: var(--space-md);
|
gap: var(--space-md);
|
||||||
padding-bottom: var(--space-xl);
|
padding-bottom: var(--space-xl);
|
||||||
|
transition: gap 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.photo-grid-borderless {
|
||||||
|
gap: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
|
|||||||
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 Grid } from './Grid.svelte';
|
||||||
export { default as Empty } from './Empty.svelte';
|
export { default as Empty } from './Empty.svelte';
|
||||||
export { default as Loading } from './Loading.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 { albums, back, photo_count, loading } from '$lib/paraglide/messages';
|
||||||
import { resolve } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { SvelteSet } from 'svelte/reactivity';
|
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();
|
let { data } = $props();
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
let hasMore = $derived(data.hasMore ?? false);
|
let hasMore = $derived(data.hasMore ?? false);
|
||||||
|
|
||||||
// 所有已加载的照片(支持分页追加)
|
// 所有已加载的照片(支持分页追加)
|
||||||
|
/** @type {import('$lib/api/types').Photo[]} */
|
||||||
let allPhotos = $state([]);
|
let allPhotos = $state([]);
|
||||||
|
|
||||||
// 分批加载配置 - 前端虚拟滚动
|
// 分批加载配置 - 前端虚拟滚动
|
||||||
@@ -36,6 +37,13 @@
|
|||||||
// 已升级质量的图片 ID 集合,避免重复升级
|
// 已升级质量的图片 ID 集合,避免重复升级
|
||||||
let upgradedPhotoIds = new SvelteSet();
|
let upgradedPhotoIds = new SvelteSet();
|
||||||
|
|
||||||
|
let viewMode = $state('card');
|
||||||
|
|
||||||
|
const viewOptions = [
|
||||||
|
{ value: 'card', label: '卡片', icon: '🖼️' },
|
||||||
|
{ value: 'borderless', label: '紧凑', icon: '📐' }
|
||||||
|
];
|
||||||
|
|
||||||
// 监听数据变化,重置状态
|
// 监听数据变化,重置状态
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (data.photos) {
|
if (data.photos) {
|
||||||
@@ -143,11 +151,22 @@
|
|||||||
<Container size="wide">
|
<Container size="wide">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={album?.name || loading()}
|
title={album?.name || loading()}
|
||||||
subtitle={album ? photo_count({ count: data.totalPhotos || allPhotos.length }) : undefined}
|
|
||||||
>
|
>
|
||||||
<BackLink href={resolve('/')} text={back()} />
|
<BackLink href={resolve('/')} text={back()} />
|
||||||
</PageHeader>
|
</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)}
|
{#if !album || (allPhotos.length === 0 && !hasMore)}
|
||||||
<Empty message={m.no_photos()} icon="📷" />
|
<Empty message={m.no_photos()} icon="📷" />
|
||||||
{:else}
|
{:else}
|
||||||
@@ -160,6 +179,21 @@
|
|||||||
onUpgradeQuality={upgradePhotoQuality}
|
onUpgradeQuality={upgradePhotoQuality}
|
||||||
bind:scrollContainer
|
bind:scrollContainer
|
||||||
bind:loadMoreTrigger
|
bind:loadMoreTrigger
|
||||||
|
borderLess={viewMode === 'borderless'}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/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