This commit is contained in:
@@ -5,15 +5,23 @@
|
|||||||
* @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
|
* @property {boolean} [borderLess]
|
||||||
|
* @property {boolean} [waterfall]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @type {PhotoCardProps} */
|
/** @type {PhotoCardProps} */
|
||||||
let { photo, onUpgradeQuality, borderLess } = $props();
|
let { photo, onUpgradeQuality, borderLess = false, waterfall = false } = $props();
|
||||||
|
|
||||||
// 使用 $derived 确保响应式更新
|
// 使用 $derived 确保响应式更新
|
||||||
let previewSrc = $derived(`/api/v1/photo/${photo.id}/preview`);
|
let previewSrc = $derived(`/api/v1/photo/${photo.id}/preview`);
|
||||||
|
|
||||||
|
// 根据原始宽高比计算瀑布流显示比例,防止图片加载前容器塌陷
|
||||||
|
let aspectRatioStyle = $derived(
|
||||||
|
waterfall && photo.width && photo.height
|
||||||
|
? `aspect-ratio: ${photo.width} / ${photo.height};`
|
||||||
|
: ''
|
||||||
|
);
|
||||||
|
|
||||||
function handleMouseEnter() {
|
function handleMouseEnter() {
|
||||||
if (onUpgradeQuality) {
|
if (onUpgradeQuality) {
|
||||||
onUpgradeQuality(photo.id, previewSrc);
|
onUpgradeQuality(photo.id, previewSrc);
|
||||||
@@ -27,8 +35,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a href={resolve(`/photo/${photo.id}`)} class="photo-card">
|
<a href={resolve(`/photo/${photo.id}`)} class="photo-card" class:photo-card-waterfall={waterfall} class:photo-card-compact-waterfall={borderLess && waterfall}>
|
||||||
<div class="photo-wrapper" class:photo-borderless={borderLess}>
|
<div class="photo-wrapper" class:photo-borderless={borderLess} class:photo-waterfall={waterfall} style={aspectRatioStyle}>
|
||||||
{#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">
|
||||||
@@ -49,7 +57,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<p class="photo-name" class:photo-name-hide={borderLess}>{photo.fileName}</p>
|
<p class="photo-name" class:photo-name-hide={borderLess}>{photo.fileName}</p>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -59,6 +67,17 @@
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 瀑布流模式:防止卡片被列截断,并添加间距 */
|
||||||
|
.photo-card-waterfall {
|
||||||
|
break-inside: avoid;
|
||||||
|
margin-bottom: var(--space-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 瀑布流 + 紧凑:无间距 */
|
||||||
|
.photo-card-compact-waterfall {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.photo-wrapper {
|
.photo-wrapper {
|
||||||
position: relative;
|
position: relative;
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
@@ -67,14 +86,20 @@
|
|||||||
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;
|
transition: border-radius 0.25s ease-out, margin-bottom 0.25s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.photo-borderless {
|
.photo-borderless {
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 瀑布流模式:保持原始宽高比 */
|
||||||
|
.photo-waterfall {
|
||||||
|
aspect-ratio: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.photo-wrapper img {
|
.photo-wrapper img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -84,6 +109,13 @@
|
|||||||
background: var(--color-border);
|
background: var(--color-border);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 瀑布流模式下图片高度自适应 */
|
||||||
|
.photo-waterfall img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.photo-card:hover .photo-wrapper img {
|
.photo-card:hover .photo-wrapper img {
|
||||||
transform: scale(1.08);
|
transform: scale(1.08);
|
||||||
}
|
}
|
||||||
@@ -101,6 +133,12 @@
|
|||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 瀑布流模式下 placeholder 默认 4:3 */
|
||||||
|
.photo-waterfall .photo-placeholder {
|
||||||
|
aspect-ratio: 4/3;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.video-indicator {
|
.video-indicator {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: var(--space-sm);
|
top: var(--space-sm);
|
||||||
@@ -122,9 +160,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);
|
transition: visibility var(--transition-slow) cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
}
|
}
|
||||||
.photo-name-hide {
|
.photo-name-hide {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -13,7 +13,8 @@
|
|||||||
* @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
|
* @property {boolean} [borderLess]
|
||||||
|
* @property {boolean} [waterfall]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @type {PhotoGridProps} */
|
/** @type {PhotoGridProps} */
|
||||||
@@ -26,7 +27,8 @@
|
|||||||
onUpgradeQuality,
|
onUpgradeQuality,
|
||||||
scrollContainer = $bindable(null),
|
scrollContainer = $bindable(null),
|
||||||
loadMoreTrigger = $bindable(null),
|
loadMoreTrigger = $bindable(null),
|
||||||
borderLess
|
borderLess = false,
|
||||||
|
waterfall = false
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
function getVisiblePhotos() {
|
function getVisiblePhotos() {
|
||||||
@@ -38,9 +40,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" class:photo-grid-borderless={borderLess}>
|
<div class="photo-grid" class:photo-grid-borderless={borderLess} class:photo-grid-waterfall={waterfall}>
|
||||||
{#each getVisiblePhotos() as photo (photo.id)}
|
{#each getVisiblePhotos() as photo (photo.id)}
|
||||||
<PhotoCard {photo} {onUpgradeQuality} {borderLess} />
|
<PhotoCard {photo} {onUpgradeQuality} {borderLess} {waterfall} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -99,12 +101,36 @@
|
|||||||
gap: 0;
|
gap: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 瀑布流布局 */
|
||||||
|
.photo-grid-waterfall {
|
||||||
|
display: block;
|
||||||
|
column-count: 3;
|
||||||
|
column-gap: var(--space-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 瀑布流 + 紧凑:无间距 */
|
||||||
|
.photo-grid-waterfall.photo-grid-borderless {
|
||||||
|
column-gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.photo-grid-waterfall {
|
||||||
|
column-count: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
.photo-grid {
|
.photo-grid {
|
||||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1200px) {
|
||||||
|
.photo-grid-waterfall {
|
||||||
|
column-count: 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.load-more-trigger,
|
.load-more-trigger,
|
||||||
.loading-trigger {
|
.loading-trigger {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -37,13 +37,21 @@
|
|||||||
// 已升级质量的图片 ID 集合,避免重复升级
|
// 已升级质量的图片 ID 集合,避免重复升级
|
||||||
let upgradedPhotoIds = new SvelteSet();
|
let upgradedPhotoIds = new SvelteSet();
|
||||||
|
|
||||||
let viewMode = $state('card');
|
// 风格模式:卡片 / 紧凑(控制间距、圆角、阴影)
|
||||||
|
let styleMode = $state('card');
|
||||||
|
// 布局模式:砖块 / 瀑布(Grid / Columns)
|
||||||
|
let layoutMode = $state('grid');
|
||||||
|
|
||||||
const viewOptions = [
|
const styleOptions = [
|
||||||
{ value: 'card', label: '卡片', icon: '🖼️' },
|
{ value: 'card', label: '卡片', icon: '🖼️' },
|
||||||
{ value: 'borderless', label: '紧凑', icon: '📐' }
|
{ value: 'borderless', label: '紧凑', icon: '📐' }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const layoutOptions = [
|
||||||
|
{ value: 'grid', label: '砖块', icon: '🧱' },
|
||||||
|
{ value: 'waterfall', label: '瀑布', icon: '🌊' }
|
||||||
|
];
|
||||||
|
|
||||||
// 监听数据变化,重置状态
|
// 监听数据变化,重置状态
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (data.photos) {
|
if (data.photos) {
|
||||||
@@ -158,12 +166,20 @@
|
|||||||
{#if album && allPhotos.length > 0}
|
{#if album && allPhotos.length > 0}
|
||||||
<div class="subtitle-bar">
|
<div class="subtitle-bar">
|
||||||
<span class="photo-count">{photo_count({ count: data.totalPhotos || allPhotos.length })}</span>
|
<span class="photo-count">{photo_count({ count: data.totalPhotos || allPhotos.length })}</span>
|
||||||
<SegmentedControl
|
<div class="controls">
|
||||||
value={viewMode}
|
<SegmentedControl
|
||||||
onchange={(v) => viewMode = v}
|
value={styleMode}
|
||||||
options={viewOptions}
|
onchange={(v) => styleMode = v}
|
||||||
size="small"
|
options={styleOptions}
|
||||||
/>
|
size="small"
|
||||||
|
/>
|
||||||
|
<SegmentedControl
|
||||||
|
value={layoutMode}
|
||||||
|
onchange={(v) => layoutMode = v}
|
||||||
|
options={layoutOptions}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -179,7 +195,8 @@
|
|||||||
onUpgradeQuality={upgradePhotoQuality}
|
onUpgradeQuality={upgradePhotoQuality}
|
||||||
bind:scrollContainer
|
bind:scrollContainer
|
||||||
bind:loadMoreTrigger
|
bind:loadMoreTrigger
|
||||||
borderLess={viewMode === 'borderless'}
|
borderLess={styleMode === 'borderless'}
|
||||||
|
waterfall={layoutMode === 'waterfall'}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</Container>
|
</Container>
|
||||||
@@ -196,4 +213,9 @@
|
|||||||
font-size: var(--font-size-base);
|
font-size: var(--font-size-base);
|
||||||
color: var(--color-text-secondary);
|
color: var(--color-text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--space-sm);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user