update
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user