hookehuyr

feat(chat): 添加聊天相关API接口实现

实现获取消息列表、消息详情、聊天会话、聊天列表和发送消息的API接口
1 +import { fn, fetch } from '@/api/fn';
2 +
3 +const Api = {
4 + GET_MESSAGES_LIST: '/srv/?a=message&t=list',
5 + GET_MESSAGES_DETAIL: '/srv/?a=message&t=system_detail',
6 + GET_CHAT_CONVERSATION: '/srv/?a=message&t=chat_conversation',
7 + GET_CHAT_LIST: '/srv/?a=message&t=chat_list',
8 + SEND_CHAT: '/srv/?a=message&t=chat_send',
9 +}
10 +
11 +/**
12 + * @description: 所有消息列表
13 + * @param {*} params
14 + * @param {number} params.page - 页码,从0开始
15 + * @param {number} params.limit - 每页数量
16 + * @returns data.list[{
17 + * id: 如果是系统消息,则ID是消息ID,如果是聊天消息,则ID是聊天室ID
18 + * type: 消息类型, system=系统消息,chat=买卖双方聊天
19 + * status: 消息状态, 3=未读,5=已读
20 + * note: 消息内容
21 + * create_time: 创建时间
22 + * created_time_desc: 消息创建时间描述
23 + * }]
24 + */
25 +export const getMessagesListAPI = (params) => fn(fetch.get(Api.GET_MESSAGES_LIST, params));
26 +
27 +/**
28 + * @description: 系统消息详情
29 + * @param {*} params
30 + * @param {number} params.id - 系统消息ID
31 + * @returns data{
32 + * id: 系统消息ID
33 + * type: 消息类型 system=系统消息,chat=买卖双方聊天
34 + * status: 消息状态, 3=未读,5=已读
35 + * note: 消息内容
36 + * create_time: 创建时间
37 + * created_time_desc: 消息创建时间描述
38 + * }
39 + */
40 +export const getMessagesDetailAPI = (params) => fn(fetch.get(Api.GET_MESSAGES_DETAIL, params));
41 +
42 +/**
43 + * @description: 获取聊天室ID
44 + * @param {*} params
45 + * @param {number} params.buyer_id - 买方ID
46 + * @param {number} params.seller_id - 卖方ID
47 + * @param {number} params.vehicle_id - 车辆ID
48 + * @returns data{
49 + * conversation_id: 会话ID
50 + * }
51 +*/
52 +export const getChatConversationAPI = (params) => fn(fetch.get(Api.GET_CHAT_CONVERSATION, params));
53 +
54 +/**
55 + * @description: 聊天消息列表
56 + * @param {*} params
57 + * @param {number} params.conversation_id - 会话ID
58 + * @param {number} params.page - 页码,从0开始
59 + * @param {number} params.limit - 每页数量
60 + * @returns data.list[{
61 + * id: 聊天消息ID
62 + * type: 消息类型 system=系统消息,chat=买卖双方聊天
63 + * status: 消息状态, 3=未读,5=已读
64 + * note: 消息内容
65 + * create_time: 创建时间
66 + * created_time_desc: 消息创建时间描述
67 + * }]
68 + * @returns 聊天对象 data.receiver{
69 + * id: ID
70 + * nickname: 昵称
71 + * avatar: 头像
72 + * }
73 +*/
74 +export const getChatListAPI = (params) => fn(fetch.get(Api.GET_CHAT_LIST, params));
75 +
76 +/**
77 + * @description: 发送聊天消息
78 + * @param {*} params
79 + * @param {number} params.conversation_id - 会话ID
80 + * @param {string} params.note - 消息内容
81 + * @returns data{
82 + * id: 聊天消息ID
83 + * }
84 +*/
85 +export const sendChatAPI = (params) => fn(fetch.post(Api.SEND_CHAT, params));