Ver Fonte

fix: 1.长链接添加了默认头像

suwenjiang há 1 mês atrás
pai
commit
e652859b7c

+ 1 - 1
.env.development

@@ -17,7 +17,7 @@ VITE_APP_ENV=development
 # 黄雯本地
 # VITE_APP_BASE_URL=http://192.168.1.44:8082/
 # 本地socoket
-# VITE_APP_IM_URL=ws://192.168.1.44:8082/system/message/
+# VITE_APP_IM_URL=ws://192.168.1.44:8082/system/message
 # 花生壳
 # VITE_APP_BASE_URL=http://q9943037p3.goho.co
 # VITE_APP_IM_URL=ws://q9943037p3.goho.co/system/message

+ 2 - 1
src/pages/chat/components/chat-message/index.vue

@@ -84,12 +84,13 @@ const msg = computed(() => {
       messageType,
       object = { headImageUrl: defaultAvatar, showName: '无名大侠' }
     } = props.message
+    const headImageUrl = props.message.headImageUrl || object.headImageUrl;
     return {
       messageContent: messageContent,
       type: getMessageType(messageType, messageContent),
       viewType: sendUserId === userInfo?.value.pass ? 0 : 1,
       createTime: createTime,
-      headImageUrl: object.headImageUrl,
+      headImageUrl: headImageUrl,
       nickName: object.showName
     }
   } catch (e) {

+ 22 - 9
src/pages/chat/group-chat.vue

@@ -40,18 +40,31 @@
     ></van-notice-bar>
 
     <template v-if="showPage">
-      <!-- <van-pull-refresh v-model="refreshing" @refresh="loadMore" class="flex-1"> -->
+      <!-- <van-pull-refresh
+        v-model="refreshing"
+        :disabled="moreDisabled"
+        head-height="50"
+        @refresh="loadMore"
+        class="flex-1"
+      > -->
       <van-list
         ref="chatListRef"
-        class="h-full overflow-y-auto px-12 flex flex-col"
+        class="flex-1 overflow-y-auto px-12 flex flex-col"
         :offset="50"
         v-model="loading"
         :finished="finished"
         direction="up"
         scroller
+        disabled
         finished-text=""
         @load="loadMore"
       >
+        <!-- <van-list
+          ref="chatListRef"
+          class="h-full overflow-y-auto px-12 flex flex-col"
+          finished-text=""
+          :finished="true"
+        > -->
         <!-- <div ref="chatListRef" class="h-full overflow-y-auto px-12 flex flex-col"> -->
         <template v-for="(message, index) in currConversationChatList" :key="index">
           <ChatMessage :show-name="true" :message="message"></ChatMessage>
@@ -275,16 +288,17 @@ const scrollToBottom = async () => {
 
 // 加载更多
 const refreshing = ref(false)
+const moreDisabled = ref(false)
 const loadMore = async () => {
   try {
-    // refreshing.value = true
-    loading.value = true
-    finished.value = true
+    refreshing.value = true
+    // loading.value = true
+    // finished.value = true
     if (currConversationChatList.value.length) {
       if (totalCount.value == currConversationChatList.value.length) {
         // 已经加载了全部
-        finished.value = false
-      } else {
+        moreDisabled.value = true
+        } else {
         await getChatList('more')
       }
     } else {
@@ -292,8 +306,7 @@ const loadMore = async () => {
     }
   } catch (e) {
   } finally {
-    loading.value = false
-    finished.value = false
+    refreshing.value = false
   }
 }
 

+ 4 - 3
src/pages/chat/set.vue

@@ -321,7 +321,7 @@
             />
           </template>
         </van-cell>
-        <van-cell
+        <!-- <van-cell
           @click="
             navigateTo({
               path: '/chat/background',
@@ -334,7 +334,7 @@
           is-link
           center
           title="设置当前聊天背景"
-        ></van-cell>
+        ></van-cell> -->
       </van-cell-group>
 
       <van-cell-group style="margin-bottom: 12px" inset>
@@ -865,7 +865,8 @@ function handleExitGroupChat() {
   })
     .then(async () => {
       const res = await request('/website/tourGroup/exitGroup', {
-        query: {
+        method: 'post',
+        body: {
           groupId: setData.id
         }
       })

+ 46 - 19
src/pages/chat/single-chat.vue

@@ -23,21 +23,27 @@
       </template>
     </van-nav-bar>
     <template v-if="showPage">
-      <!-- <van-pull-refresh v-model="refreshing" @refresh="loadMore" class="flex-1"> -->
-      <van-list
-        ref="chatListRef"
-        class="h-full overflow-y-auto px-12 flex flex-col"
-        :finished="true"
-        finished-text=""
+      <van-pull-refresh
+        v-model="moreLoading"
+        :disabled="moreDisabled"
+        @refresh="loadMore"
+        head-height="50"
+        class="flex-1"
       >
-        <template v-for="(message, index) in currConversationChatList" :key="index">
-          <ChatMessage :message="message"></ChatMessage>
-        </template>
-        <div v-if="false" class="text-[#979797] text-sm text-center mt-auto mb-10">
-          {{ followStatus }}在对方关注或回复前,最多只能发送1条信息
-        </div>
-      </van-list>
-      <!-- </van-pull-refresh> -->
+        <van-list
+          ref="chatListRef"
+          class="h-full overflow-y-auto px-12 flex flex-col"
+          finished-text=""
+          :finished="true"
+        >
+          <template v-for="(message, index) in currConversationChatList" :key="index">
+            <ChatMessage :message="message"></ChatMessage>
+          </template>
+          <div v-if="false" class="text-[#979797] text-sm text-center mt-auto mb-10">
+            {{ followStatus }}在对方关注或回复前,最多只能发送1条信息
+          </div>
+        </van-list>
+      </van-pull-refresh>
       <div class="h-70 w-full bg-[#fff]"></div>
       <div class="fixed bottom-0 left-0 right-0 w-full bg-[#fff]">
         <ChatInput
@@ -99,6 +105,7 @@ const initGroupId = async () => {
     groupId.value = res.data
     getAnnouncement()
     await getChatList('init')
+    await getFollowStatus()
   } catch (e) {
   } finally {
     pageLoading.value = false
@@ -140,7 +147,6 @@ const getChatList = async (type = 'init') => {
       currConversationChatList.value = resList
       await scrollToBottom()
     }
-    await getFollowStatus()
   } catch (e) {
     console.error(e)
   } finally {
@@ -241,7 +247,7 @@ const handleSendMessage = async ({ type, messageContent }) => {
 
 const scrollToBottom = async () => {
   // 操作向上加载不滚动 TODO 判断用户是否有向上滑的操作更准确
-  if (refreshing.value) return
+  if (moreLoading.value) return
   setTimeout(async () => {
     await nextTick() // 确保DOM已经更新
     const listElement = chatListRef.value?.$el
@@ -262,13 +268,18 @@ const getFollowStatus = async () => {
 }
 
 // 加载更多
-const refreshing = ref(false)
+const moreLoading = ref(false)
+const moreDisabled = ref(false)
+
 const loadMore = async () => {
+  console.warn('loadMore')
   try {
-    refreshing.value = true
+    moreLoading.value = true
     if (currConversationChatList.value.length) {
       if (totalCount.value === currConversationChatList.value.length) {
+        console.warn('已经加载了全部')
         // 已经加载了全部
+        moreDisabled.value = true
       } else {
         await getChatList('more')
       }
@@ -276,8 +287,9 @@ const loadMore = async () => {
       await getChatList('init')
     }
   } catch (e) {
+    console.log(e, 'error')
   } finally {
-    refreshing.value = false
+    moreLoading.value = false
   }
 }
 
@@ -333,6 +345,21 @@ async function getAnnouncement() {
     }
   }
 }
+// async function getAnnouncement() {
+//   let { data } = await request('/website/tourMember/getGroupUserListVo', {
+//     query: { groupId: groupId.value }
+//   })
+
+//   if (data) {
+//     if (Array.isArray(data.memberList) && data?.memberList?.length) {
+//       data.memberList.map((el) => {
+//         if (el.userId == userInfo.value.userId) {
+//           memberInfo.value = el
+//         }
+//       })
+//     }
+//   }
+// }
 
 // 用户删除消息
 const delMessage = (messageId) => {

+ 1 - 1
src/pages/profile/my-news/index.vue

@@ -25,7 +25,7 @@
       </div>
     </van-sticky>
 
-    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
+    <van-pull-refresh v-model="refreshing" head-height="100" @refresh="onRefresh">
       <div class="h-[100vh] overflow-y-auto">
         <van-list class="h-full" :finished="true" finished-text="">
           <div

+ 4 - 2
src/pages/profile/system-message/index.vue

@@ -23,10 +23,12 @@
               class="w-[91.2%] box-border h-103 mx-16 bg-white p-16 rounded-2xl"
             >
               <h1 class="text-black w-full line-clamp-1 text-2xl font-semibold mb-8">
-                {{ messageShowName(item?.messageContent).title }}
+                <!-- {{ messageShowName(item?.messageContent).title }} -->
+                {{ item?.messagePO.title }}
               </h1>
               <p class="line-clamp-2 w-full leading-3xl text-black-9 text-sm">
-                {{ messageShowName(item?.messageContent)?.messageContent }}
+                <!-- {{ messageShowName(item?.messageContent)?.content }} -->
+                {{ item?.messagePO?.content }}
               </p>
             </div>
           </div>

+ 32 - 35
src/stores/useChats.js

@@ -1,14 +1,14 @@
-import {XYWebSocket} from "~/utils/XYWebSocket";
-import {isValidJson} from "~/utils";
+import { XYWebSocket } from '~/utils/XYWebSocket'
+import { isValidJson } from '~/utils'
 
 export const useChatsStore = defineStore('chats', () => {
-  const userInfoStore = useUserInfoStore();
-  const {userInfo} = storeToRefs(userInfoStore);
+  const userInfoStore = useUserInfoStore()
+  const { userInfo } = storeToRefs(userInfoStore)
 
-  let socket = null;
+  let socket = null
   const initWebSocket = (url) => {
     if (!socket) {
-      socket = new XYWebSocket.WebSocketClass(url);
+      socket = new XYWebSocket.WebSocketClass(url)
       console.warn(socket, 'socket')
     }
   }
@@ -27,40 +27,37 @@ export const useChatsStore = defineStore('chats', () => {
   const getCurrConversationId = async (userId) => {
     try {
       return await request('/website/tourGroup/createMember', {
-        method: 'post', body: {
+        method: 'post',
+        body: {
           getUserId: userId,
           groupId: createGroupId()
         }
       })
     } catch (e) {
-
     } finally {
       currConversationLoading.value = false
-
     }
   }
 
   const getChatHistory = async (query) => {
-    return await request('/website/tourMessage/getMessageByGroupId', {query})
+    return await request('/website/tourMessage/getMessageByGroupId', { query })
   }
 
   const isRealMessage = (sendUserId) => {
     return sendUserId !== userInfo.value.pass
   }
 
-
   // 会话列表
-  let chatList = ref([]);
-  let chatListLoading = ref(false);
+  let chatList = ref([])
+  let chatListLoading = ref(false)
   const getChatList = async () => {
     try {
       if (chatListLoading.value) return
-      const res = await request('/website/tourism/fans/getTourMemberList');
+      const res = await request('/website/tourism/fans/getTourMemberList')
       await handleResponse(res)
-      const {list} = res.data;
-      chatList.value = list;
+      const { list } = res.data
+      chatList.value = list
     } catch (e) {
-
     } finally {
       chatListLoading.value = false
     }
@@ -74,27 +71,29 @@ export const useChatsStore = defineStore('chats', () => {
     socketStatus.value = status
   })
 
-
   const createGroupId = () => Date.now() + '' + Math.floor(Math.random() * 100000)
 
-  // 处理后端接口回来的sendUserId被修改
+  // 处理后端接口回来的消息体
+  // 修正sendUserId被后端修改
   const handleMessageList = (list) => {
-    return (list ?? []).filter(o => isValidJson(o.messageContent)).map(o => {
-      let messageContent = JSON.parse(o.messageContent)
-      messageContent.sendUserId = o.sendUserId;
-      messageContent.messageId = o.id;
-      // console.log(messageContent, 'messageContent')
-
-      return messageContent
-    });
+    return (list ?? [])
+      .filter((o) => isValidJson(o.messageContent))
+      .map((o) => {
+        let messageContent = JSON.parse(o.messageContent)
+        messageContent.sendUserId = o.sendUserId
+        messageContent.messageId = o.id
+        messageContent.headImageUrl = o.headImageUrl
+        // console.log(messageContent, 'messageContent')
+        return messageContent
+      })
   }
 
   const MESSAGE_TYPE = {
-    'text': 0,
-    'image': 1,
-    'audio': 2,
-    'video': 3,
-    'link': 4
+    text: 0,
+    image: 1,
+    audio: 2,
+    video: 3,
+    link: 4
   }
   const NOTICE_TYPE = []
 
@@ -116,10 +115,8 @@ export const useChatsStore = defineStore('chats', () => {
     chatListLoading,
     getChatList,
 
-
     // 排除自己发的消息
     isRealMessage,
     handleMessageList
-
   }
-})
+})