Files
aiops/frontend/src/components/navigation/NavigationPage.tsx
T
attacker 97c4207ff8 refactor: 标准化项目结构 frontend/ + backend/ + SQLite + run.sh
- 目录重构: app/ -> frontend/,与 backend/ 并列
- 数据库: 默认 SQLite(零配置),修复 DSN() bug
- run.sh: 一键启动前后端,支持 start/stop/restart/status
- Makefile: install/dev/build/lint/clean 快捷命令
- vite.config.ts: 配置 dev server 端口 5173 + API 代理到 8080
- config.yaml: SQLite 默认配置,开箱即用
- docs/: 完整开发文档(项目结构/API/数据库/规范/部署)
- 修复: GORM foreign key 关联声明
- 修复: go get gorm.io/driver/sqlite 依赖
2026-06-13 23:34:23 +08:00

315 lines
12 KiB
TypeScript

import { useState } 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 {
Search,
ExternalLink,
Plus,
Edit2,
Trash2,
Folder,
LayoutGrid,
List,
Star,
Settings
} from 'lucide-react';
import { navigationGroups, navigationLinks } from '@/mocks/data';
interface NavLink {
id: string;
name: string;
url: string;
icon?: string;
description?: string;
groupId: string;
isFavorite?: boolean;
tags?: string[];
}
interface NavGroup {
id: string;
name: string;
icon?: string;
description?: string;
linkCount?: 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 = navigationGroups;
const links = navigationLinks;
const filteredLinks = links.filter(link => {
const matchesSearch = link.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
link.description?.toLowerCase().includes(searchQuery.toLowerCase()) ||
link.tags?.some(tag => tag.toLowerCase().includes(searchQuery.toLowerCase()));
const matchesGroup = selectedGroup === 'all' || link.groupId === selectedGroup;
const matchesFavorite = !showFavoritesOnly || link.isFavorite;
return matchesSearch && matchesGroup && matchesFavorite;
});
const groupedLinks = groups.map(group => ({
...group,
links: filteredLinks.filter(link => link.groupId === group.id)
})).filter(group => group.links.length > 0);
const stats = {
totalLinks: links.length,
totalGroups: groups.length,
favorites: links.filter(l => l.isFavorite).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>
{/* 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} />
))}
</div>
) : (
<div className="space-y-2">
{group.links.map(link => (
<NavLinkRow key={link.id} link={link} />
))}
</div>
)}
</div>
))
) : (
// Flat view
viewMode === 'grid' ? (
<div className="grid grid-cols-4 gap-4">
{filteredLinks.map(link => (
<NavLinkCard key={link.id} link={link} />
))}
</div>
) : (
<div className="space-y-2">
{filteredLinks.map(link => (
<NavLinkRow key={link.id} link={link} />
))}
</div>
)
)}
</div>
</div>
);
}
function NavLinkCard({ link }: { link: NavLink }) {
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.name.slice(0, 2)}
</div>
<div className="flex-1 min-w-0">
<h3 className="font-medium text-slate-100 truncate">{link.name}</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">
<Star className={`h-4 w-4 ${link.isFavorite ? '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 }: { link: NavLink }) {
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.name.slice(0, 2)}
</div>
<div>
<h3 className="font-medium text-slate-100">{link.name}</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">
<Star className={`h-4 w-4 ${link.isFavorite ? '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>
);
}