chore: sync local latest state and repository cleanup

This commit is contained in:
Your Name
2026-03-23 13:02:36 +08:00
parent f1ff3d629f
commit 2ef0f17961
493 changed files with 46912 additions and 7977 deletions

View File

@@ -1,6 +1,7 @@
/**
* 用户管理服务
*/
import { authFetch, getAuthHeaders, baseUrl } from './authHelper'
export interface User {
id: number
@@ -20,7 +21,7 @@ export interface ApiResponse<T> {
}
class UserService {
private baseUrl = '/api'
private baseUrl = baseUrl || '/api/v1'
async getUsers(params?: { page?: number; size?: number; keyword?: string }): Promise<User[]> {
const searchParams = new URLSearchParams()
@@ -28,9 +29,7 @@ class UserService {
if (params?.size) searchParams.set('size', String(params.size))
if (params?.keyword) searchParams.set('keyword', params.keyword)
const response = await fetch(`${this.baseUrl}/users?${searchParams}`, {
credentials: 'include'
})
const response = await authFetch(`${this.baseUrl}/users?${searchParams}`)
const result = await response.json() as ApiResponse<User[]>
if (result.code !== 200) {
throw new Error(result.message || '获取用户列表失败')
@@ -39,9 +38,7 @@ class UserService {
}
async getUserById(id: number): Promise<User | null> {
const response = await fetch(`${this.baseUrl}/users/${id}`, {
credentials: 'include'
})
const response = await authFetch(`${this.baseUrl}/users/${id}`)
const result = await response.json() as ApiResponse<User>
if (result.code !== 200) {
return null
@@ -50,10 +47,8 @@ class UserService {
}
async createUser(data: Partial<User>): Promise<number> {
const response = await fetch(`${this.baseUrl}/users`, {
const response = await authFetch(`${this.baseUrl}/users`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(data)
})
const result = await response.json() as ApiResponse<number>
@@ -64,10 +59,8 @@ class UserService {
}
async updateUser(id: number, data: Partial<User>): Promise<void> {
const response = await fetch(`${this.baseUrl}/users/${id}`, {
const response = await authFetch(`${this.baseUrl}/users/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(data)
})
const result = await response.json() as ApiResponse<void>
@@ -77,9 +70,8 @@ class UserService {
}
async deleteUser(id: number): Promise<void> {
const response = await fetch(`${this.baseUrl}/users/${id}`, {
method: 'DELETE',
credentials: 'include'
const response = await authFetch(`${this.baseUrl}/users/${id}`, {
method: 'DELETE'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
@@ -88,9 +80,8 @@ class UserService {
}
async freezeUser(id: number): Promise<void> {
const response = await fetch(`${this.baseUrl}/users/${id}/freeze`, {
method: 'POST',
credentials: 'include'
const response = await authFetch(`${this.baseUrl}/users/${id}/freeze`, {
method: 'POST'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
@@ -99,9 +90,8 @@ class UserService {
}
async unfreezeUser(id: number): Promise<void> {
const response = await fetch(`${this.baseUrl}/users/${id}/unfreeze`, {
method: 'POST',
credentials: 'include'
const response = await authFetch(`${this.baseUrl}/users/${id}/unfreeze`, {
method: 'POST'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
@@ -110,10 +100,8 @@ class UserService {
}
async assignRoles(userId: number, roleIds: number[]): Promise<void> {
const response = await fetch(`${this.baseUrl}/users/${userId}/roles`, {
const response = await authFetch(`${this.baseUrl}/users/${userId}/roles`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ roleIds })
})
const result = await response.json() as ApiResponse<void>
@@ -121,6 +109,87 @@ class UserService {
throw new Error(result.message || '分配角色失败')
}
}
async addToBlacklist(userId: number): Promise<void> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/blacklist`, {
method: 'POST'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
throw new Error(result.message || '加入黑名单失败')
}
}
async removeFromBlacklist(userId: number): Promise<void> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/unblacklist`, {
method: 'POST'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
throw new Error(result.message || '取消黑名单失败')
}
}
async addToWhitelist(userId: number): Promise<void> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/whitelist`, {
method: 'POST'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
throw new Error(result.message || '加入白名单失败')
}
}
async removeFromWhitelist(userId: number): Promise<void> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/unwhitelist`, {
method: 'POST'
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
throw new Error(result.message || '取消白名单失败')
}
}
async adjustPoints(userId: number, amount: number, reason: string): Promise<number> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/points/adjust`, {
method: 'POST',
body: JSON.stringify({ amount, reason })
})
const result = await response.json() as ApiResponse<{ newPoints: number }>
if (result.code !== 200) {
throw new Error(result.message || '积分调整失败')
}
return result.data.newPoints
}
async getPoints(userId: number): Promise<number> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/points`)
const result = await response.json() as ApiResponse<{ points: number }>
if (result.code !== 200) {
throw new Error(result.message || '获取积分失败')
}
return result.data.points
}
async getComplaints(userId: number): Promise<any[]> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/complaints`)
const result = await response.json() as ApiResponse<any[]>
if (result.code !== 200) {
throw new Error(result.message || '获取投诉记录失败')
}
return result.data
}
async addComplaint(userId: number, data: { title: string; content: string; complainant?: string }): Promise<void> {
const response = await authFetch(`${this.baseUrl}/users/${userId}/complaints`, {
method: 'POST',
body: JSON.stringify(data)
})
const result = await response.json() as ApiResponse<void>
if (result.code !== 200) {
throw new Error(result.message || '添加投诉记录失败')
}
}
}
export const userService = new UserService()