This commit is contained in:
lychang
2026-07-19 15:03:13 +08:00
parent f5336a4ea2
commit b915e69222
16 changed files with 332 additions and 2032 deletions

View File

@@ -18,6 +18,7 @@
<div class="album-info" id="album-info">
<i class="fas fa-images"></i> 正在加载...
</div>
<div class="album-meta-tags" id="album-meta-tags"></div>
</div>
<div class="images-grid" id="images-container">
@@ -78,6 +79,6 @@
</div>
</div>
<script src="/assets/js/album.js"></script>
<script src="/assets/js/album.js?v=4"></script>
</body>
</html>

View File

@@ -72,7 +72,7 @@ body {
text-align: center;
color: var(--text-light);
font-size: 1.2rem;
margin-bottom: 40px;
margin-bottom: 20px;
background: var(--white);
padding: 20px;
border-radius: var(--border-radius);
@@ -83,6 +83,57 @@ body {
margin-right: auto;
}
/* 相册元数据标签(人名 + 标签) */
.album-meta-tags {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
margin: 0 auto 40px;
max-width: 800px;
}
.meta-chip {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 6px 14px;
border-radius: 20px;
font-size: 0.85rem;
cursor: pointer;
transition: all 0.2s ease;
user-select: none;
border: 1px solid transparent;
}
.meta-chip i {
font-size: 0.75rem;
}
.meta-chip-person {
background: #dbeafe;
color: #1e40af;
border-color: #bfdbfe;
}
.meta-chip-person:hover {
background: #bfdbfe;
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}
.meta-chip-tag {
background: #f0fdf4;
color: #166534;
border-color: #bbf7d0;
}
.meta-chip-tag:hover {
background: #dcfce7;
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(22, 163, 74, 0.2);
}
/* 智能图片网格布局 - 自适应瀑布流效果 */
.images-grid {
display: grid;
@@ -392,6 +443,10 @@ body {
.album-info {
font-size: 1.1rem;
padding: 18px;
margin-bottom: 18px;
}
.album-meta-tags {
margin-bottom: 35px;
}
@@ -441,7 +496,18 @@ body {
.album-info {
font-size: 1rem;
padding: 15px;
margin-bottom: 15px;
}
.album-meta-tags {
gap: 8px;
margin-bottom: 30px;
padding: 0 10px;
}
.meta-chip {
padding: 5px 12px;
font-size: 0.8rem;
}
.images-grid {
@@ -523,7 +589,18 @@ body {
.album-info {
font-size: 0.9rem;
padding: 12px;
margin-bottom: 12px;
}
.album-meta-tags {
gap: 6px;
margin-bottom: 25px;
padding: 0 8px;
}
.meta-chip {
padding: 4px 10px;
font-size: 0.75rem;
}
.images-grid {

View File

@@ -1168,6 +1168,7 @@ body {
transition: all 0.3s ease;
position: relative;
border: 1px solid var(--medium-gray);
cursor: pointer;
}
.album-card:hover {
transform: translateY(-8px);
@@ -1196,7 +1197,7 @@ body {
.album-info {
padding: 25px;
}
.album-info h2 {
.album-info h3 {
font-size: 1.4rem;
margin-bottom: 12px;
color: var(--text-dark);
@@ -1211,7 +1212,6 @@ body {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
color: var(--text-light);
font-size: 0.9rem;
}
@@ -1220,25 +1220,6 @@ body {
align-items: center;
gap: 6px;
}
.view-button {
display: block;
text-align: center;
padding: 14px;
background: linear-gradient(135deg, var(--secondary-blue) 0%, var(--primary-blue) 100%);
color: var(--white);
text-decoration: none;
border-radius: 10px;
font-weight: 600;
transition: all 0.3s ease;
border: none;
cursor: pointer;
font-size: 1rem;
}
.view-button:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
background: linear-gradient(135deg, var(--primary-blue) 0%, var(--secondary-blue) 100%);
}
.no-results {
text-align: center;
@@ -1431,7 +1412,7 @@ body {
padding: 20px;
}
.album-info h2 {
.album-info h3 {
font-size: 1.2rem;
}
@@ -1440,11 +1421,6 @@ body {
align-items: flex-start;
gap: 8px;
}
.view-button {
padding: 12px;
font-size: 0.9rem;
}
}
@media (max-width: 480px) {
@@ -1516,7 +1492,7 @@ body {
padding: 15px;
}
.album-info h2 {
.album-info h3 {
font-size: 1.1rem;
}
@@ -1524,11 +1500,6 @@ body {
font-size: 0.8rem;
}
.view-button {
padding: 10px;
font-size: 0.85rem;
}
.loading {
padding: 40px 15px;
font-size: 1rem;
@@ -1559,14 +1530,6 @@ body {
transform: scale(0.98);
box-shadow: var(--shadow-md);
}
.view-button:hover {
transform: none;
}
.view-button:active {
transform: scale(0.95);
}
}
/* 高分辨率屏幕优化 */
@@ -1661,8 +1624,7 @@ body {
/* 打印样式 */
@media print {
.search-container,
.view-button {
.search-container {
display: none;
}

View File

@@ -41,6 +41,6 @@
</div>
</div>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/app.js?v=4"></script>
</body>
</html>

View File

@@ -261,11 +261,89 @@ async function loadAlbum(albumId) {
// 更新相册信息
function updateAlbumInfo() {
document.getElementById('album-title').textContent = currentAlbum.title;
document.getElementById('album-info').innerHTML =
`<i class="fas fa-images"></i> 共 ${images.length} 张图片`;
let infoHtml = `<i class="fas fa-images"></i> 共 ${images.length} 张图片`;
document.getElementById('album-info').innerHTML = infoHtml;
// 显示相册元数据(人名 + 标签)
updateAlbumMeta();
document.title = `${currentAlbum.title} - 图片展示服务`;
}
// 更新相册元数据(人名 + 标签)点击可搜索
function updateAlbumMeta() {
const metaContainer = document.getElementById('album-meta-tags');
if (!metaContainer) return;
let chips = [];
// 添加人名标签
if (currentAlbum.person_name_cleaned) {
chips.push({
text: currentAlbum.person_name_cleaned,
type: 'person',
query: currentAlbum.person_name_cleaned
});
}
// 添加标签
if (currentAlbum.tags) {
try {
const tags = JSON.parse(currentAlbum.tags);
if (Array.isArray(tags)) {
tags.forEach(tag => {
chips.push({
text: tag,
type: 'tag',
query: tag
});
});
}
} catch (e) {
// 非JSON格式,当作逗号分隔
currentAlbum.tags.split(',').forEach(tag => {
const t = tag.trim();
if (t) {
chips.push({
text: t,
type: 'tag',
query: t
});
}
});
}
}
if (chips.length === 0) {
metaContainer.style.display = 'none';
return;
}
metaContainer.style.display = 'flex';
metaContainer.innerHTML = chips.map(chip => {
const icon = chip.type === 'person' ? 'fa-user' : 'fa-tag';
return `<span class="meta-chip meta-chip-${chip.type}" data-meta-type="${chip.type}" data-meta-query="${encodeURIComponent(chip.query)}">
<i class="fas ${icon}"></i> ${chip.text}
</span>`;
}).join('');
}
// 事件委托:点击元数据标签
document.addEventListener('click', function(e) {
const chip = e.target.closest('.meta-chip');
if (!chip) return;
const query = chip.dataset.metaQuery;
if (query) {
searchByMeta(query);
}
});
// 点击元数据标签搜索
function searchByMeta(encodedQuery) {
window.location.href = `/?search=${encodedQuery}`;
}
// 智能判断图片方向 - 更精确的判断逻辑
function getImageOrientation(width, height) {
if (!width || !height) return 'square';
@@ -708,8 +786,12 @@ function toggleFavorite(event, imageIndex) {
return;
}
// 找到按钮元素(event.target 可能是 i 图标)
const btn = event.target.closest('.favorite-btn');
if (!btn) return;
// 检查当前收藏状态
const isFavorited = event.target.classList.contains('favorited');
const isFavorited = btn.classList.contains('favorited');
if (isFavorited) {
// 取消收藏
@@ -723,7 +805,7 @@ function toggleFavorite(event, imageIndex) {
return response.json();
})
.then(() => {
event.target.classList.remove('favorited');
btn.classList.remove('favorited');
showFavoriteToast('已取消收藏', false);
})
.catch(error => {
@@ -750,7 +832,7 @@ function toggleFavorite(event, imageIndex) {
return response.json();
})
.then(() => {
event.target.classList.add('favorited');
btn.classList.add('favorited');
showFavoriteToast('已添加到收藏夹', true);
})
.catch(error => {
@@ -835,4 +917,5 @@ window.openLightbox = openLightbox;
window.closeLightbox = closeLightbox;
window.prevImage = prevImage;
window.nextImage = nextImage;
window.toggleFavorite = toggleFavorite;
window.toggleFavorite = toggleFavorite;
window.addToFavoritesFromLightbox = addToFavoritesFromLightbox;

View File

@@ -99,10 +99,21 @@ document.addEventListener('DOMContentLoaded', function () {
document.body.classList.add('touch-device');
}
loadAlbums();
initSearch();
initInfiniteScroll();
initLazyLoading(); // 初始化图片懒加载
// 检查URL中是否有search参数
const urlParams = new URLSearchParams(window.location.search);
const searchQuery = urlParams.get('search');
if (searchQuery) {
const searchInput = document.getElementById('search-input');
searchInput.value = searchQuery;
// 直接搜索,不先加载全部相册
searchAlbums();
} else {
loadAlbums();
}
});
// 初始化搜索功能
@@ -355,7 +366,7 @@ function appendAlbums(albums) {
const createdDate = new Date(album.created_at).toLocaleDateString('zh-CN');
return `
<div class="album-card" data-album-id="${album.id}">
<div class="album-card" data-album-id="${album.id}" onclick="openAlbum('${album.id}')">
<div class="album-cover">
<img
src="${coverImageUrl}"
@@ -371,9 +382,6 @@ function appendAlbums(albums) {
<span><i class="fas fa-images"></i> ${album.image_count} 张图片</span>
<span><i class="fas fa-calendar"></i> ${createdDate}</span>
</div>
<a href="/album?id=${album.id}" class="view-button">
<i class="fas fa-eye"></i> 查看相册
</a>
</div>
</div>
`;
@@ -555,7 +563,7 @@ function displayAlbums(albums) {
const createdDate = new Date(album.created_at).toLocaleDateString('zh-CN');
return `
<div class="album-card" data-album-id="${album.id}">
<div class="album-card" data-album-id="${album.id}" onclick="openAlbum('${album.id}')">
<div class="album-cover">
<img
src="${coverImageUrl}"
@@ -571,9 +579,6 @@ function displayAlbums(albums) {
<span><i class="fas fa-images"></i> ${album.image_count} 张图片</span>
<span><i class="fas fa-calendar"></i> ${createdDate}</span>
</div>
<a href="/album?id=${album.id}" class="view-button">
<i class="fas fa-eye"></i> 查看相册
</a>
</div>
</div>
`;
@@ -759,6 +764,11 @@ preloadCriticalResources();
// 优化滚动性能
optimizeScrollPerformance();
// 打开相册详情
function openAlbum(albumId) {
window.location.href = `/album?id=${albumId}`;
}
// 随机打开相册
function openRandomAlbum() {
// 添加随机动画效果
@@ -818,12 +828,7 @@ function showFavorites() {
return response.json();
})
.then(favoriteImages => {
if (favoriteImages.length === 0) {
alert('收藏夹为空,快去收藏一些喜欢的图片吧!');
return;
}
// 创建收藏夹页面或跳转到收藏夹视图
// 始终显示收藏夹视图(包括空状态)
displayFavorites(favoriteImages);
})
.catch(error => {
@@ -1197,4 +1202,11 @@ function openFavoriteImage(favoriteId) {
// 导出函数供全局使用
window.searchAlbums = searchAlbums;
window.openRandomAlbum = openRandomAlbum;
window.showFavorites = showFavorites;
window.showFavorites = showFavorites;
window.openAlbum = openAlbum;
window.backToHome = backToHome;
window.loadAlbums = loadAlbums;
window.removeFavorite = removeFavorite;
window.previewFavorite = previewFavorite;
window.openFavoriteImage = openFavoriteImage;
window.removeFavoriteFromPreview = removeFavoriteFromPreview;