// 操作日志页面JavaScript document.addEventListener('DOMContentLoaded', function() { // 初始化 initializeLogManagement(); }); // 初始化日志管理功能 function initializeLogManagement() { // 添加事件监听器 setupEventListeners(); // 初始化工具提示 initializeTooltips(); // 初始化表格 initializeTable(); } // 设置事件监听器 function setupEventListeners() { // 搜索表单提交 const searchForm = document.querySelector('form[method="GET"]'); if (searchForm) { searchForm.addEventListener('submit', function(e) { // 可以在这里添加搜索前的验证 }); } // 用户类型筛选变更 const userTypeSelect = document.getElementById('user_type'); if (userTypeSelect) { userTypeSelect.addEventListener('change', function() { // 自动提交表单 this.form.submit(); }); } // 操作类型输入框 const actionInput = document.getElementById('action'); if (actionInput) { // 添加防抖搜索 let searchTimer; actionInput.addEventListener('input', function() { clearTimeout(searchTimer); searchTimer = setTimeout(() => { // 可以实现实时搜索 }, 500); }); } } // 初始化工具提示 function initializeTooltips() { // 为用户代理字段添加工具提示 const userAgentElements = document.querySelectorAll('.user-agent'); userAgentElements.forEach(element => { if (element.title) { // 使用Bootstrap的tooltip new bootstrap.Tooltip(element); } }); } // 初始化表格 function initializeTable() { // 添加表格行点击事件 const tableRows = document.querySelectorAll('.table tbody tr'); tableRows.forEach(row => { row.addEventListener('click', function(e) { // 如果点击的是按钮,不触发行点击事件 if (e.target.tagName === 'BUTTON' || e.target.closest('button')) { return; } // 高亮选中行 tableRows.forEach(r => r.classList.remove('table-active')); this.classList.add('table-active'); }); }); } // 查看日志详情 function viewLogDetail(logId) { // 发送AJAX请求获取日志详情 fetch(`/admin/logs/${logId}/detail`) .then(response => response.json()) .then(data => { if (data.success) { showLogDetailModal(data.log); } else { showError('获取日志详情失败: ' + data.message); } }) .catch(error => { console.error('Error:', error); showError('网络错误,请重试'); }); } // 显示日志详情模态框 function showLogDetailModal(log) { const modalHtml = `