update
This commit is contained in:
@@ -262,7 +262,7 @@ async function loadAlbum(albumId) {
|
||||
function updateAlbumInfo() {
|
||||
document.getElementById('album-title').textContent = currentAlbum.title;
|
||||
|
||||
let infoHtml = `<i class="fas fa-images"></i> 共 ${images.length} 张图片`;
|
||||
let infoHtml = `${images.length} 张图片`;
|
||||
document.getElementById('album-info').innerHTML = infoHtml;
|
||||
|
||||
// 显示相册元数据(人名 + 标签)
|
||||
@@ -316,7 +316,7 @@ function getTagCategory(tag) {
|
||||
return 'default';
|
||||
}
|
||||
|
||||
// 更新相册元数据(人名 + 标签)点击可搜索
|
||||
// 更新相册元数据(人名 + 标签)简洁版:只用颜色区分,不写分类名
|
||||
function updateAlbumMeta() {
|
||||
const metaContainer = document.getElementById('album-meta-tags');
|
||||
if (!metaContainer) return;
|
||||
@@ -337,7 +337,6 @@ function updateAlbumMeta() {
|
||||
if (currentAlbum.tags) {
|
||||
let tagList = [];
|
||||
try {
|
||||
// 格式1: JSON数组 [["标签名", "分类"], ...]
|
||||
const parsed = JSON.parse(currentAlbum.tags);
|
||||
if (Array.isArray(parsed)) {
|
||||
parsed.forEach(item => {
|
||||
@@ -353,7 +352,6 @@ function updateAlbumMeta() {
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 格式2: 逗号分隔字符串
|
||||
currentAlbum.tags.split(',').forEach(tag => {
|
||||
const t = tag.trim();
|
||||
if (t) tagList.push({ text: t, category: getTagCategory(t) });
|
||||
@@ -378,9 +376,8 @@ function updateAlbumMeta() {
|
||||
metaContainer.style.display = 'flex';
|
||||
metaContainer.innerHTML = chips.map(chip => {
|
||||
const icon = chip.type === 'person' ? 'fa-user' : 'fa-tag';
|
||||
// 生成 CSS 类名:人物用 person,标签用 tag-{category}
|
||||
const cssClass = chip.type === 'person' ? 'meta-chip-person' : `meta-chip-tag-${chip.category || 'default'}`;
|
||||
return `<span class="meta-chip ${cssClass}" data-meta-type="${chip.type}" data-meta-query="${encodeURIComponent(chip.query)}">
|
||||
return `<span class="meta-chip ${cssClass}" data-meta-type="${chip.type}" data-meta-query="${encodeURIComponent(chip.query)}" title="点击搜索: ${chip.text}">
|
||||
<i class="fas ${icon}"></i> ${chip.text}
|
||||
</span>`;
|
||||
}).join('');
|
||||
@@ -446,7 +443,7 @@ function displayImages() {
|
||||
// 检查图片是否已被收藏
|
||||
isImageFavorited(image.id || image.original_url);
|
||||
return `
|
||||
<div class="image-item ${orientation}" onclick="openLightbox(${index})">
|
||||
<div class="image-item ${orientation}">
|
||||
<img
|
||||
src="${imageUrl}"
|
||||
${image.id ? `data-image-id="${image.id}"` : ''}
|
||||
@@ -454,6 +451,7 @@ function displayImages() {
|
||||
class="lazy"
|
||||
loading="lazy"
|
||||
onerror="this.src='/assets/placeholder.svg'"
|
||||
onclick="openLightbox(${index})"
|
||||
>
|
||||
<div class="image-caption">
|
||||
${image.width ? `<small>${image.width}×${image.height}</small>` : ''}
|
||||
|
||||
136
assets/js/app.js
136
assets/js/app.js
@@ -109,6 +109,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
initSearch();
|
||||
initInfiniteScroll();
|
||||
initLazyLoading(); // 初始化图片懒加载
|
||||
initSidebarSections(); // 初始化侧边栏区块折叠状态
|
||||
|
||||
// 检查URL中是否有search参数
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
@@ -539,7 +540,10 @@ async function performServerSearch(searchTerm) {
|
||||
|
||||
// 显示服务器搜索结果
|
||||
displayAlbums(serverResults);
|
||||
document.getElementById('stats').innerHTML = `在全站找到 ${serverResults.length} 个包含 "${searchTerm}" 的相册`;
|
||||
const oldStats = document.getElementById('stats');
|
||||
if (oldStats) {
|
||||
oldStats.innerHTML = `在全站找到 ${serverResults.length} 个包含 "${searchTerm}" 的相册`;
|
||||
}
|
||||
|
||||
// 初始化图片懒加载
|
||||
initLazyLoading();
|
||||
@@ -636,11 +640,11 @@ function updateStats(albums) {
|
||||
const oldStats = document.getElementById('stats');
|
||||
if (oldStats) oldStats.innerHTML = `共发现 ${albums.length} 个相册,包含 ${totalImages} 张图片`;
|
||||
|
||||
// 获取人物数量
|
||||
fetch(`${API_BASE}/recommend/popular-persons?limit=1`).then(r => r.ok && r.json()).then(data => {
|
||||
if (data && data.length > 0 && data[0].total) {
|
||||
// 获取人物数量(用 metadata stats API)
|
||||
fetch(`${API_BASE}/metadata/stats`).then(r => r.ok && r.json()).then(data => {
|
||||
if (data && data.total_persons !== undefined) {
|
||||
const statPeople = document.getElementById('stat-people');
|
||||
if (statPeople) statPeople.textContent = data[0].total.toLocaleString();
|
||||
if (statPeople) statPeople.textContent = data.total_persons.toLocaleString();
|
||||
}
|
||||
}).catch(() => {});
|
||||
}
|
||||
@@ -799,14 +803,20 @@ function openAlbum(albumId) {
|
||||
|
||||
// 随机打开相册
|
||||
function openRandomAlbum() {
|
||||
// 添加随机动画效果
|
||||
const randomButton = document.querySelector('.random-button');
|
||||
randomButton.style.transform = 'scale(0.95)';
|
||||
randomButton.disabled = true;
|
||||
|
||||
// 显示加载状态
|
||||
const originalText = randomButton.textContent;
|
||||
randomButton.textContent = '随机加载中...';
|
||||
// 添加随机动画效果 - 兼容侧边栏导航项
|
||||
const navItems = document.querySelectorAll('.nav-item');
|
||||
let randomButton = null;
|
||||
navItems.forEach(item => {
|
||||
if (item.textContent.includes('随机')) randomButton = item;
|
||||
});
|
||||
// 也试试顶部操作按钮
|
||||
if (!randomButton) {
|
||||
randomButton = document.querySelector('.action-btn[onclick*="openRandomAlbum"]');
|
||||
}
|
||||
|
||||
if (randomButton) {
|
||||
randomButton.style.transform = 'scale(0.95)';
|
||||
}
|
||||
|
||||
// 调用新的随机相册API
|
||||
fetch(`${API_BASE}/album/random`)
|
||||
@@ -821,22 +831,22 @@ function openRandomAlbum() {
|
||||
})
|
||||
.then(randomAlbum => {
|
||||
// 恢复按钮状态
|
||||
setTimeout(() => {
|
||||
randomButton.style.transform = '';
|
||||
randomButton.disabled = false;
|
||||
randomButton.textContent = originalText;
|
||||
}, 200);
|
||||
if (randomButton) {
|
||||
setTimeout(() => {
|
||||
randomButton.style.transform = '';
|
||||
}, 200);
|
||||
}
|
||||
|
||||
// 跳转到随机相册
|
||||
window.location.href = `/album?id=${randomAlbum.id}`;
|
||||
})
|
||||
.catch(error => {
|
||||
// 恢复按钮状态
|
||||
setTimeout(() => {
|
||||
randomButton.style.transform = '';
|
||||
randomButton.disabled = false;
|
||||
randomButton.textContent = originalText;
|
||||
}, 200);
|
||||
if (randomButton) {
|
||||
setTimeout(() => {
|
||||
randomButton.style.transform = '';
|
||||
}, 200);
|
||||
}
|
||||
|
||||
alert(error.message);
|
||||
});
|
||||
@@ -847,6 +857,11 @@ function showFavorites() {
|
||||
// 设置当前在收藏页
|
||||
isInFavoritesPage = true;
|
||||
|
||||
// 切换侧边栏选中状态
|
||||
document.querySelectorAll('.nav-item').forEach(item => item.classList.remove('active'));
|
||||
const favNav = document.querySelector('.nav-item[data-view="favorites"]');
|
||||
if (favNav) favNav.classList.add('active');
|
||||
|
||||
// 从后端API获取收藏列表
|
||||
fetch(`${API_BASE}/favorites`)
|
||||
.then(response => {
|
||||
@@ -919,8 +934,10 @@ function displayFavorites(favoriteImages) {
|
||||
`}
|
||||
`;
|
||||
|
||||
// 更新统计信息 - 显示收藏数量
|
||||
document.getElementById('stats').innerHTML = `<div class="favorites-header">
|
||||
// 更新统计信息 - 显示收藏数量(兼容新旧版布局)
|
||||
const statsEl = document.getElementById('stats');
|
||||
if (statsEl) {
|
||||
statsEl.innerHTML = `<div class="favorites-header">
|
||||
<div class="header-content">
|
||||
<div class="header-left">
|
||||
<div class="favorites-icon">
|
||||
@@ -940,6 +957,7 @@ function displayFavorites(favoriteImages) {
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// 初始化图片懒加载,确保收藏的图片被加载
|
||||
initLazyLoading();
|
||||
@@ -959,8 +977,12 @@ function formatDate(dateString) {
|
||||
function backToHome() {
|
||||
// 重置收藏页标记
|
||||
isInFavoritesPage = false;
|
||||
// 重新加载首页相册
|
||||
loadAlbums(true);
|
||||
// 切换导航高亮到首页
|
||||
document.querySelectorAll('.nav-item').forEach(item => {
|
||||
item.classList.toggle('active', item.dataset.view === 'home');
|
||||
});
|
||||
// 清除筛选
|
||||
clearFilter();
|
||||
}
|
||||
|
||||
// 全局变量存储收藏列表和当前预览索引
|
||||
@@ -1241,7 +1263,9 @@ async function loadDiscoverData() {
|
||||
]);
|
||||
|
||||
if (tagsResp.ok) {
|
||||
const tags = await tagsResp.json();
|
||||
const tagsData = await tagsResp.json();
|
||||
// 兼容两种格式:直接数组 或 { total, tags }
|
||||
const tags = Array.isArray(tagsData) ? tagsData : (tagsData.tags || tagsData.items || []);
|
||||
if (tags && tags.length > 0) {
|
||||
renderTagCloud(tags);
|
||||
}
|
||||
@@ -1300,7 +1324,24 @@ function renderTagCloud(tags) {
|
||||
|
||||
// 渲染热门人物(横向滚动条)
|
||||
function renderPeopleCloud(people) {
|
||||
// 新版:横向滚动条
|
||||
// 侧边栏人物列表
|
||||
const sidebarPeople = document.getElementById('sidebar-people');
|
||||
if (sidebarPeople && people && people.length) {
|
||||
sidebarPeople.innerHTML = people.slice(0, 25).map(p => {
|
||||
const name = p.name || p.display_name || '';
|
||||
const albumCount = p.total_albums || 0;
|
||||
const isActive = currentFilter && currentFilter.type === 'person' && currentFilter.value === name;
|
||||
return `<div class="sidebar-person ${isActive ? 'active' : ''}" onclick="filterByPerson('${name}')" title="${albumCount} 个相册">
|
||||
<div class="sidebar-person-avatar">${name.charAt(0)}</div>
|
||||
<div class="sidebar-person-info">
|
||||
<div class="sidebar-person-name">${name}</div>
|
||||
<div class="sidebar-person-count">${albumCount} 相册</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// 横向滚动条
|
||||
const strip = document.getElementById('people-strip');
|
||||
const scroll = document.getElementById('people-scroll');
|
||||
if (strip && scroll && people && people.length) {
|
||||
@@ -1339,6 +1380,32 @@ function renderPeopleCloud(people) {
|
||||
}
|
||||
}
|
||||
|
||||
// 侧边栏区块折叠/展开
|
||||
function toggleSidebarSection(section) {
|
||||
const group = document.querySelector(`.sidebar-section-group [data-section="${section}"]`)?.closest('.sidebar-section-group');
|
||||
if (!group) return;
|
||||
group.classList.toggle('collapsed');
|
||||
// 保存状态到 localStorage
|
||||
try {
|
||||
const state = JSON.parse(localStorage.getItem('sidebarSections') || '{}');
|
||||
state[section] = group.classList.contains('collapsed');
|
||||
localStorage.setItem('sidebarSections', JSON.stringify(state));
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// 初始化侧边栏区块折叠状态
|
||||
function initSidebarSections() {
|
||||
try {
|
||||
const state = JSON.parse(localStorage.getItem('sidebarSections') || '{}');
|
||||
Object.keys(state).forEach(section => {
|
||||
if (state[section]) {
|
||||
const group = document.querySelector(`.sidebar-section-group [data-section="${section}"]`)?.closest('.sidebar-section-group');
|
||||
if (group) group.classList.add('collapsed');
|
||||
}
|
||||
});
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// 按标签筛选
|
||||
async function filterByTag(tag) {
|
||||
currentFilter = { type: 'tag', value: tag };
|
||||
@@ -1372,6 +1439,15 @@ async function filterByPerson(personName) {
|
||||
currentFilter = { type: 'person', value: personName };
|
||||
showFilterStatus(`人物: ${personName}`);
|
||||
|
||||
// 刷新侧边栏人物高亮
|
||||
try {
|
||||
const peopleResp = await fetch(`${API_BASE}/recommend/popular-persons?limit=30`);
|
||||
if (peopleResp.ok) {
|
||||
const peopleData = await peopleResp.json();
|
||||
renderPeopleCloud(peopleData);
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
try {
|
||||
showSkeleton(6);
|
||||
const response = await fetch(`${API_BASE}/people/search?q=${encodeURIComponent(personName)}`);
|
||||
@@ -1489,6 +1565,8 @@ function switchView(view) {
|
||||
|
||||
if (view === 'home') {
|
||||
backToHome();
|
||||
} else if (view === 'favorites') {
|
||||
showFavorites();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user