优化web逻辑
This commit is contained in:
@@ -2722,30 +2722,69 @@ function toggleSidebar() {
|
||||
// 响应式处理
|
||||
function handleResponsive() {
|
||||
const toggleBtn = document.getElementById('toggle-sidebar');
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
|
||||
toggleBtn.addEventListener('click', toggleSidebar);
|
||||
|
||||
// 初始状态处理
|
||||
if (window.innerWidth < 1024) {
|
||||
document.getElementById('sidebar').classList.add('-translate-x-full');
|
||||
function updateSidebarState() {
|
||||
if (window.innerWidth < 1024) {
|
||||
sidebar.classList.add('-translate-x-full');
|
||||
} else {
|
||||
sidebar.classList.remove('-translate-x-full');
|
||||
}
|
||||
}
|
||||
|
||||
updateSidebarState();
|
||||
|
||||
// 窗口大小改变时处理
|
||||
window.addEventListener('resize', () => {
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
if (window.innerWidth >= 1024) {
|
||||
sidebar.classList.remove('-translate-x-full');
|
||||
}
|
||||
updateSidebarState();
|
||||
|
||||
// 更新图表大小
|
||||
// 更新所有图表大小
|
||||
if (dnsRequestsChart) {
|
||||
dnsRequestsChart.update();
|
||||
}
|
||||
|
||||
if (ratioChart) {
|
||||
ratioChart.update();
|
||||
}
|
||||
if (queryTypeChart) {
|
||||
queryTypeChart.update();
|
||||
}
|
||||
if (detailedDnsRequestsChart) {
|
||||
detailedDnsRequestsChart.update();
|
||||
}
|
||||
// 更新统计卡片图表
|
||||
Object.values(statCardCharts).forEach(chart => {
|
||||
if (chart) {
|
||||
chart.update();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 添加触摸事件支持,用于移动端
|
||||
let touchStartX = 0;
|
||||
let touchEndX = 0;
|
||||
|
||||
document.addEventListener('touchstart', (e) => {
|
||||
touchStartX = e.changedTouches[0].screenX;
|
||||
}, false);
|
||||
|
||||
document.addEventListener('touchend', (e) => {
|
||||
touchEndX = e.changedTouches[0].screenX;
|
||||
handleSwipe();
|
||||
}, false);
|
||||
|
||||
function handleSwipe() {
|
||||
// 从左向右滑动,打开侧边栏
|
||||
if (touchEndX - touchStartX > 50 && window.innerWidth < 1024) {
|
||||
sidebar.classList.remove('-translate-x-full');
|
||||
}
|
||||
// 从右向左滑动,关闭侧边栏
|
||||
if (touchStartX - touchEndX > 50 && window.innerWidth < 1024) {
|
||||
sidebar.classList.add('-translate-x-full');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加重试功能
|
||||
|
||||
Reference in New Issue
Block a user