update code level
This commit is contained in:
@@ -1247,9 +1247,43 @@ body {
|
||||
.search-hint h3 {
|
||||
color: var(--text-dark);
|
||||
margin-bottom: 15px;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
/* 加载状态样式 */
|
||||
.loading-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-light);
|
||||
font-size: 1.2rem;
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.loading-state .fa-spinner {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 20px;
|
||||
color: var(--secondary-blue);
|
||||
}
|
||||
|
||||
.loading-state p {
|
||||
margin-bottom: 20px;
|
||||
color: var(--text-dark);
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 6px;
|
||||
background-color: var(--light-gray);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress {
|
||||
height: 100%;
|
||||
background: linear-gradient(135deg, var(--secondary-blue) 0%, var(--primary-blue) 100%);
|
||||
border-radius: 3px;
|
||||
transition: width 0.3s ease;}
|
||||
|
||||
.search-hint p {
|
||||
margin-bottom: 15px;
|
||||
font-weight: 500;
|
||||
|
||||
@@ -37,7 +37,12 @@ function initSearch() {
|
||||
// 防抖搜索
|
||||
searchInput.addEventListener('input', function () {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(debouncedSearch, 300);
|
||||
|
||||
// 优化:根据输入长度动态调整延迟
|
||||
const inputLength = this.value.length;
|
||||
const debounceDelay = inputLength > 3 ? 200 : 500; // 长文本快速搜索,短文本慢速搜索
|
||||
|
||||
searchTimeout = setTimeout(debouncedSearch, debounceDelay);
|
||||
});
|
||||
|
||||
// 移动端优化:搜索框聚焦时自动滚动到可视区域
|
||||
@@ -128,6 +133,22 @@ function showSkeleton(count = 6) {
|
||||
`).join('');
|
||||
}
|
||||
|
||||
// 显示详细加载状态
|
||||
function showLoadingState(message = '加载中...', progress = 0) {
|
||||
const container = document.getElementById('albums-container');
|
||||
const progressWidth = Math.min(Math.max(progress, 0), 100);
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="loading-state">
|
||||
<i class="fas fa-spinner fa-spin"></i>
|
||||
<p>${message}</p>
|
||||
<div class="progress-bar">
|
||||
<div class="progress" style="width: ${progressWidth}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// 显示加载更多指示器
|
||||
function showLoadingMore() {
|
||||
const container = document.getElementById('albums-container');
|
||||
@@ -398,8 +419,8 @@ function initLazyLoading() {
|
||||
}
|
||||
});
|
||||
}, {
|
||||
rootMargin: '100px 0px', // 提前100px开始加载
|
||||
threshold: 0.01
|
||||
rootMargin: '50px', // 优化:提前50px开始加载
|
||||
threshold: 0.1 // 优化:降低触发阈值
|
||||
});
|
||||
}
|
||||
|
||||
@@ -456,17 +477,30 @@ async function searchAlbums() {
|
||||
// 性能监控
|
||||
function logPerformance() {
|
||||
if ('performance' in window) {
|
||||
window.addEventListener('load', () => {
|
||||
setTimeout(() => {
|
||||
const navigationTiming = performance.getEntriesByType('navigation')[0];
|
||||
if (navigationTiming && navigationTiming.loadEventEnd && navigationTiming.navigationStart) {
|
||||
const loadTime = navigationTiming.loadEventEnd - navigationTiming.navigationStart;
|
||||
console.log('页面加载时间:', loadTime, 'ms');
|
||||
// 使用更可靠的方式获取页面加载时间
|
||||
const calculateLoadTime = () => {
|
||||
const navigationTiming = performance.getEntriesByType('navigation')[0];
|
||||
if (navigationTiming && navigationTiming.loadEventEnd > 0 && navigationTiming.navigationStart > 0) {
|
||||
const loadTime = navigationTiming.loadEventEnd - navigationTiming.navigationStart;
|
||||
console.log('页面加载时间:', loadTime, 'ms');
|
||||
} else {
|
||||
// 备用方案:使用DOMContentLoaded时间
|
||||
const domContentLoadedTime = performance.timing?.domContentLoadedEventEnd - performance.timing?.navigationStart;
|
||||
if (domContentLoadedTime && domContentLoadedTime > 0) {
|
||||
console.log('DOM加载时间:', domContentLoadedTime, 'ms');
|
||||
} else {
|
||||
console.log('页面加载时间: 无法计算');
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 如果页面已经加载完成,直接计算
|
||||
if (document.readyState === 'complete') {
|
||||
calculateLoadTime();
|
||||
} else {
|
||||
// 否则等待页面加载完成
|
||||
window.addEventListener('load', calculateLoadTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,18 +520,18 @@ function preventDoubleTapZoom() {
|
||||
|
||||
// 预加载关键资源
|
||||
function preloadCriticalResources() {
|
||||
// 预加载关键CSS和字体
|
||||
const criticalResources = [
|
||||
'/assets/css/font-awesome.css',
|
||||
'/assets/css/style.css',
|
||||
'/assets/webfonts/fa-solid-900.woff2'
|
||||
// 预加载字体文件(CSS文件不应该预加载,因为已经在HTML中引用了)
|
||||
const fontResources = [
|
||||
'/assets/webfonts/fa-solid-900.woff2',
|
||||
'/assets/webfonts/fa-brands-400.woff2',
|
||||
'/assets/webfonts/fa-regular-400.woff2'
|
||||
];
|
||||
|
||||
criticalResources.forEach(resource => {
|
||||
fontResources.forEach(resource => {
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'preload';
|
||||
link.href = resource;
|
||||
link.as = resource.endsWith('.css') ? 'style' : 'font';
|
||||
link.as = 'font';
|
||||
link.crossOrigin = 'anonymous';
|
||||
document.head.appendChild(link);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user