From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/store/modules/mall/kefu.ts |   81 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/store/modules/mall/kefu.ts b/src/store/modules/mall/kefu.ts
new file mode 100644
index 0000000..2aecee0
--- /dev/null
+++ b/src/store/modules/mall/kefu.ts
@@ -0,0 +1,81 @@
+import { store } from '@/store'
+import { defineStore } from 'pinia'
+import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
+import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
+import { isEmpty } from '@/utils/is'
+
+interface MallKefuInfoVO {
+  conversationList: KeFuConversationRespVO[] // 浼氳瘽鍒楄〃
+  conversationMessageList: Map<number, KeFuMessageRespVO[]> // 浼氳瘽娑堟伅
+}
+
+export const useMallKefuStore = defineStore('mall-kefu', {
+  state: (): MallKefuInfoVO => ({
+    conversationList: [],
+    conversationMessageList: new Map<number, KeFuMessageRespVO[]>() // key 浼氳瘽锛寁alue 浼氳瘽娑堟伅鍒楄〃
+  }),
+  getters: {
+    getConversationList(): KeFuConversationRespVO[] {
+      return this.conversationList
+    },
+    getConversationMessageList(): (conversationId: number) => KeFuMessageRespVO[] | undefined {
+      return (conversationId: number) => this.conversationMessageList.get(conversationId)
+    }
+  },
+  actions: {
+    // ======================= 浼氳瘽娑堟伅鐩稿叧 =======================
+    /** 缂撳瓨鍘嗗彶娑堟伅 */
+    saveMessageList(conversationId: number, messageList: KeFuMessageRespVO[]) {
+      this.conversationMessageList.set(conversationId, messageList)
+    },
+
+    // ======================= 浼氳瘽鐩稿叧 =======================
+    /** 鍔犺浇浼氳瘽缂撳瓨鍒楄〃 */
+    async setConversationList() {
+      this.conversationList = await KeFuConversationApi.getConversationList()
+      this.conversationSort()
+    },
+    /** 鏇存柊浼氳瘽缂撳瓨宸茶 */
+    async updateConversationStatus(conversationId: number) {
+      if (isEmpty(this.conversationList)) {
+        return
+      }
+      const conversation = this.conversationList.find((item) => item.id === conversationId)
+      conversation && (conversation.adminUnreadMessageCount = 0)
+    },
+    /** 鏇存柊浼氳瘽缂撳瓨 */
+    async updateConversation(conversationId: number) {
+      if (isEmpty(this.conversationList)) {
+        return
+      }
+
+      const conversation = await KeFuConversationApi.getConversation(conversationId)
+      this.deleteConversation(conversationId)
+      conversation && this.conversationList.push(conversation)
+      this.conversationSort()
+    },
+    /** 鍒犻櫎浼氳瘽缂撳瓨 */
+    deleteConversation(conversationId: number) {
+      const index = this.conversationList.findIndex((item) => item.id === conversationId)
+      // 瀛樺湪鍒欏垹闄�
+      if (index > -1) {
+        this.conversationList.splice(index, 1)
+      }
+    },
+    conversationSort() {
+      // 鎸夌疆椤跺睘鎬у拰鏈�鍚庢秷鎭椂闂存帓搴�
+      this.conversationList.sort((a, b) => {
+        // 鎸夌収缃《鎺掑簭锛岀疆椤剁殑浼氬湪鍓嶉潰
+        if (a.adminPinned !== b.adminPinned) {
+          return a.adminPinned ? -1 : 1
+        }
+        // 鎸夌収鏈�鍚庢秷鎭椂闂存帓搴忥紝鏈�杩戠殑浼氬湪鍓嶉潰
+        return (b.lastMessageTime as unknown as number) - (a.lastMessageTime as unknown as number)
+      })
+    }
+  }
+})
+
+export const useMallKefuStoreWithOut = () => {
+  return useMallKefuStore(store)
+}

--
Gitblit v1.8.0