ChatApi.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import FetchRequest from '@/api/FetchRequest'
  2. import type Chat from '@/mode/Chat'
  3. import type AjaxResult from '@/mode/AjaxResult'
  4. class ChatApi {
  5. static url = '/api/sys/chat'
  6. /**
  7. * 获取当前用户的非置顶聊天列表
  8. */
  9. static list(): Promise<AjaxResult<Chat[]>> {
  10. return FetchRequest.get(`${this.url}/list`, true)
  11. }
  12. /**
  13. * 获取当前用户的置顶聊天列表
  14. */
  15. static topList(): Promise<AjaxResult<Chat[]>> {
  16. return FetchRequest.get(`${this.url}/topList`, true)
  17. }
  18. /**
  19. * 新增聊天
  20. * @param chat chat
  21. */
  22. static add(chat: Chat): Promise<AjaxResult<boolean>> {
  23. return FetchRequest.post(this.url, JSON.stringify(chat), true)
  24. }
  25. /**
  26. * 更新聊天
  27. * @param chat chat
  28. */
  29. static update(chat: Chat): Promise<AjaxResult<boolean>> {
  30. const chatTemp = JSON.parse(JSON.stringify(chat))
  31. chatTemp.unreadCount = 0
  32. return FetchRequest.put(this.url, JSON.stringify(chatTemp), true)
  33. }
  34. /**
  35. * 批量更新聊天
  36. * @param chatList chatList
  37. */
  38. static batch(chatList: Array<Chat>): Promise<AjaxResult<boolean>> {
  39. const chatListTemp = JSON.parse(JSON.stringify(chatList))
  40. chatListTemp.forEach((chat:Chat) => {
  41. chat.unreadCount = 0
  42. })
  43. return FetchRequest.put(`${this.url}/batch`, JSON.stringify(chatListTemp), true)
  44. }
  45. /**
  46. * 移动聊天室位置
  47. * @param chatId chatId
  48. */
  49. static move(chatId: string): void {
  50. FetchRequest.get(`${this.url}/move?chatId=${chatId}`, true)
  51. }
  52. /**
  53. * 置顶聊天
  54. * @param chatId chatId
  55. */
  56. static top(chatId: string): Promise<AjaxResult<boolean>> {
  57. return FetchRequest.get(`${this.url}/top?chatId=${chatId}`, true)
  58. }
  59. /**
  60. * 取消置顶聊天
  61. * @param chatId 收藏id
  62. */
  63. static cancelTop(chatId: string): Promise<AjaxResult<boolean>> {
  64. return FetchRequest.get(`${this.url}/cancelTop?chatId=${chatId}`, true)
  65. }
  66. /**
  67. * 删除聊天
  68. * @param chatId 聊天id
  69. */
  70. static delete(chatId: string): Promise<AjaxResult<boolean>> {
  71. return FetchRequest.del(`${this.url}/${chatId}`, '', true)
  72. }
  73. }
  74. export default ChatApi