| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import request from './request'
- import type { ApiResponse } from '@/types/auth'
- export interface UserProfile {
- id: string
- username: string
- email: string
- phone?: string
- real_name?: string
- company?: string
- department?: string
- position?: string
- avatar_url?: string
- is_active: boolean
- is_superuser: boolean
- created_at: string
- updated_at: string
- last_login_at?: string
- roles?: string[]
- }
- export interface UpdateProfileRequest {
- email: string
- phone?: string
- real_name?: string
- company?: string
- department?: string
- position?: string
- }
- export interface ChangePasswordRequest {
- old_password: string
- new_password: string
- }
- export interface LoginLog {
- id: string
- username: string
- login_type: string
- ip_address: string
- user_agent: string
- success: boolean
- failure_reason?: string
- login_at: string
- }
- export interface UserToken {
- id: string
- app_name: string
- token_type: string
- scope: string
- expires_at: string
- created_at: string
- last_used_at?: string
- }
- export const userApi = {
- // 获取用户信息 - 使用auth模块的userinfo端点
- getProfile(): Promise<ApiResponse<UserProfile>> {
- return request.get('/api/v1/auth/userinfo')
- },
- // 更新用户信息
- updateProfile(data: UpdateProfileRequest): Promise<ApiResponse> {
- return request.put('/api/v1/system/users/profile', data)
- },
- // 修改密码
- changePassword(data: ChangePasswordRequest): Promise<ApiResponse> {
- return request.put('/api/v1/system/users/password', data)
- },
- // 上传头像
- uploadAvatar(file: File): Promise<ApiResponse<{ url: string }>> {
- const formData = new FormData()
- formData.append('avatar', file)
- return request.post('/api/v1/system/users/avatar', formData, {
- headers: {
- 'Content-Type': 'multipart/form-data'
- }
- })
- },
- // 获取登录日志
- getLoginLogs(params?: {
- page?: number
- page_size?: number
- start_time?: string
- end_time?: string
- }): Promise<ApiResponse<{
- items: LoginLog[]
- total: number
- page: number
- page_size: number
- }>> {
- return request.get('/api/v1/system/users/login-logs', { params })
- },
- // 获取用户令牌
- getTokens(params?: {
- page?: number
- page_size?: number
- }): Promise<ApiResponse<{
- items: UserToken[]
- total: number
- page: number
- page_size: number
- }>> {
- return request.get('/api/v1/system/users/tokens', { params })
- },
- // 撤销令牌
- revokeToken(tokenId: string): Promise<ApiResponse> {
- return request.delete(`/api/v1/system/users/tokens/${tokenId}`)
- },
- // 强制下线(撤销所有令牌)
- forceLogout(): Promise<ApiResponse> {
- return request.post('/api/v1/system/users/force-logout')
- }
- }
|