app.js•1.9 kB
/**
* Memory Bank 首页脚本
*/
document.addEventListener('DOMContentLoaded', function() {
// 平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (!targetId || targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (!targetElement) return;
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
});
});
// 初始化工具提示
const tooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]');
if (typeof bootstrap !== 'undefined' && tooltips.length > 0) {
Array.from(tooltips).forEach(tooltip => {
try {
new bootstrap.Tooltip(tooltip);
} catch (e) {
console.error('Bootstrap Tooltip initialization error:', e);
}
});
}
// 检测功能可用性
const apiStatus = document.getElementById('apiStatus');
if (apiStatus) {
fetch('/api/status')
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
apiStatus.classList.add('text-success');
apiStatus.textContent = '可用';
} else {
apiStatus.classList.add('text-warning');
apiStatus.textContent = '部分可用';
}
})
.catch(error => {
apiStatus.classList.add('text-danger');
apiStatus.textContent = '不可用';
console.error('API状态检查失败:', error);
});
}
});