取消游客模式,强制登录后使用
This commit is contained in:
@@ -10,14 +10,14 @@ export interface UserInfo {
|
||||
id: string
|
||||
username: string
|
||||
email?: string
|
||||
role: 'system_admin' | 'admin' | 'user' | 'guest'
|
||||
role: 'system_admin' | 'admin' | 'user'
|
||||
status: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface Role {
|
||||
id: number
|
||||
name: 'system_admin' | 'admin' | 'user' | 'guest'
|
||||
name: 'system_admin' | 'admin' | 'user'
|
||||
description?: string
|
||||
permissions: string[]
|
||||
created_at: string
|
||||
@@ -79,9 +79,6 @@ async function request<T>(
|
||||
}
|
||||
|
||||
export const api = {
|
||||
publicInfo: () =>
|
||||
request<{ message: string; guest_allowed: boolean }>('/api/public'),
|
||||
|
||||
register: (body: { username: string; email?: string; password: string }) =>
|
||||
request<AuthResponse>('/api/auth/register', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -30,13 +30,12 @@ export function clearAuth() {
|
||||
localStorage.removeItem('user')
|
||||
}
|
||||
|
||||
export type RoleName = 'system_admin' | 'admin' | 'user' | 'guest'
|
||||
export type RoleName = 'system_admin' | 'admin' | 'user'
|
||||
|
||||
const ROLE_RANK: Record<RoleName, number> = {
|
||||
system_admin: 3,
|
||||
admin: 2,
|
||||
user: 1,
|
||||
guest: 0,
|
||||
}
|
||||
|
||||
export function roleRank(role: RoleName): number {
|
||||
@@ -51,8 +50,6 @@ export function roleLabel(role: RoleName): string {
|
||||
return '管理员'
|
||||
case 'user':
|
||||
return '用户'
|
||||
case 'guest':
|
||||
return '游客'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { LayoutDashboard, Globe, ShieldCheck } from 'lucide-react'
|
||||
import { api } from '@/lib/api'
|
||||
import { LayoutDashboard, ShieldCheck } from 'lucide-react'
|
||||
import { getStoredUser, roleLabel } from '@/lib/auth'
|
||||
|
||||
export function Dashboard() {
|
||||
const [publicInfo, setPublicInfo] = useState<{ message: string } | null>(null)
|
||||
const user = getStoredUser()
|
||||
|
||||
useEffect(() => {
|
||||
api.publicInfo().then(setPublicInfo).catch(() => null)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -19,7 +12,7 @@ export function Dashboard() {
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-foreground">看板</h1>
|
||||
<p className="text-sm text-secondary">欢迎回来,{user?.username || '游客'}</p>
|
||||
<p className="text-sm text-secondary">欢迎回来,{user?.username || '—'}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -27,14 +20,8 @@ export function Dashboard() {
|
||||
<Card
|
||||
icon={<ShieldCheck className="h-5 w-5 text-accent" />}
|
||||
title="当前身份"
|
||||
value={user ? roleLabel(user.role) : '游客'}
|
||||
desc={user ? `用户:${user.username}` : '未登录,仅可查看公开信息'}
|
||||
/>
|
||||
<Card
|
||||
icon={<Globe className="h-5 w-5 text-bear" />}
|
||||
title="公开信息"
|
||||
value="已接入"
|
||||
desc={publicInfo?.message || '加载中…'}
|
||||
value={user ? roleLabel(user.role) : '—'}
|
||||
desc={user ? `用户:${user.username}` : '加载中…'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -44,7 +31,6 @@ export function Dashboard() {
|
||||
<li><span className="text-accent font-medium">系统管理员</span>:可管理管理员、用户、系统配置</li>
|
||||
<li><span className="text-accent font-medium">管理员</span>:可管理普通用户</li>
|
||||
<li><span className="text-accent font-medium">用户</span>:可访问业务功能、修改个人资料</li>
|
||||
<li><span className="text-accent font-medium">游客</span>:仅查看公开内容,不可操作</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,11 @@ export const router = createBrowserRouter([
|
||||
{ path: '/login', element: <Login /> },
|
||||
{
|
||||
path: '/',
|
||||
element: <Layout />,
|
||||
element: (
|
||||
<AuthGuard requireAuth>
|
||||
<Layout />
|
||||
</AuthGuard>
|
||||
),
|
||||
children: [
|
||||
{ index: true, element: <Dashboard /> },
|
||||
{
|
||||
@@ -23,11 +27,7 @@ export const router = createBrowserRouter([
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
element: (
|
||||
<AuthGuard requireAuth>
|
||||
<Profile />
|
||||
</AuthGuard>
|
||||
),
|
||||
element: <Profile />,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user