// src/lib/services/userService.ts import api from '@/lib/api'; export interface UserListParams { page?: number; page_size?: number; size?: number; keyword?: string; [key: string]: any; } export const userService = { /** * 分页查询用户列表 */ async listAll(params?: UserListParams) { const res = await api.get('/api/user/list_all', { params }); return res.data; }, /** * 获取用户详情 */ async getDetail(userId: number) { try { const res = await api.get('/api/user/get_by_id', { params: { user_id: userId }, }); return res.data; } catch { const res = await api.get('/api/user/detail', { params: { user_id: userId }, }); return res.data; } }, /** * 更新用户信息 / 权限 */ async update(userId: number | string, payload: Record) { const res = await api.post('/api/user/update', payload, { params: { user_id: userId, uid: userId }, }); return res.data; }, /** * 用户修改个人资料 (前台) */ async setProfiles(payload: { phone?: string; nickname?: string; avatar_url?: string; [key: string]: any }) { const res = await api.post('/api/user/set_profiles', payload); return res.data; }, /** * 上传文件 / 头像资源 */ async uploadFile(file: File) { const formData = new FormData(); formData.append('file', file); const res = await api.post('/api/resource/upload_file', formData, { headers: { 'Content-Type': 'multipart/form-data' }, }); return res.data; }, };