From 089bf5d2378b3c4a61d795b2a92bede2c193b771 Mon Sep 17 00:00:00 2001
From: admin <344137771@qq.com>
Date: Tue, 06 Jan 2026 11:22:58 +0800
Subject: [PATCH] 1
---
src/store/modules/talk.js | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 150 insertions(+), 0 deletions(-)
diff --git a/src/store/modules/talk.js b/src/store/modules/talk.js
new file mode 100644
index 0000000..bec208d
--- /dev/null
+++ b/src/store/modules/talk.js
@@ -0,0 +1,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
--
Gitblit v1.9.3