Răsfoiți Sursa

fix: 1.移除的页面

suwenjiang 1 lună în urmă
părinte
comite
04aefe2e77

+ 1 - 1
src/pages/chat/group-add.vue

@@ -245,7 +245,7 @@ async function handleCreateGroup() {
     })
     if (data) {
       navigateTo({
-        path: '/chat/group-chat',
+        path: '/chat/group',
         query: data,
         replace: true
       })

+ 76 - 80
src/pages/chat/group-chat.vue

@@ -3,7 +3,7 @@
     <van-nav-bar @click-left="router.back()" @click-right="onClickRight">
       <template #left>
         <div>
-          <van-icon name="arrow-left" color="black" size="18"/>
+          <van-icon name="arrow-left" color="black" size="18" />
         </div>
       </template>
       <template #title>
@@ -19,7 +19,7 @@
         </div>
       </template>
       <template #right>
-        <van-icon name="ellipsis" color="black" size="18"/>
+        <van-icon name="ellipsis" color="black" size="18" />
       </template>
     </van-nav-bar>
 
@@ -32,19 +32,23 @@
 
     <template v-if="showPage">
       <van-list
-          ref="chatListRef"
-          class="flex-1 overflow-y-auto px-12 flex flex-col"
-          :finished="true"
-          finished-text=""
+        ref="chatListRef"
+        class="flex-1 overflow-y-auto px-12 flex flex-col"
+        :finished="true"
+        finished-text=""
       >
         <template v-for="(message, index) in currConversationChatList" :key="index">
-          <ChatMessage :show-name="true" :message="message" ></ChatMessage>
+          <ChatMessage :show-name="true" :message="message"></ChatMessage>
         </template>
       </van-list>
       <!--  <van-pull-refresh v-model="refreshing" @refresh="loadMore" class="flex-1">
             </van-pull-refresh>-->
       <!--      <div class="fixed bottom-0 left-0 right-0 w-full">-->
-      <ChatInput :operates="['image', 'share-group']" @focus="scrollToBottom" @send="handleSendMessage"></ChatInput>
+      <ChatInput
+        :operates="['image', 'share-group']"
+        @focus="scrollToBottom"
+        @send="handleSendMessage"
+      ></ChatInput>
       <!--      </div>-->
     </template>
     <template v-else>
@@ -53,7 +57,7 @@
         <div v-else class="grid place-items-center">
           <div v-if="groupId">创建成功</div>
           <div v-else class="grid place-items-center">
-            <div  class="mb-10">创建会话失败</div>
+            <div class="mb-10">创建会话失败</div>
             <van-button size="small" @click="initGroupId">点击重试</van-button>
           </div>
         </div>
@@ -63,16 +67,16 @@
 </template>
 <script setup>
 import ChatMessage from './chat-message'
-import ChatInput from "./chat-input";
-import {findHyperlinks} from "~/pages/chat/chat-message/link-message/handle";
-import {XYWebSocket} from "~/utils/XYWebSocket";
-import {isValidJson} from "~/utils";
+import ChatInput from './chat-input'
+import { findHyperlinks } from '~/pages/chat/chat-message/link-message/handle'
+import { XYWebSocket } from '~/utils/XYWebSocket'
+import { isValidJson } from '~/utils'
 
 const route = useRoute()
 const router = useRouter()
 
-const chatsStore = useChatsStore();
-const userInfoStore = useUserInfoStore();
+const chatsStore = useChatsStore()
+const userInfoStore = useUserInfoStore()
 
 const { userInfo } = storeToRefs(userInfoStore)
 // 群聊的标题
@@ -81,34 +85,32 @@ const groupInfo = ref({})
 const groupMemberInfo = ref({})
 
 // 聊天列表
-const chatListRef = ref(null);
+const chatListRef = ref(null)
 
-const pageLoading = ref(true);
-const getUserId = ref(null); // 消息接收者的用户id
+const pageLoading = ref(true)
+const getUserId = ref(null) // 消息接收者的用户id
 const sendUserId = computed(() => userInfo?.value.pass) // 消息发送者:当前登录用户的加密id
-const groupId = ref(route.query?.groupId); // 会话ID
+const groupId = ref(route.query?.groupId) // 会话ID
 const showPage = computed(() => groupId.value)
 
 const initGroupId = async () => {
   try {
-    if (!groupId.value) return;
-/*
+    if (!groupId.value) return
+    /*
     pageLoading.value = true;
     const res = await chatsStore.getCurrConversationId(getUserId.value)
     await handleResponse(res)
     groupId.value = res.data;*/
     await getAnnouncement()
     await getChatList('init')
-
   } catch (e) {
-
   } finally {
-    pageLoading.value = false;
+    pageLoading.value = false
   }
 }
 
 let pageNum = ref(0)
-const currConversationChatList = ref([]);
+const currConversationChatList = ref([])
 /**
  * 加载当前聊天信息
  * @param type init|more
@@ -116,22 +118,27 @@ const currConversationChatList = ref([]);
  */
 const getChatList = async (type = 'init') => {
   try {
-    const page = type === 'init' ? 1 : pageNum.value + 1;
+    const page = type === 'init' ? 1 : pageNum.value + 1
     const res = await chatsStore.getChatHistory({
       pageNum: page,
       pageSize: 100,
-      groupId: groupId.value,
+      groupId: groupId.value
     })
-    pageNum.value = page;
-    await handleResponse(res);
-    currConversationChatList.value = chatsStore.handleMessageList(res.data?.data)
+    pageNum.value = page
+    await handleResponse(res)
+    currConversationChatList.value = handleChatList(res.data?.data)
+    console.log(currConversationChatList.value, 'currConversationChatList')
     if (type === 'init') await scrollToBottom()
   } catch (e) {
     console.error(e)
   } finally {
-
   }
 }
+const handleChatList = (list = []) => {
+  return (list ?? [])
+    .filter((o) => isValidJson(o.messageContent))
+    .map((o) => JSON.parse(o.messageContent))
+}
 
 // 发送文本消息
 const sendTextMessage = async (text) => {
@@ -154,7 +161,7 @@ const sendTextMessage = async (text) => {
       }
     }
     const isLink = !!findHyperlinks(text)
-    if (isLink) msg.messageType = 4;
+    if (isLink) msg.messageType = 4
     currConversationChatList.value.push(msg)
     await scrollToBottom()
     const res = await chatsStore.sendSocketMessage(msg)
@@ -162,7 +169,6 @@ const sendTextMessage = async (text) => {
   } catch (e) {
     console.log(e, '2')
   } finally {
-
   }
 }
 
