refactor: 清理站内导航死代码 (删除孤立NavigationPage组件+navigationApi+导航mock数据)

- 删除 frontend/src/components/navigation/NavigationPage.tsx (359行, 菜单/路由移除后遗留的孤立组件)
- 移除 services/api.ts 中 navigationApi (唯一消费者已删除)
- 移除 mocks/modules/misc.ts 中 navigationGroups/navigationLinks 死数据 (252行)
- 清理 mocks/data.ts barrel 中导航 re-export
- 修正 cloud.ts 误导性注释 (站内导航→云平台/账号/区域/域名数据)
- 后端 navigation.go 保留不动 (菜单已移除但后端代码保留)
- tsc --noEmit 零错误 + npm run build 通过
This commit is contained in:
attacker committed 2026-06-15 16:06:04 +08:00
1 parent 9af0890bc6
commit d13f5b8fa1
5 files changed
+2 -646

No files matched your search

@@ -1,359 +0,0 @@
import { useState, useEffect } from 'react';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Loader2 } from 'lucide-react';
import {
Search,
ExternalLink,
Plus,
Edit2,
Trash2,
Folder,
LayoutGrid,
List,
Star,
Settings
} from 'lucide-react';
import { navigationApi } from '@/services/api';
interface NavLink {
id: string;
title: string;
url: string;
icon?: string;
description?: string;
group_id: string;
is_favorite?: boolean;
tags?: string[];
}
interface NavGroup {
id: string;
name: string;
icon?: string;
description?: string;
sort_order?: number;
}
export function NavigationPage() {
const [searchQuery, setSearchQuery] = useState('');
const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid');
const [selectedGroup, setSelectedGroup] = useState<string>('all');
const [showFavoritesOnly, setShowFavoritesOnly] = useState(false);
const [groups, setGroups] = useState<NavGroup[]>([]);
const [links, setLinks] = useState<NavLink[]>([]);
const [loading, setLoading] = useState(true);
const loadData = async () => {
try {
setLoading(true);
const [groupsData, linksData] = await Promise.all([
navigationApi.getGroups(),
navigationApi.getLinks(),
]);
setGroups(groupsData || []);
setLinks(linksData || []);
} catch (error) {
console.error('Failed to load navigation data:', error);
} finally {
setLoading(false);
}
};
useEffect(() => {
loadData();
}, []);
const handleToggleFavorite = async (id: string) => {
try {
await navigationApi.toggleFavorite(id);
loadData();
} catch (error) {
console.error('Failed to toggle favorite:', error);
}
};
const handleDeleteLink = async (id: string) => {
try {
await navigationApi.deleteLink(id);
loadData();
} catch (error) {
console.error('Failed to delete link:', error);
}
};
const filteredLinks = links.filter(link => {
const matchesSearch = (link.title || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
(link.description || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
(link.tags || []).some(tag => tag.toLowerCase().includes(searchQuery.toLowerCase()));
const matchesGroup = selectedGroup === 'all' || link.group_id === selectedGroup;
const matchesFavorite = !showFavoritesOnly || link.is_favorite;
return matchesSearch && matchesGroup && matchesFavorite;
});
const groupedLinks = groups.map(group => ({
...group,
links: filteredLinks.filter(link => link.group_id === group.id)
})).filter(group => group.links.length > 0);
const stats = {
totalLinks: links.length,
totalGroups: groups.length,
favorites: links.filter(l => l.is_favorite).length,
};
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-slate-100">站内导航</h1>
<p className="text-slate-400 mt-1">管理内部系统和常用链接</p>
</div>
<div className="flex items-center gap-2">
<Button variant="outline" className="border-slate-700 text-slate-300 hover:bg-slate-800">
<Settings className="h-4 w-4 mr-2" />
管理分组
</Button>
<Button className="bg-blue-600 hover:bg-blue-700">
<Plus className="h-4 w-4 mr-2" />
添加链接
</Button>
</div>
</div>
{/* Stats */}
<div className="grid grid-cols-3 gap-4">
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">链接总数</p>
<p className="text-2xl font-bold text-slate-100 mt-1">{stats.totalLinks}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center">
<ExternalLink className="h-5 w-5 text-blue-400" />
</div>
</div>
</CardContent>
</Card>
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">分组数</p>
<p className="text-2xl font-bold text-slate-100 mt-1">{stats.totalGroups}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-purple-500/20 flex items-center justify-center">
<Folder className="h-5 w-5 text-purple-400" />
</div>
</div>
</CardContent>
</Card>
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-4">
<div className="flex items-center justify-between">
<div>
<p className="text-slate-400 text-sm">收藏</p>
<p className="text-2xl font-bold text-yellow-400 mt-1">{stats.favorites}</p>
</div>
<div className="w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center">
<Star className="h-5 w-5 text-yellow-400" />
</div>
</div>
</CardContent>
</Card>
</div>
{/* Filters */}
<div className="flex items-center gap-4">
<div className="relative flex-1 max-w-md">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400" />
<Input
placeholder="搜索链接名称、描述或标签..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10 bg-slate-800 border-slate-700 text-slate-100"
/>
</div>
<select
value={selectedGroup}
onChange={(e) => setSelectedGroup(e.target.value)}
className="px-3 py-2 bg-slate-800 border border-slate-700 rounded-md text-slate-100 text-sm"
>
<option value="all">全部分组</option>
{groups.map(group => (
<option key={group.id} value={group.id}>{group.name}</option>
))}
</select>
<Button
variant={showFavoritesOnly ? 'default' : 'outline'}
size="sm"
onClick={() => setShowFavoritesOnly(!showFavoritesOnly)}
className={showFavoritesOnly ? 'bg-yellow-600 hover:bg-yellow-700' : 'border-slate-700 text-slate-300'}
>
<Star className="h-4 w-4 mr-1" />
收藏
</Button>
<div className="flex items-center gap-1 border border-slate-700 rounded-md p-1">
<Button
variant={viewMode === 'grid' ? 'secondary' : 'ghost'}
size="icon"
className="h-8 w-8"
onClick={() => setViewMode('grid')}
>
<LayoutGrid className="h-4 w-4" />
</Button>
<Button
variant={viewMode === 'list' ? 'secondary' : 'ghost'}
size="icon"
className="h-8 w-8"
onClick={() => setViewMode('list')}
>
<List className="h-4 w-4" />
</Button>
</div>
</div>
{loading ? (
<div className="flex items-center justify-center py-12">
<Loader2 className="h-6 w-6 text-slate-500 animate-spin" />
</div>
) : null}
{/* Navigation Content */}
<div className="space-y-6">
{selectedGroup === 'all' && !searchQuery && !showFavoritesOnly ? (
// Grouped view
groupedLinks.map(group => (
<div key={group.id}>
<div className="flex items-center gap-2 mb-3">
<Folder className="h-5 w-5 text-blue-400" />
<h2 className="text-lg font-semibold text-slate-100">{group.name}</h2>
<Badge variant="secondary" className="bg-slate-700 text-slate-300">
{group.links.length}
</Badge>
</div>
{viewMode === 'grid' ? (
<div className="grid grid-cols-4 gap-4">
{group.links.map(link => (
<NavLinkCard key={link.id} link={link} onToggleFavorite={handleToggleFavorite} onDelete={handleDeleteLink} />
))}
</div>
) : (
<div className="space-y-2">
{group.links.map(link => (
<NavLinkRow key={link.id} link={link} onToggleFavorite={handleToggleFavorite} onDelete={handleDeleteLink} />
))}
</div>
)}
</div>
))
) : (
// Flat view
viewMode === 'grid' ? (
<div className="grid grid-cols-4 gap-4">
{filteredLinks.map(link => (
<NavLinkCard key={link.id} link={link} onToggleFavorite={handleToggleFavorite} onDelete={handleDeleteLink} />
))}
</div>
) : (
<div className="space-y-2">
{filteredLinks.map(link => (
<NavLinkRow key={link.id} link={link} onToggleFavorite={handleToggleFavorite} onDelete={handleDeleteLink} />
))}
</div>
)
)}
</div>
</div>
);
}
function NavLinkCard({ link, onToggleFavorite, onDelete }: { link: NavLink; onToggleFavorite: (id: string) => void; onDelete: (id: string) => void }) {
return (
<Card className="bg-slate-800 border-slate-700 hover:border-blue-500/50 transition-colors group">
<CardContent className="p-4">
<div className="flex items-start justify-between">
<div className="flex items-start gap-3">
<div className="w-10 h-10 rounded-lg bg-gradient-to-br from-blue-500 to-cyan-500 flex items-center justify-center text-white font-bold text-lg">
{(link.title || '').slice(0, 2)}
</div>
<div className="flex-1 min-w-0">
<h3 className="font-medium text-slate-100 truncate">{link.title}</h3>
<p className="text-xs text-slate-400 mt-0.5 line-clamp-2">{link.description}</p>
</div>
</div>
<div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<Button variant="ghost" size="icon" className="h-7 w-7 text-slate-400 hover:text-yellow-400" onClick={() => onToggleFavorite(link.id)}>
<Star className={`h-4 w-4 ${link.is_favorite ? 'fill-yellow-400 text-yellow-400' : ''}`} />
</Button>
<Button variant="ghost" size="icon" className="h-7 w-7 text-slate-400 hover:text-blue-400">
<Edit2 className="h-4 w-4" />
</Button>
</div>
</div>
<div className="flex items-center justify-between mt-3 pt-3 border-t border-slate-700">
<div className="flex gap-1">
{(link.tags || []).map(tag => (
<Badge key={tag} variant="secondary" className="bg-slate-700 text-slate-300 text-xs">
{tag}
</Badge>
))}
</div>
<Button variant="ghost" size="sm" className="h-7 px-2 text-blue-400 hover:text-blue-300" asChild>
<a href={link.url} target="_blank" rel="noopener noreferrer">
<ExternalLink className="h-3 w-3 mr-1" />
访问
</a>
</Button>
</div>
</CardContent>
</Card>
);
}
function NavLinkRow({ link, onToggleFavorite, onDelete }: { link: NavLink; onToggleFavorite: (id: string) => void; onDelete: (id: string) => void }) {
return (
<Card className="bg-slate-800 border-slate-700 hover:border-blue-500/50 transition-colors">
<CardContent className="p-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-gradient-to-br from-blue-500 to-cyan-500 flex items-center justify-center text-white font-bold text-sm">
{(link.title || '').slice(0, 2)}
</div>
<div>
<h3 className="font-medium text-slate-100">{link.title}</h3>
<p className="text-xs text-slate-400">{link.description}</p>
</div>
</div>
<div className="flex items-center gap-4">
<div className="flex gap-1">
{(link.tags || []).map(tag => (
<Badge key={tag} variant="secondary" className="bg-slate-700 text-slate-300 text-xs">
{tag}
</Badge>
))}
</div>
<div className="flex items-center gap-1">
<Button variant="ghost" size="icon" className="h-7 w-7 text-slate-400 hover:text-yellow-400" onClick={() => onToggleFavorite(link.id)}>
<Star className={`h-4 w-4 ${link.is_favorite ? 'fill-yellow-400 text-yellow-400' : ''}`} />
</Button>
<Button variant="ghost" size="icon" className="h-7 w-7 text-slate-400 hover:text-blue-400">
<Edit2 className="h-4 w-4" />
</Button>
<Button variant="ghost" size="sm" className="h-7 px-2 text-blue-400 hover:text-blue-300" asChild>
<a href={link.url} target="_blank" rel="noopener noreferrer">
<ExternalLink className="h-3 w-3 mr-1" />
访问
</a>
</Button>
</div>
</div>
</div>
</CardContent>
</Card>
);
}
+1 -3
View File
@@ -12,7 +12,7 @@ export * from './modules/monitor';
export * from './modules/misc'; export * from './modules/misc';
// Aggregate mockData object (cross-module references) // Aggregate mockData object (cross-module references)
import { sqlAuditRecords, sqlAuditRules, resourceModels, modelInstances, navigationGroups, navigationLinks } from './modules/misc'; import { sqlAuditRecords, sqlAuditRules, resourceModels, modelInstances } from './modules/misc';
import { ansiblePlaybooks, ansibleJobs, ansibleInventories, cronJobsList, cronJobExecutions, scripts } from './modules/automation'; import { ansiblePlaybooks, ansibleJobs, ansibleInventories, cronJobsList, cronJobExecutions, scripts } from './modules/automation';
import { logMonitorEntries, logSources, traces, serviceMetrics, traceSpans, grafanaDashboards, datasources } from './modules/monitor'; import { logMonitorEntries, logSources, traces, serviceMetrics, traceSpans, grafanaDashboards, datasources } from './modules/monitor';
import { alertCenterAlerts, alertCenterRules, notificationChannels, recentAlerts, alertEvents } from './modules/alerts'; import { alertCenterAlerts, alertCenterRules, notificationChannels, recentAlerts, alertEvents } from './modules/alerts';
@@ -75,6 +75,4 @@ export const mockData = {
approvalFlows, approvalFlows,
approvalInstances, approvalInstances,
alertEvents, alertEvents,
navigationGroups,
navigationLinks,
}; };
+1 -1
View File
@@ -279,7 +279,7 @@ export const platforms = [
}, },
]; ];
// ==================== 站内导航数据 ==================== // ==================== 云平台/账号/区域/域名数据 ====================
export const cloudProvidersList = [ export const cloudProvidersList = [
{ id: 'aliyun', name: '阿里云', icon: 'aliyun', regions: ['cn-beijing', 'cn-shanghai'] }, { id: 'aliyun', name: '阿里云', icon: 'aliyun', regions: ['cn-beijing', 'cn-shanghai'] },
-252
View File
@@ -132,258 +132,6 @@ export const modelInstances: ModelInstance[] = [
}, },
]; ];
// ==================== 机房机柜数据 ====================
export const navigationGroups = [
{
id: 'group-001',
name: '运维工具',
description: '日常运维常用工具',
linkCount: 5,
},
{
id: 'group-002',
name: '监控告警',
description: '监控系统和告警平台',
linkCount: 4,
},
{
id: 'group-003',
name: '开发工具',
description: '开发相关工具和平台',
linkCount: 6,
},
{
id: 'group-004',
name: '文档知识库',
description: '技术文档和知识库',
linkCount: 3,
},
{
id: 'group-005',
name: '云平台',
description: '各大云厂商控制台',
linkCount: 5,
},
];
export const navigationLinks = [
// 运维工具
{
id: 'link-001',
name: 'Jenkins',
url: 'https://jenkins.company.com',
description: 'CI/CD流水线平台',
groupId: 'group-001',
isFavorite: true,
tags: ['CI/CD', 'DevOps'],
},
{
id: 'link-002',
name: 'GitLab',
url: 'https://gitlab.company.com',
description: '代码仓库管理平台',
groupId: 'group-001',
isFavorite: true,
tags: ['Git', '代码仓库'],
},
{
id: 'link-003',
name: 'Harbor',
url: 'https://harbor.company.com',
description: 'Docker镜像仓库',
groupId: 'group-001',
isFavorite: false,
tags: ['Docker', '镜像'],
},
{
id: 'link-004',
name: 'Nexus',
url: 'https://nexus.company.com',
description: 'Maven/npm仓库',
groupId: 'group-001',
isFavorite: false,
tags: ['Maven', 'npm'],
},
{
id: 'link-005',
name: 'Confluence',
url: 'https://confluence.company.com',
description: '团队协作文档平台',
groupId: 'group-001',
isFavorite: true,
tags: ['文档', 'Wiki'],
},
// 监控告警
{
id: 'link-006',
name: 'Prometheus',
url: 'https://prometheus.company.com',
description: '监控指标采集和查询',
groupId: 'group-002',
isFavorite: true,
tags: ['监控', '指标'],
},
{
id: 'link-007',
name: 'Grafana',
url: 'https://grafana.company.com',
description: '可视化监控大盘',
groupId: 'group-002',
isFavorite: true,
tags: ['监控', '可视化'],
},
{
id: 'link-008',
name: 'AlertManager',
url: 'https://alertmanager.company.com',
description: '告警管理和通知',
groupId: 'group-002',
isFavorite: false,
tags: ['告警', '通知'],
},
{
id: 'link-009',
name: 'ELK Stack',
url: 'https://kibana.company.com',
description: '日志收集和分析平台',
groupId: 'group-002',
isFavorite: false,
tags: ['日志', 'ELK'],
},
// 开发工具
{
id: 'link-010',
name: 'Jira',
url: 'https://jira.company.com',
description: '项目管理和任务跟踪',
groupId: 'group-003',
isFavorite: true,
tags: ['项目管理', '敏捷'],
},
{
id: 'link-011',
name: 'SonarQube',
url: 'https://sonarqube.company.com',
description: '代码质量分析平台',
groupId: 'group-003',
isFavorite: false,
tags: ['代码质量', '扫描'],
},
{
id: 'link-012',
name: 'Nexus',
url: 'https://nexus.company.com',
description: '制品仓库管理',
groupId: 'group-003',
isFavorite: false,
tags: ['制品', '仓库'],
},
{
id: 'link-013',
name: 'Swagger UI',
url: 'https://swagger.company.com',
description: 'API文档和测试',
groupId: 'group-003',
isFavorite: false,
tags: ['API', '文档'],
},
{
id: 'link-014',
name: 'YApi',
url: 'https://yapi.company.com',
description: 'API接口管理平台',
groupId: 'group-003',
isFavorite: false,
tags: ['API', '接口管理'],
},
{
id: 'link-015',
name: 'Postman',
url: 'https://web.postman.co',
description: 'API测试工具',
groupId: 'group-003',
isFavorite: true,
tags: ['API', '测试'],
},
// 文档知识库
{
id: 'link-016',
name: 'Confluence',
url: 'https://confluence.company.com',
description: '团队知识库',
groupId: 'group-004',
isFavorite: true,
tags: ['文档', '知识库'],
},
{
id: 'link-017',
name: 'Notion',
url: 'https://notion.so',
description: '个人和团队笔记',
groupId: 'group-004',
isFavorite: true,
tags: ['笔记', '文档'],
},
{
id: 'link-018',
name: '语雀',
url: 'https://yuque.com',
description: '阿里知识库平台',
groupId: 'group-004',
isFavorite: false,
tags: ['文档', '知识库'],
},
// 云平台
{
id: 'link-019',
name: '阿里云控制台',
url: 'https://ecs.console.aliyun.com',
description: '阿里云ECS管理',
groupId: 'group-005',
isFavorite: true,
tags: ['阿里云', 'ECS'],
},
{
id: 'link-020',
name: '腾讯云控制台',
url: 'https://console.cloud.tencent.com',
description: '腾讯云CVM管理',
groupId: 'group-005',
isFavorite: false,
tags: ['腾讯云', 'CVM'],
},
{
id: 'link-021',
name: 'AWS控制台',
url: 'https://console.aws.amazon.com',
description: 'AWS EC2管理',
groupId: 'group-005',
isFavorite: true,
tags: ['AWS', 'EC2'],
},
{
id: 'link-022',
name: '华为云控制台',
url: 'https://console.huaweicloud.com',
description: '华为云ECS管理',
groupId: 'group-005',
isFavorite: false,
tags: ['华为云', 'ECS'],
},
{
id: 'link-023',
name: 'Azure门户',
url: 'https://portal.azure.com',
description: 'Azure虚拟机管理',
groupId: 'group-005',
isFavorite: false,
tags: ['Azure', 'VM'],
},
];
// ============ SQL审计数据 ============ // ============ SQL审计数据 ============
export const sqlAuditRecords = [ export const sqlAuditRecords = [
{ {
-31
View File
@@ -376,37 +376,6 @@ export const approvalApi = {
}, },
}; };
// ==================== 导航管理 API ====================
export const navigationApi = {
getGroups: async () => {
return http.get('/navigations/groups');
},
createGroup: async (data: any) => {
return http.post('/navigations/groups', data);
},
updateGroup: async (id: number | string, data: any) => {
return http.put(`/navigations/groups/${id}`, data);
},
deleteGroup: async (id: number | string) => {
return http.delete(`/navigations/groups/${id}`);
},
getLinks: async () => {
return http.get('/navigations/links');
},
createLink: async (data: any) => {
return http.post('/navigations/links', data);
},
updateLink: async (id: number | string, data: any) => {
return http.put(`/navigations/links/${id}`, data);
},
deleteLink: async (id: number | string) => {
return http.delete(`/navigations/links/${id}`);
},
toggleFavorite: async (id: number | string) => {
return http.post(`/navigations/links/${id}/favorite`);
},
};
// ==================== 云管理 API ==================== // ==================== 云管理 API ====================
export const cloudApi = { export const cloudApi = {
getAccounts: async () => { getAccounts: async () => {