修复服务器重启时端口被占用和数据保存问题
This commit is contained in:
@@ -205,12 +205,7 @@
|
||||
<span>Hosts管理</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#blacklists" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100 rounded-md transition-all">
|
||||
<i class="fa fa-ban mr-3 text-lg"></i>
|
||||
<span>黑名单管理</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#query" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100 rounded-md transition-all">
|
||||
<i class="fa fa-search mr-3 text-lg"></i>
|
||||
@@ -843,14 +838,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="blacklists-content" class="hidden">
|
||||
<!-- 黑名单管理页面内容 -->
|
||||
<div class="bg-white rounded-lg p-6 card-shadow">
|
||||
<h3 class="text-lg font-semibold mb-6">黑名单管理</h3>
|
||||
<!-- 这里将添加黑名单管理相关内容 -->
|
||||
<p>黑名单管理页面内容待实现</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="query-content" class="hidden space-y-6">
|
||||
<!-- DNS查询表单 -->
|
||||
|
||||
@@ -2708,77 +2708,105 @@ function handlePageSwitch() {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理hash变化
|
||||
function handleHashChange() {
|
||||
let hash = window.location.hash;
|
||||
|
||||
// 如果没有hash,默认设置为#dashboard
|
||||
if (!hash) {
|
||||
hash = '#dashboard';
|
||||
window.location.hash = hash;
|
||||
return;
|
||||
}
|
||||
|
||||
const targetId = hash.substring(1);
|
||||
|
||||
// 查找对应的菜单项
|
||||
let targetMenuItem = null;
|
||||
menuItems.forEach(item => {
|
||||
if (item.getAttribute('href') === hash) {
|
||||
targetMenuItem = item;
|
||||
}
|
||||
});
|
||||
|
||||
// 如果找到了对应的菜单项,切换页面
|
||||
if (targetMenuItem) {
|
||||
switchPage(targetId, targetMenuItem);
|
||||
} else {
|
||||
// 如果没有找到对应的菜单项,尝试显示对应的内容
|
||||
const contentElement = document.getElementById(`${targetId}-content`);
|
||||
if (contentElement) {
|
||||
// 隐藏所有内容
|
||||
document.querySelectorAll('[id$="-content"]').forEach(content => {
|
||||
content.classList.add('hidden');
|
||||
});
|
||||
|
||||
// 显示目标内容
|
||||
contentElement.classList.remove('hidden');
|
||||
|
||||
// 查找对应的菜单项并更新活动状态
|
||||
menuItems.forEach(item => {
|
||||
item.classList.remove('sidebar-item-active');
|
||||
if (item.getAttribute('href') === hash) {
|
||||
item.classList.add('sidebar-item-active');
|
||||
// 更新页面标题
|
||||
document.getElementById('page-title').textContent = item.querySelector('span').textContent;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 如果没有找到对应的内容,默认显示dashboard
|
||||
window.location.hash = '#dashboard';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化hash路由
|
||||
function initHashRoute() {
|
||||
handleHashChange();
|
||||
}
|
||||
|
||||
// 监听hash变化事件
|
||||
window.addEventListener('hashchange', handleHashChange);
|
||||
|
||||
menuItems.forEach(item => {
|
||||
item.addEventListener('click', (e) => {
|
||||
// 允许默认的hash变化
|
||||
// 页面切换会由hashchange事件处理
|
||||
});
|
||||
});
|
||||
|
||||
// 初始化hash路由
|
||||
initHashRoute();
|
||||
}
|
||||
|
||||
// 处理hash变化 - 全局函数,确保在页面加载时就能被调用
|
||||
function handleHashChange() {
|
||||
let hash = window.location.hash;
|
||||
|
||||
// 如果没有hash,默认设置为#dashboard
|
||||
if (!hash) {
|
||||
hash = '#dashboard';
|
||||
window.location.hash = hash;
|
||||
return;
|
||||
}
|
||||
|
||||
const targetId = hash.substring(1);
|
||||
const menuItems = document.querySelectorAll('nav a');
|
||||
|
||||
// 首先检查是否存在对应的内容元素
|
||||
const contentElement = document.getElementById(`${targetId}-content`);
|
||||
|
||||
// 查找对应的菜单项
|
||||
let targetMenuItem = null;
|
||||
menuItems.forEach(item => {
|
||||
if (item.getAttribute('href') === hash) {
|
||||
targetMenuItem = item;
|
||||
}
|
||||
});
|
||||
|
||||
// 如果找到了对应的内容元素,直接显示
|
||||
if (contentElement) {
|
||||
// 隐藏所有内容
|
||||
document.querySelectorAll('[id$="-content"]').forEach(content => {
|
||||
content.classList.add('hidden');
|
||||
});
|
||||
|
||||
// 显示目标内容
|
||||
contentElement.classList.remove('hidden');
|
||||
|
||||
// 更新活动菜单项和页面标题
|
||||
menuItems.forEach(item => {
|
||||
item.classList.remove('sidebar-item-active');
|
||||
});
|
||||
|
||||
if (targetMenuItem) {
|
||||
targetMenuItem.classList.add('sidebar-item-active');
|
||||
// 更新页面标题
|
||||
const pageTitle = targetMenuItem.querySelector('span').textContent;
|
||||
document.getElementById('page-title').textContent = pageTitle;
|
||||
} else {
|
||||
// 如果没有找到对应的菜单项,尝试根据hash更新页面标题
|
||||
const titleElement = document.getElementById(`${targetId}-title`);
|
||||
if (titleElement) {
|
||||
document.getElementById('page-title').textContent = titleElement.textContent;
|
||||
}
|
||||
}
|
||||
} else if (targetMenuItem) {
|
||||
// 隐藏所有内容
|
||||
document.querySelectorAll('[id$="-content"]').forEach(content => {
|
||||
content.classList.add('hidden');
|
||||
});
|
||||
|
||||
// 显示目标内容
|
||||
document.getElementById(`${targetId}-content`).classList.remove('hidden');
|
||||
|
||||
// 更新页面标题
|
||||
document.getElementById('page-title').textContent = targetMenuItem.querySelector('span').textContent;
|
||||
|
||||
// 更新活动菜单项
|
||||
menuItems.forEach(item => {
|
||||
item.classList.remove('sidebar-item-active');
|
||||
});
|
||||
targetMenuItem.classList.add('sidebar-item-active');
|
||||
|
||||
// 侧边栏切换(移动端)
|
||||
if (window.innerWidth < 1024) {
|
||||
toggleSidebar();
|
||||
}
|
||||
} else {
|
||||
// 如果既没有找到内容元素也没有找到菜单项,默认显示dashboard
|
||||
window.location.hash = '#dashboard';
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化hash路由
|
||||
function initHashRoute() {
|
||||
handleHashChange();
|
||||
}
|
||||
|
||||
// 监听hash变化事件 - 全局事件监听器
|
||||
window.addEventListener('hashchange', handleHashChange);
|
||||
|
||||
// 初始化hash路由 - 确保在页面加载时就能被调用
|
||||
initHashRoute();
|
||||
|
||||
// 侧边栏切换
|
||||
function toggleSidebar() {
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
|
||||
@@ -8,7 +8,6 @@ function setupNavigation() {
|
||||
document.getElementById('dashboard-content'),
|
||||
document.getElementById('shield-content'),
|
||||
document.getElementById('hosts-content'),
|
||||
document.getElementById('blacklists-content'),
|
||||
document.getElementById('query-content'),
|
||||
document.getElementById('config-content')
|
||||
];
|
||||
@@ -16,30 +15,15 @@ function setupNavigation() {
|
||||
|
||||
menuItems.forEach((item, index) => {
|
||||
item.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
// 允许浏览器自动更新地址栏中的hash,不阻止默认行为
|
||||
|
||||
// 更新活跃状态
|
||||
menuItems.forEach(menuItem => {
|
||||
menuItem.classList.remove('sidebar-item-active');
|
||||
});
|
||||
item.classList.add('sidebar-item-active');
|
||||
|
||||
// 隐藏所有内容部分
|
||||
contentSections.forEach(section => {
|
||||
section.classList.add('hidden');
|
||||
});
|
||||
|
||||
// 显示对应内容部分
|
||||
const target = item.getAttribute('href').substring(1);
|
||||
const activeContent = document.getElementById(`${target}-content`);
|
||||
if (activeContent) {
|
||||
activeContent.classList.remove('hidden');
|
||||
// 移动端点击菜单项后自动关闭侧边栏
|
||||
if (window.innerWidth < 768) {
|
||||
closeSidebar();
|
||||
}
|
||||
|
||||
// 更新页面标题
|
||||
pageTitle.textContent = item.querySelector('span').textContent;
|
||||
|
||||
// 页面特定初始化
|
||||
// 页面特定初始化 - 保留这部分逻辑,因为它不会与hashchange事件处理逻辑冲突
|
||||
const target = item.getAttribute('href').substring(1);
|
||||
if (target === 'shield' && typeof initShieldPage === 'function') {
|
||||
initShieldPage();
|
||||
} else if (target === 'hosts' && typeof initHostsPage === 'function') {
|
||||
|
||||
Reference in New Issue
Block a user