1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| export default {
| state: {
| // 对话来源[1:私聊;2:群聊]
| talk_type: 0,
|
| // 接收者ID
| receiver_id: 0,
|
| is_robot: 0,
|
| // 聊天记录
| records: [
| {
| id: "",
| createTime: "",
| toUser: "",
| isRead: false,
| messageType: "",
| talkId: "",
| text: "",
| float: "",
| },
| ],
| webSocketWithOut:false, // ws 是否是掉线 无输出状态
| // 对话索引(聊天对话的唯一索引)
| index_name: null,
| },
| mutations: {
| // 设置ws状态
| SET_WS_STATUS: (state,resource) =>{
| state.webSocketWithOut = resource
| },
| // 更新对话
| UPDATE_DIALOGUE_MESSAGE (state, resource) {
| state.records = [];
| state.talk_type = parseInt(resource.talk_type);
| state.receiver_id = parseInt(resource.receiver_id);
| state.is_robot = parseInt(resource.is_robot);
|
| /**
| * receiver_id 就是 好友id
| * 比如 a 和 b 聊天 receiver_id = b的id
| */
| state.index_name = (resource.talk_type || 1) + "_" + resource.receiver_id;
| },
|
| // 数组头部压入对话记录1494593861786271744 1494593778193793024
| UNSHIFT_DIALOGUE (state, records) {
| // console.log("%c 数组头部压入对话记录", "color:green");
| // console.log("state", state);
| // console.log("records", records);
| if (state.records.length > 0) {
| state.records.unshift(...records);
| } else {
| state.records.push(...records);
| }
|
| // console.log("最后的数据",state.records)
| },
|
| // 推送对话记录
| PUSH_DIALOGUE (state, record) {
| record = {...record,webSocketStatus:state.webSocketWithOut}
| console.log("推送对话",)
| state.records.push(record);
| },
|
| // 更新对话记录
| UPDATE_DIALOGUE (state, resource) {
| for (let i in state.records) {
| if (state.records[i].id === resource.id) {
| Object.assign(state.records[i], resource);
| break;
| }
| }
| },
|
| // 删除对话记录
| DELETE_DIALOGUE (state, index) {
| state.records.splice(index, 1);
| },
|
| BATCH_DELETE_DIALOGUE (state, ids) {
| ids.forEach((record_id) => {
| let index = state.records.findIndex((item) => item.id == record_id);
| if (index >= 0) state.records.splice(index, 1);
| });
| },
|
| // 数组头部压入对话记录
| SET_DIALOGUE (state, records) {
| state.records = records;
| },
| },
| };
|
|