Jelajahi Sumber

消息问题

zhangyaowen 3 bulan lalu
induk
melakukan
19a9fbbb53

+ 3 - 1
pages/chat/index.vue

@@ -160,13 +160,15 @@ const { options } = useWebSocket({
   onConnected: async () => { },
   // 收到消息
   onMessage: async (data) => {
+    console.log(data, 'data');
     const type = data.type;
     if (!type) {
       console.error('未知的消息类型:' + data);
       return;
     }
     // 2.2 消息类型:KEFU_MESSAGE_TYPE
-    if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_TYPE) {
+    if (type === WebSocketMessageTypeConstants.KEFU_MESSAGE_IM) {
+      console.log('客服消息IM');
       // 刷新消息列表
       await messageListRef.value.refreshMessageList(jsonParse(data.content));
       return;

+ 5 - 4
pages/chat/util/constants.js

@@ -5,8 +5,8 @@ export const KeFuMessageContentTypeEnum = {
   VIDEO: 4, // 视频消息
   SYSTEM: 5, // 系统消息
   // ========== 商城特殊消息 ==========
-  PRODUCT: 10,//  产品消息
-  ORDER: 11,//  订单消息"
+  PRODUCT: 10, //  产品消息
+  ORDER: 11, //  订单消息"
 };
 export const UserTypeEnum = {
   MEMBER: 1, // 会员 面向 c 端,普通用户
@@ -15,5 +15,6 @@ export const UserTypeEnum = {
 // Promotion 的 WebSocket 消息类型枚举类
 export const WebSocketMessageTypeConstants = {
   KEFU_MESSAGE_TYPE: 'kefu_message_type', // 客服消息类型
-  KEFU_MESSAGE_ADMIN_READ: 'kefu_message_read_status_change' // 客服消息管理员已读
-}
+  KEFU_MESSAGE_ADMIN_READ: 'kefu_message_read_status_change', // 客服消息管理员已读
+  KEFU_MESSAGE_IM: 'kefu_message_im', // 客服消息IM
+};

+ 34 - 16
pages/user/consultationRecords.vue

@@ -1,22 +1,26 @@
 <template>
   <s-layout :bgStyle="{ color: '#f2f2f2' }" title="咨询记录">
-    <view class="chat-list">
-      <view v-for="item in chatList" :key="item.id" class="chat-item" @click="goToChat(item)">
-        <view class="avatar">
-          <image :src="item.userAvatar || activityright" mode="aspectFill"></image>
-        </view>
-        <view class="content">
-          <view class="top">
-            <text class="nickname">{{ item.userNickname }}</text>
-            <text class="time">{{ formatTime(item.lastMessageTime) }}</text>
+    <scroll-view scroll-y="true" refresher-enabled="true" :refresher-triggered="triggered"
+      @refresherrefresh="onRefresh">
+      <view class="chat-list">
+        <view v-for="item in chatList" :key="item.id" class="chat-item" @click="goToChat(item)">
+          <view class="avatar">
+            <image :src="item.userAvatar || activityright" mode="aspectFill"></image>
+          </view>
+          <view class="content">
+            <view class="top">
+              <text class="nickname">{{ item.userNickname }}</text>
+              <text class="time">{{ formatTime(item.lastMessageTime) }}</text>
+            </view>
+            <view class="message">{{ parseMessage(item.lastMessageContent) }}</view>
+          </view>
+          <view v-if="item.relUserId == userInfo.id ? item.relUnreadMessageCount : item.adminUnreadMessageCount"
+            class="unread-count">
+            {{ item.relUserId == userInfo.id ? item.relUnreadMessageCount : item.adminUnreadMessageCount }}
           </view>
-          <view class="message">{{ parseMessage(item.lastMessageContent) }}</view>
-        </view>
-        <view v-if="item.adminUnreadMessageCount" class="unread-count">
-          {{ item.adminUnreadMessageCount }}
         </view>
       </view>
-    </view>
+    </scroll-view>
   </s-layout>
 </template>
 
@@ -24,7 +28,7 @@
 import sheep from '@/sheep';
 import { reactive, ref, toRefs, computed } from 'vue';
 import { useWebSocket } from '@/sheep/hooks/useWebSocket';
-import { onLoad } from '@dcloudio/uni-app';
+import { onLoad, onShow } from '@dcloudio/uni-app';
 import SpuHistoryApi from '@/sheep/api/product/history';
 import activityright from '@/static/activity-right.png'
 import {
@@ -32,6 +36,7 @@ import {
   WebSocketMessageTypeConstants,
 } from '@/pages/chat/util/constants';
 const chatList = ref([]);
+const triggered = ref(false);
 
 const conversationListAxios = async () => {
   const res = await SpuHistoryApi.conversationList();
@@ -40,6 +45,12 @@ const conversationListAxios = async () => {
   }
 }
 
+const onRefresh = async () => {
+  triggered.value = true;
+  await conversationListAxios();
+  triggered.value = false;
+}
+
 const formatTime = (timestamp) => {
   const date = new Date(timestamp);
   const now = new Date();
@@ -61,6 +72,9 @@ const userInfo = computed(() => sheep.$store('user').userInfo);
 console.log(userInfo.value.id, 44444)
 const goToChat = (item) => {
   console.log(item, 44444)
+  SpuHistoryApi.updateKefuMessageReadStatus({
+    conversationId: item.id,
+  })
   sheep.$router.go('/pages/chat/index', { conversationId: item.id, relUserId: userInfo.value.id === item.relUserId ? item.userId : item.relUserId })
 
 }
@@ -86,14 +100,18 @@ const { options } = useWebSocket({
   },
 });
 const isReconnecting = toRefs(options).isReconnecting; // 重连状态
-onLoad(() => {
+onShow(() => {
   conversationListAxios();
+})
+onLoad(() => {
+  // conversationListAxios();
 });
 </script>
 
 <style lang="scss" scoped>
 .chat-list {
   padding: 20rpx;
+  height: calc(100vh - var(--window-top));
 
   .chat-item {
     display: flex;

+ 8 - 0
sheep/api/product/history.js

@@ -13,6 +13,14 @@ const SpuHistoryApi = {
       },
     });
   },
+  // 更新客服消息已读状态
+  updateKefuMessageReadStatus: (params) => {
+    return request({
+      url: '/promotion/kefu-message/update-read-status',
+      method: 'PUT',
+      params,
+    });
+  },
   // 清空产品浏览记录
   cleanBrowseHistory: () => {
     return request({

+ 1 - 0
sheep/components/s-menu-tools/s-menu-tools.vue

@@ -8,6 +8,7 @@
         <view class="list-item ss-m-b-24" v-for="item in list" :key="item.title">
           <view class="ss-flex-col ss-col-center">
             <button class="ss-reset-button list-image ss-flex ss-row-center ss-col-center" @tap="onClick(item)">
+              {{ sheep.$url.static(item.icon) }}
               <image v-if="show" :src="sheep.$url.static(item.icon)" class="list-icon" />
             </button>
             <view class="list-title ss-m-t-20">{{ item.title }}</view>

+ 1 - 1
sheep/store/app.js

@@ -66,7 +66,7 @@ const app = defineStore({
           copyright: '全部开源,个人与企业可 100% 免费使用',
           copytime: 'Copyright© 2018-2024',
 
-          cdnurl: 'https://file.sheepjs.com', // 云存储域名
+          cdnurl: 'http://42.194.163.46:9095', //'https://file.sheepjs.com', // 云存储域名
           filesystem: 'qcloud', // 云存储平台
         };
         this.platform = {