10.10综合交易所原始源码-管理后台
admin
2026-01-06 a3cc41349752d6fb067df2a58e4e4b723a915f21
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { getSort, getMutipSort } from '@/utils/functions'
import { ServeGetTalkList } from '@/api/chat'
import { formateTalkItem } from '@/utils/talk'
 
const Talk = {
  state: {
    loadStatus: 0, // 加载状态[1:未加载;2:加载中;3:加载完成;4:加载失败;]
 
    // 会话列表
    items: [],
 
    // 最后一条消息
    unreadMessage: {
      num: 0,
      nickname: '未知',
      content: '...',
    },
 
    imageViewer: {
      isShow: false,
      file: null,
    },
 
 
    status: 0, //0:加载,1:加载中
    clinkStatus:0, //0:加载,1:加载中
    sendStatus:0, //0:加载,1:加载中
  },
  getters: {
    // 过滤所有置顶对话列表
    topItems: state => {
      return state.items.filter(item => item.is_top == 1)
    },
    talkItems: state => {
      return state.items.sort(
        getMutipSort([getSort((a, b) => a.updated_at > b.updated_at)])
      )
    },
    // 消息未读数总计
    unreadNum: state => {
      return state.items.reduce((total, item) => {
        return total + parseInt(item.unread_num)
      }, 0)
    },
    talkNum: state => state.items.length,
    imageViewer: state => state.imageViewer,
  },
  mutations: {
    SET_STATUS(state, resource) {
      state.status = resource
    },
    SET_CLINK_STATUS(state, resource) {
      state.clinkStatus = resource
    },
    SET_SEND_STATUS(state, resource) {
      state.sendStatus = resource
    },
    //
    SET_LOAD_STATUS(state, resource) {
      state.loadStatus = resource
    },
 
    // 设置对话列表
    SET_TALK_ITEMS(state, resource) {
      state.items = resource.items
    },
 
    // 更新对话节点
    UPDATE_TALK_ITEM(state, resource) {
      for (const iterator of state.items) {
        if (iterator.index_name === resource.index_name) {
          Object.assign(iterator, resource)
          break
        }
      }
    },
 
    // 新增对话节点
    PUSH_TALK_ITEM(state, resource) {
      state.items.push(resource)
    },
 
    // 移除对话节点
    REMOVE_TALK_ITEM(state, index_name) {
      for (let i in state.items) {
        if (state.items[i].index_name === index_name) {
          state.items.splice(i, 1)
          break
        }
      }
    },
 
    // 更新对话消息
    UPDATE_TALK_MESSAGE(state, resource) {
      for (const iterator of state.items) {
        if (iterator.index_name !== resource.index_name) {
          continue
        }
 
        iterator.unread_num++
        iterator.msg_text = resource.msg_text
        iterator.updated_at = resource.updated_at
        break
      }
    },
 
    SET_TLAK_UNREAD_MESSAGE(state, resource) {
      state.unreadMessage.num++
      state.unreadMessage.nickname = resource.nickname
      state.unreadMessage.content = resource.content
    },
 
    // 清除最后一条未读消息
    CLEAR_TLAK_UNREAD_MESSAGE(state) {
      state.unreadMessage = {
        num: 0,
        nickname: '未知',
        content: '...',
      }
    },
 
    SET_IMAGE_VIEWER(state, resource){
      state.imageViewer.isShow = resource.isShow;
      state.imageViewer.file = resource.file;
    }
 
  },
  actions: {
    // 加载会话列表
    LOAD_TALK_ITEMS(context) {
      context.commit('SET_LOAD_STATUS', 2)
 
      ServeGetTalkList()
        .then(({ code, data }) => {
          if (code !== 200) return
 
          context.commit('SET_TALK_ITEMS', {
            items: data.map(item => formateTalkItem(item)),
          })
          
          context.commit('SET_LOAD_STATUS', 3)
        })
        .catch(() => {
          context.commit('SET_LOAD_STATUS', 4)
        })
    },
  },
}
 
export default Talk