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:
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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user