feat: rbac接入

This commit is contained in:
Blizzard
2026-04-28 23:47:48 +08:00
parent ccb36fa59c
commit 3ed0b76fc2
8 changed files with 76 additions and 133 deletions
+6 -12
View File
@@ -1,13 +1,13 @@
import { get, post } from '@/lib/request'
import { USE_MOCK, delay, mockResponse } from '@/mock'
import { mockUsers } from '@/mock/system/users'
// ==================== Types ====================
export interface SystemUser {
id: string; account: string; name: string; nickName?: string; phone?: string
avatar?: SystemOss; avatarId?: string; clientId?: string; tenantId?: string
createdAt: string; updatedAt: string; roles?: SystemRole[]
createdAt: string; updatedAt: string; roles?: string[] // Adjusted based on backend info
menus?: any[]
gender?: number
}
export interface SystemRole {
@@ -44,26 +44,20 @@ export interface OperationLog {
createdAt: string
}
export interface CaptchaRes { captcha: string; captchaId: string }
export interface CaptchaRes { captchaImg: string; captchaId: string }
export interface LoginParams { account: string; password: string; captcha: string; captchaId: string }
export interface LoginResponse { token: string; expiresAt: number; user: SystemUser }
export interface LoginResponse { token: string; userInfo: SystemUser }
// ==================== Auth ====================
export async function getCaptcha() {
if (USE_MOCK) { await delay(200); return mockResponse({ captcha: 'data:image/svg+xml;base64,PHN2Zz48L3N2Zz4=', captchaId: 'mock-captcha-id' }) }
return get<{ code: number; data: CaptchaRes; msg: string }>('/auth/captcha')
}
export async function login(data: LoginParams) {
if (USE_MOCK) { await delay(500); return mockResponse({ token: 'mock-token-xxx', expiresAt: Date.now() + 7200000, user: mockUsers[0] }, '登录成功') }
return post<{ code: number; data: LoginResponse; msg: string }>('/auth/login', data)
}
export async function logout() {
if (USE_MOCK) { await delay(100); return mockResponse(null, '已登出') }
return get<{ code: number; data: null; msg: string }>('/auth/logout')
return get<{ code: number; data: null; msg: string }>('/auth/logout') // If backend doesn't have it, we just clear local token
}
// ==================== 以下在各自文件中实现 ====================
// 这里只导出类型,具体 CRUD 在 api/system/*.ts 子文件中