// 自定义JavaScript函数 // 显示加载动画 function showLoading() { const loadingElement = document.getElementById('loading'); if (loadingElement) { loadingElement.style.display = 'block'; } } // 隐藏加载动画 function hideLoading() { const loadingElement = document.getElementById('loading'); if (loadingElement) { loadingElement.style.display = 'none'; } } // 显示通知 function showNotification(message, type = 'info') { // 创建通知元素 const alertDiv = document.createElement('div'); alertDiv.className = `alert alert-${type} alert-dismissible fade show`; alertDiv.innerHTML = ` ${message} `; // 插入到页面中 const container = document.querySelector('main') || document.body; container.insertBefore(alertDiv, container.firstChild); // 5秒后自动隐藏 setTimeout(() => { if (alertDiv.parentNode) { alertDiv.remove(); } }, 5000); } // 格式化日期 function formatDate(dateString) { if (!dateString) return '-'; const date = new Date(dateString); return date.toLocaleDateString('zh-CN') + ' ' + date.toLocaleTimeString('zh-CN'); } // 格式化文件大小 function formatFileSize(bytes) { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }