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

@@ -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;