user.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { get, post, put, del } from '@/utils/request'
  2. import type { IResponse, IBaseResponse, BaseResponse } from '@/types'
  3. // 用户类型
  4. export interface User {
  5. id: string
  6. username: string
  7. role: 'admin' | 'operator' | 'viewer'
  8. createdAt?: string
  9. updatedAt?: string
  10. }
  11. // 用户列表查询参数 (matches backend schema)
  12. export interface UserQueryParams {
  13. page?: number
  14. pageSize?: number
  15. search?: string
  16. role?: 'admin' | 'operator' | 'viewer'
  17. status?: 'active' | 'disabled'
  18. }
  19. // 创建/更新用户参数
  20. export interface UserForm {
  21. username: string
  22. password?: string
  23. role: 'admin' | 'operator' | 'viewer'
  24. }
  25. // 获取用户列表
  26. export function listUsers(params?: UserQueryParams): Promise<IResponse<User>> {
  27. return get('/users', params)
  28. }
  29. // 获取用户详情
  30. export function getUser(id: string): Promise<IBaseResponse<User>> {
  31. return get(`/users/${id}`)
  32. }
  33. // 创建用户
  34. export function createUser(data: UserForm): Promise<IBaseResponse<User>> {
  35. return post('/users', data)
  36. }
  37. // 更新用户
  38. export function updateUser(id: string, data: Partial<UserForm>): Promise<IBaseResponse<User>> {
  39. return put(`/users/${id}`, data)
  40. }
  41. // 删除用户
  42. export function deleteUser(id: string): Promise<BaseResponse> {
  43. return del(`/users/${id}`)
  44. }
  45. // 重置用户密码
  46. export function resetPassword(id: string, password: string): Promise<BaseResponse> {
  47. return post(`/users/${id}/reset-password`, { password })
  48. }