FriendApi.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import FetchRequest from "@/api/FetchRequest";
  2. import type Friend from "@/mode/Friend";
  3. class FriendApi {
  4. static url = "/api/sys/friends";
  5. /**
  6. * 获取用户的所有好友
  7. * @param id 用户ID
  8. */
  9. static friends(): Promise<any> {
  10. return FetchRequest.get(`${this.url}?state=0`, true);
  11. }
  12. /**
  13. * 获取用户的待审核好友
  14. */
  15. static validateList(): Promise<any> {
  16. return FetchRequest.get(`${this.url}/validateList`, true);
  17. }
  18. /**
  19. * 添加好友
  20. * @param friend 好友
  21. */
  22. static add(friend: Friend): Promise<any> {
  23. return FetchRequest.post(`${this.url}/add`, JSON.stringify(friend), true);
  24. }
  25. /**
  26. * 审核好友
  27. * @param userId 用户ID
  28. * @param friendId 好友
  29. * @param state 状态
  30. */
  31. static check(userId: string, friendId: string, state: string): Promise<any> {
  32. const data = {
  33. friendId: friendId.toString(),
  34. state: state.toString(),
  35. };
  36. console.log('check',data)
  37. return FetchRequest.patch(
  38. `${this.url}/${userId}`,
  39. JSON.stringify(data),
  40. true
  41. );
  42. }
  43. /**
  44. * 同意加好友
  45. * @param friendId 好友ID
  46. */
  47. static agree(friendId: string): Promise<any> {
  48. return FetchRequest.post(`${this.url}/agree`, friendId, true);
  49. }
  50. /**
  51. * 删除好友
  52. * @param friendId 好友ID
  53. */
  54. static delete(friendId: string): Promise<any> {
  55. return FetchRequest.del(`${this.url}/delete`, friendId, true);
  56. }
  57. /**
  58. * 判断是否好友
  59. */
  60. static isFriend(friendId: string): Promise<any> {
  61. return FetchRequest.get(`${this.url}/isFriend?friendId=${friendId}`, true);
  62. }
  63. }
  64. export default FriendApi;