@@ -173,7 +179,7 @@ const sendImageMessage = async (file) => {
     formData.append('uploadFile', file)
     formData.append('asImage', true)
     formData.append('fieldName', 'messageContent')
-    const {data} = await request('/website/tourMessage/upload', {
+    const { data } = await request('/website/tourMessage/upload', {
       method: 'post',
       body: formData
     })
@@ -199,44 +205,37 @@ const sendImageMessage = async (file) => {
   } catch (e) {
     console.error(e, '??')
   } finally {
-
   }
 }
 
-const handleSendMessage = async ({type, messageContent}) => {
+const handleSendMessage = async ({ type, messageContent }) => {
   try {
     switch (type) {
       case 'text':
         await sendTextMessage(messageContent)
-        break;
+        break
       case 'image':
         await sendImageMessage(messageContent)
-        break;
+        break
 
       default:
-
-        break;
+        break
     }
-
   } catch (e) {
-
   } finally {
-
   }
 }
 
 const scrollToBottom = async () => {
   setTimeout(async () => {
-    await nextTick(); // 确保DOM已经更新
-    const listElement = chatListRef.value?.$el;
+    await nextTick() // 确保DOM已经更新
+    const listElement = chatListRef.value?.$el
     if (listElement) {
-      const scrollContainer = listElement;
-      scrollContainer.scrollTop = scrollContainer.scrollHeight;
+      const scrollContainer = listElement
+      scrollContainer.scrollTop = scrollContainer.scrollHeight
     }
   }, 200)
-};
-
-
+}
 
 // 加载更多
 const refreshing = ref(false)
@@ -244,19 +243,20 @@ const loadMore = async () => {
   try {
     refreshing.value = true
     await getChatList('more')
-  } catch (e) { } finally {
+  } catch (e) {
+  } finally {
     refreshing.value = false
   }
 }
 
 const onClickRight = () => {
-  groupId.value && navigateTo({
-    path: '/chat/set',
-    query: {groupId: groupId.value}
-  })
+  groupId.value &&
+    navigateTo({
+      path: '/chat/set',
+      query: { groupId: groupId.value }
+    })
 }
 
-
 // 本地生成一个唯一消息id
 function getLocalId() {
   const random = Math.floor(Math.random() * 10000)
@@ -267,17 +267,11 @@ onMounted(() => {
   initGroupId()
 
   XYWebSocket.SocketEventsBus.on(XYWebSocket.SocketEvents.chatEvent, async (chat) => {
-    console.log('订阅群聊消息', chat)
-    const isCurrGroupId = chat.groupId && chat.groupId === groupId.value;
-    const isOtherUserMessage = chat.sendUserId && chatsStore.isRealMessage(chat.sendUserId);
-    if(isCurrGroupId) {
-      if (isOtherUserMessage) {
-        currConversationChatList.value.push(chat)
-        await scrollToBottom()
-      }
-      if(!isOtherUserMessage) {
-        await getChatList('init')
-      }
+    const isCurrGroupId = chat.groupId && chat.groupId === groupId.value
+    const isOtherUserMessage = chat.sendUserId && chatsStore.isRealMessage(chat.sendUserId)
+    if (isCurrGroupId && isOtherUserMessage) {
+      currConversationChatList.value.push(chat)
+      await scrollToBottom()
     }
   })
 })
@@ -287,12 +281,15 @@ async function getAnnouncement() {
   let { data } = await request('/website/tourGroup/getGroupInfoAndMemberByGroupId', {
     query: { groupId: groupId.value }
   })
+  console.log(data.memberList)
 
   if (data) {
     groupInfo.value = data
-    if (Array.isArray(data.memberList) && data.memberList?.lenght) {
-      data.memberList.map((el) => {
+    if (Array.isArray(data?.memberList) && data?.memberList?.lenght) {
+      data?.memberList?.map((el) => {
         if (el.userId == userInfo.value.userId) {
+          // console.log(el, '8888-------')
+
           groupMemberInfo.value = el
         }
       })
@@ -307,19 +304,18 @@ const delMessage = (messageId) => {
     message: '是否删除这条消息?',
     confirmButtonColor: '#FF9300'
   })
-      .then(async () => {
-        const res = await request('/website/tourMessage/delMessage', {
-          method: 'post',
-          body: {
-            messageId: [messageId]
-          }
-        })
-
-        if (res && res?.success) {
+    .then(async () => {
+      const res = await request('/website/tourMessage/delMessage', {
+        method: 'post',
+        body: {
+          messageId: [messageId]
         }
       })
-      .catch(() => {
-      })
+
+      if (res && res?.success) {
+      }
+    })
+    .catch(() => {})
 }
 
 definePageMeta({

+ 20 - 8
src/pages/chat/group-member.vue

@@ -22,7 +22,7 @@
         <div style="height: calc(100vh - 170px)">
           <van-checkbox-group v-model="checked">
             <template v-for="item in addDataList" :key="item.userId">
-              <van-cell center clickable @click.stop="toggle(item)">
+              <van-cell v-if="item.groupRole != 1" center clickable @click.stop="toggle(item)">
                 <template #icon>
                   <div class="flex justify-start">
                     <van-checkbox
@@ -120,6 +120,9 @@ const checkboxRefs = ref([])
 const checkedList = ref([])
 const checkedId = ref([])
 
+const addDataList = ref([])
+const filterDataList = ref([])
+
 onMounted(() => {
   getList()
 })
@@ -137,16 +140,22 @@ const search = () => {
   finished.value = false
 }
 
-const toggle = (id) => {
-  let index = checked.value.findIndex((el) => el?.id == id)
+const toggle = (item) => {
+  // let index2 = checked.value.findIndex((el) => el?.id == item.id)
+  let index = checkedList.value.findIndex((el) => el?.userId == item?.userId)
 
+  // if (index2 != -1) {
+  //   checkedId.value.splice(index2, 1)
+  // } else {
+  //   checkedId.value.push(id)
+  // }
   if (index != -1) {
-    checkedId.value.splice(index, 1)
+    checkedList.value.splice(index, 1)
   } else {
-    checkedId.value.push(id)
+    checkedList.value.push(item)
   }
-  console.log(checkedId.value, 'checkedId.value')
-  checkboxRefs.value[id].toggle()
+  console.log(checked.value, 'checkedId.value')
+  checkboxRefs.value[item.userId].toggle()
 }
 
 // 获取群设置的配置信息
@@ -158,9 +167,12 @@ const getList = async () => {
         groupId: route.query.groupId
       }
     })
+    console.log(data?.memberList, '555')
 
-    if (Array.isArray(data?.memberList) && data.memberList?.length) {
+    if (Array.isArray(data?.memberList) && data?.memberList?.length) {
       addDataList.value = data?.memberList
+      console.log(addDataList.value, '55')
+
       filterDataList.value = data?.memberList
     } else {
       filterDataList.value = []

+ 28 - 27
src/pages/chat/set.vue

@@ -196,11 +196,12 @@
       >
         <van-cell size="large" center title="个人主页展示">
           <template #label>
-            <!-- class="text-base text-black/[0.4]" -->
             <span>开启后,在群聊广场和个人主页</span>
           </template>
           <template #right-icon>
             <van-switch
+              :active-value="1"
+              :inactive-value="0"
               v-model="isPublic"
               @click="changeIsPublic"
               active-color="#FF9300"
@@ -216,6 +217,8 @@
           </template>
           <template #right-icon>
             <van-switch
+              :active-value="1"
+              :inactive-value="0"
               v-model="isNeedConfirm"
               @click="changeIsNeedConfirm"
               active-color="#FF9300"
@@ -285,21 +288,20 @@
         <van-cell size="large" is-link center title="消息免打扰">
           <template #right-icon>
             <van-switch
+              :active-value="1"
+              :inactive-value="0"
               v-model="isNotDisturb"
               @click="handleIsNotDisturb"
               active-color="#FF9300"
               inactive-color="#dcdee0"
             />
-            <!-- @change="
-                (val) => {
-                  isNotDisturb = val
-                }
-              " -->
           </template>
         </van-cell>
         <van-cell size="large" is-link center title="置顶聊天">
           <template #right-icon>
             <van-switch
+              :active-value="1"
+              :inactive-value="0"
               v-model="isTop"
               @click="handleIsTop"
               active-color="#FF9300"
@@ -492,11 +494,12 @@ const groupName = ref('')
 // isPublic 是否公开展示 0隐藏 1公开。
 // isNeedConfirm 是否开启群聊邀请确认 0不开启 1开启。
 // 是否显示到个人主页
-const isPublic = ref(false)
-const isNeedConfirm = ref(false)
-const isNotDisturb = ref(false)
+const isPublic = ref(0)
+const isNeedConfirm = ref(0)
+
 const showBelongTypeId = ref(false)
-const isTop = ref(false)
+const isNotDisturb = ref(0)
+const isTop = ref(0)
 
 // 弹出窗
 const showDialog = ref(false)
@@ -558,12 +561,12 @@ const changeGroupName = async (body) => {
 
 // 是否开启群验证
 const changeIsNeedConfirm = async () => {
-  changeGroupBelongTypeIdIsNeedConfirm({ isNeedConfirm: changeStateBoolean(isNeedConfirm.value) })
+  changeGroupBelongTypeIdIsNeedConfirm({ isNeedConfirm: isNeedConfirm.value })
 }
 
 // 是否公开展示
 const changeIsPublic = async () => {
-  changeGroupBelongTypeIdIsNeedConfirm({ isPublic: changeStateBoolean(isPublic.value) })
+  changeGroupBelongTypeIdIsNeedConfirm({ isPublic: isPublic.value })
 }
 
 const showIndex = ref(null)
@@ -691,12 +694,14 @@ const changeStateBoolean = (state) => {
 
 // 是否置顶
 const handleIsTop = () => {
-  handleBoolean({ isTop: changeStateBoolean(isTop.value) })
+  // handleBoolean({ isTop: changeStateBoolean(isTop.value) })
+  handleBoolean({ isTop: isTop.value })
 }
 
 // 是否免打扰
 const handleIsNotDisturb = () => {
-  handleBoolean({ isNotDisturb: changeStateBoolean(isNotDisturb.value) })
+  // handleBoolean({ isNotDisturb: changeStateBoolean(isNotDisturb.value) })
+  handleBoolean({ isNotDisturb: isNotDisturb.value })
 }
 
 // 是否免打扰和 是否置顶 公共
@@ -729,22 +734,18 @@ const getGroupSetData = async () => {
   })
   if (typeof data == 'object') {
     setData = data
-    console.log(setData.id, 'setDataid')
-    console.log(setData, 'setData')
-
-    console.log(data.memberList, '555')
-    console.log(userInfo.value.userId, 'userInfo')
-
-    userGroupData.value = data.memberList.find((item) => item.userId == userInfo.value.userId)
 
-    console.log(userGroupData.value, '4444')
-    console.log(userGroupData.value.groupRole, 'userGroupData groupRole')
+    userGroupData.value = data?.memberList.find((item) => item?.userId == userInfo.value?.userId)
 
-    isPublic.value = changeState(setData.isPublic)
-    isNeedConfirm.value = changeState(setData.isNeedConfirm)
+    // isPublic.value = changeState(setData.isPublic)
+    // isNeedConfirm.value = changeState(setData.isNeedConfirm)
+    isPublic.value = setData.isPublic
+    isNeedConfirm.value = setData.isNeedConfirm
 
-    isNotDisturb.value = changeState(userGroupData.value?.isNotDisturb)
-    isTop.value = changeState(userGroupData.value.isTop)
+    // isNotDisturb.value = changeState(userGroupData.value?.isNotDisturb)
+    // isTop.value = changeState(userGroupData.value.isTop)
+    isNotDisturb.value = userGroupData.value?.isNotDisturb
+    isTop.value = userGroupData.value.isTop
   }
 }