初始化项目

This commit is contained in:
wmp
2025-09-13 14:00:56 +08:00
commit f1fa28401e
61 changed files with 4710 additions and 0 deletions

115
src/app/dashboard/page.tsx Normal file
View File

@@ -0,0 +1,115 @@
'use client'
import { useState, useEffect } from 'react'
import { useRouter } from 'next/navigation'
import Gatewayinfo from './components/gatewayinfo'
import GatewayConfig from './components/gatewayConfig'
import CityNodeStats from './components/cityNodeStats'
import AllocationStatus from './components/allocationStatus'
import Edge from './components/edge'
import { LogOut } from 'lucide-react'
const tabs = [
{ id: 'gatewayInfo', label: '网关信息' },
{ id: 'gateway', label: '网关配置' },
{ id: 'city', label: '城市信息' },
{ id: 'allocation', label: '分配状态' },
{ id: 'edge', label: '节点信息' }
]
export default function Dashboard() {
const [activeTab, setActiveTab] = useState('gatewayInfo')
const [isLoading, setIsLoading] = useState(false)
const router = useRouter()
// 从 URL 中获取 tab 参数
useEffect(() => {
if (typeof window !== 'undefined') {
const urlParams = new URLSearchParams(window.location.search)
const urlTab = urlParams.get('tab')
if (urlTab && tabs.some(tab => tab.id === urlTab)) {
setActiveTab(urlTab)
}
}
}, [])
// 退出登录
const handleLogout = async () => {
setIsLoading(true)
try {
const response = await fetch('/api/auth/logout', {
method: 'POST',
})
if (response.ok) {
// 退出成功后跳转到登录页
router.push('/login')
router.refresh()
} else {
console.error('退出失败')
}
} catch (error) {
console.error('退出错误:', error)
} finally {
setIsLoading(false)
}
}
const handleTabClick = (tabId: string) => {
setActiveTab(tabId)
// 更新 URL 参数
router.push(`/dashboard?tab=${tabId}`)
}
return (
<div className="min-h-screen bg-gray-100">
<nav className="bg-white shadow-sm">
<div className="px-4 sm:px-6 lg:px-8">
<div className="flex justify-between h-16 items-center">
<div className="flex items-center">
<h1 className="text-xl font-bold text-gray-900"></h1>
</div>
{/* 简化的退出按钮 */}
<button
onClick={handleLogout}
disabled={isLoading}
className="flex items-center space-x-2 px-4 py-2 bg-gray-100 text-gray-700 rounded-md hover:bg-gray-200 disabled:opacity-50 transition-colors"
>
<LogOut className="h-4 w-4" />
<span>{isLoading ? '退出中...' : '退出登录'}</span>
</button>
</div>
</div>
</nav>
<div className="px-4 sm:px-6 lg:px-8 py-8">
<div className="border-b border-gray-200 mb-6">
<nav className="-mb-px flex space-x-8">
{tabs.map((tab) => (
<button
key={tab.id}
onClick={() => handleTabClick(tab.id)}
className={`py-2 px-1 border-b-2 font-medium text-sm ${
activeTab === tab.id
? 'border-blue-500 text-blue-600'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
}`}
>
{tab.label}
</button>
))}
</nav>
</div>
<div className="grid grid-cols-1 gap-6">
{activeTab === 'gatewayInfo' && <Gatewayinfo />}
{activeTab === 'gateway' && <GatewayConfig />}
{activeTab === 'city' && <CityNodeStats />}
{activeTab === 'allocation' && <AllocationStatus detailed />}
{activeTab === 'edge' && <Edge />}
</div>
</div>
</div>
)
}