usersApi.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import api from '@/utils/http'
  2. // ==================== 用户管理 API(遗留,地磅独立用户;门户登录请用 authApi) ====================
  3. export interface User {
  4. id: string
  5. username: string
  6. role: string
  7. createdAt?: string
  8. }
  9. export interface UserCreate {
  10. username: string
  11. password: string
  12. role: string
  13. remark?: string
  14. }
  15. export interface UserUpdate {
  16. username?: string
  17. password?: string
  18. role?: string
  19. remark?: string
  20. }
  21. /** @deprecated 旧地磅用户 CRUD,门户体系下不再使用 */
  22. export const userApi = {
  23. list: async (): Promise<User[]> => {
  24. return api.get<User[]>({
  25. url: '/users'
  26. })
  27. },
  28. get: async (id: string): Promise<User> => {
  29. return api.get<User>({
  30. url: `/users/${id}`
  31. })
  32. },
  33. create: async (payload: UserCreate): Promise<User> => {
  34. return api.post<User>({
  35. url: '/users',
  36. data: payload
  37. })
  38. },
  39. update: async (id: string, payload: UserUpdate): Promise<User> => {
  40. return api.put<User>({
  41. url: `/users/${id}`,
  42. data: payload
  43. })
  44. },
  45. delete: async (id: string): Promise<void> => {
  46. return api.del({
  47. url: `/users/${id}`
  48. })
  49. }
  50. }
  51. /**
  52. * @deprecated 请使用 `@/api/authApi` 的 `fetchLogin`(门户 RSA + JWT)
  53. */
  54. export const UserService = {
  55. login: async (_username: string, _password: string): Promise<never> => {
  56. throw new Error('请使用 fetchLogin(@/api/authApi)登录门户账号')
  57. },
  58. getUserInfo: async (): Promise<never> => {
  59. throw new Error('请使用门户 /web/auth/current-user 获取用户信息')
  60. }
  61. }