mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 15:46:37 +08:00
Refactor code structure and remove redundant sections for improved readability and maintainability
This commit is contained in:
@@ -1,64 +1,51 @@
|
||||
import type { NavigationItem } from '@/types/navigation';
|
||||
|
||||
export const dashboardNavigation: NavigationItem[] = [
|
||||
{
|
||||
href: '/',
|
||||
label: '总览',
|
||||
shortLabel: '总览',
|
||||
description: '查看阶段推进情况、系统入口与模块骨架状态。',
|
||||
},
|
||||
import type { NavigationItem } from '@/types/navigation';
|
||||
|
||||
export const dashboardNavigation: NavigationItem[] = [
|
||||
{
|
||||
href: '/proxy-route',
|
||||
label: '反代规则',
|
||||
shortLabel: '规则',
|
||||
description: '已接入列表、表单、证书匹配与发布动作。',
|
||||
},
|
||||
{
|
||||
href: '/config-version',
|
||||
label: '配置版本',
|
||||
shortLabel: '版本',
|
||||
description: '已接入版本预览、发布前 diff 与重新激活。',
|
||||
},
|
||||
href: '/',
|
||||
label: '总览',
|
||||
icon: 'home',
|
||||
},
|
||||
{
|
||||
href: '/node',
|
||||
label: '节点管理',
|
||||
shortLabel: '节点',
|
||||
description: '已接入状态标签、部署命令、心跳与更新动作。',
|
||||
},
|
||||
label: '节点',
|
||||
icon: 'node',
|
||||
},
|
||||
{
|
||||
href: '/apply-log',
|
||||
label: '应用记录',
|
||||
shortLabel: '记录',
|
||||
description: '已接入 node_id 筛选、结果状态展示与单条详情查看。',
|
||||
href: '/config-version',
|
||||
label: '发布',
|
||||
icon: 'release',
|
||||
},
|
||||
{
|
||||
href: '/managed-domain',
|
||||
label: '域名管理',
|
||||
shortLabel: '域名',
|
||||
description: '已接入列表、证书绑定、启停控制与编辑删除。',
|
||||
label: '网站',
|
||||
icon: 'website',
|
||||
children: [
|
||||
{
|
||||
href: '/managed-domain',
|
||||
label: '域名',
|
||||
icon: 'domain',
|
||||
},
|
||||
{
|
||||
href: '/tls-certificate',
|
||||
label: '证书',
|
||||
icon: 'certificate',
|
||||
},
|
||||
{
|
||||
href: '/proxy-route',
|
||||
label: '反向代理',
|
||||
icon: 'proxy',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
href: '/tls-certificate',
|
||||
label: 'TLS 证书',
|
||||
shortLabel: '证书',
|
||||
description: '已接入 PEM 导入、文件上传、到期展示与删除。',
|
||||
},
|
||||
{
|
||||
href: '/file',
|
||||
label: '文件管理',
|
||||
shortLabel: '文件',
|
||||
description: '已接入上传、下载、复制链接、搜索与删除动作。',
|
||||
},
|
||||
{
|
||||
href: '/user',
|
||||
label: '用户管理',
|
||||
shortLabel: '用户',
|
||||
description: '已接入搜索、创建、编辑、封禁与权限调整。',
|
||||
},
|
||||
label: '用户',
|
||||
icon: 'user',
|
||||
},
|
||||
{
|
||||
href: '/setting',
|
||||
label: '设置',
|
||||
shortLabel: '设置',
|
||||
description: '已接入个人、运维、系统与关于内容维护。',
|
||||
},
|
||||
];
|
||||
label: '设置',
|
||||
icon: 'setting',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
import { dashboardNavigation } from '@/lib/constants/navigation';
|
||||
import type { NavigationItem } from '@/types/navigation';
|
||||
|
||||
export function isPathActive(pathname: string, href: string) {
|
||||
import { dashboardNavigation } from '@/lib/constants/navigation';
|
||||
import type { NavigationItem } from '@/types/navigation';
|
||||
|
||||
export function isPathActive(pathname: string, href: string) {
|
||||
if (href === '/') {
|
||||
return pathname === '/';
|
||||
}
|
||||
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
}
|
||||
|
||||
export function getCurrentNavigationItem(pathname: string): NavigationItem | undefined {
|
||||
return dashboardNavigation.find((item) => isPathActive(pathname, item.href));
|
||||
}
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
}
|
||||
|
||||
export function isNavigationItemActive(pathname: string, item: NavigationItem): boolean {
|
||||
return isPathActive(pathname, item.href) || item.children?.some((child) => isNavigationItemActive(pathname, child)) || false;
|
||||
}
|
||||
|
||||
export function flattenNavigationItems(items: NavigationItem[]): NavigationItem[] {
|
||||
return items.flatMap((item) => [item, ...(item.children ? flattenNavigationItems(item.children) : [])]);
|
||||
}
|
||||
|
||||
export function getCurrentNavigationItem(pathname: string): NavigationItem | undefined {
|
||||
const findMatch = (items: NavigationItem[]): NavigationItem | undefined => {
|
||||
for (const item of items) {
|
||||
if (item.children) {
|
||||
const childMatch = findMatch(item.children);
|
||||
if (childMatch) {
|
||||
return childMatch;
|
||||
}
|
||||
}
|
||||
|
||||
if (isPathActive(pathname, item.href)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
return findMatch(dashboardNavigation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user