From 6f1e429e1cca3ea47425fee7dabebc748013f1d1 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 29 Oct 2023 23:10:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A5=BD=E5=8F=8B?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E6=9C=AA=E8=AF=BB=E6=95=B0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=A5=BD=E5=8F=8B?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E8=A2=AB=E5=90=8C=E6=84=8F=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=94=B6=E5=88=B0=E5=AF=B9=E6=96=B9=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=9A=84=E6=B6=88=E6=81=AF=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components.d.ts | 2 ++ src/services/apis.ts | 2 ++ src/services/urls.ts | 1 + src/stores/chat.ts | 16 ++++++++-------- src/stores/contacts.ts | 15 +++++++++++++++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/components.d.ts b/src/components.d.ts index 2d6f2716..2ff4683e 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -16,6 +16,8 @@ declare module '@vue/runtime-core' { ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElBadge: typeof import('element-plus/es')['ElBadge'] ElButton: typeof import('element-plus/es')['ElButton'] + ElCollapse: typeof import('element-plus/es')['ElCollapse'] + ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem'] ElDialog: typeof import('element-plus/es')['ElDialog'] ElDivider: typeof import('element-plus/es')['ElDivider'] ElDrawer: typeof import('element-plus/es')['ElDrawer'] diff --git a/src/services/apis.ts b/src/services/apis.ts index 89e65466..daf6343c 100644 --- a/src/services/apis.ts +++ b/src/services/apis.ts @@ -83,6 +83,8 @@ export default { putRequest(urls.sendAddFriendRequest, params), /** 同意好友申请 */ deleteFriend: (params: { targetUid: number }) => deleteRequest(urls.deleteFriend, params), + /** 好友申请未读数 */ + newFriendCount: () => getRequest<{ unReadCount: number }>(urls.newFriendCount), /** 会话列表 */ getSessionList: (params?: any) => getRequest>(urls.getSessionList, params), diff --git a/src/services/urls.ts b/src/services/urls.ts index adc6fe2f..0299e203 100644 --- a/src/services/urls.ts +++ b/src/services/urls.ts @@ -24,6 +24,7 @@ export default { requestFriendList: `${prefix}/capi/user/friend/apply/page`, // 好友申请列表 sendAddFriendRequest: `${prefix}/capi/user/friend/apply`, // 申请好友 deleteFriend: `${prefix}/capi/user/friend`, // 删除好友 + newFriendCount: `${prefix}/capi/user/friend/apply/unread`, // 申请未读数 // -------------- 聊天室相关 --------------- getSessionList: `${prefix}/capi/chat/public/contact/page`, // 会话列表 diff --git a/src/stores/chat.ts b/src/stores/chat.ts index 7a8952ef..0d3b005d 100644 --- a/src/stores/chat.ts +++ b/src/stores/chat.ts @@ -2,7 +2,7 @@ import { ref, reactive, computed, watch } from 'vue' import { defineStore } from 'pinia' import cloneDeep from 'lodash/cloneDeep' import { useRoute } from 'vue-router' -import Router from '@/router' +// import Router from '@/router' import apis from '@/services/apis' import type { MessageType, MarkItemType, RevokedMsgType, SessionItem } from '@/services/types' import { MarkEnum, RoomTypeEnum } from '@/enums' @@ -280,14 +280,14 @@ export const useChatStore = defineStore('chat', () => { if (globalStore.currentSession && globalStore.currentSession.roomId !== msg.message.roomId) { let result = undefined // 如果当前路由不是聊天,就开始拿会话详情,并手动新增一条会话记录 - if (route?.path && route?.path !== '/') { - globalStore.currentSession.roomId = msg.message.roomId - globalStore.currentSession.type = RoomTypeEnum.Single - if (!current) { - result = await apis.sessionDetail({ id: msg.message.roomId }).send() - } - Router.push('/') + // if (route?.path && route?.path !== '/') { + // globalStore.currentSession.roomId = msg.message.roomId + // globalStore.currentSession.type = RoomTypeEnum.Single + if (!current) { + result = await apis.sessionDetail({ id: msg.message.roomId }).send() } + // Router.push('/') + // } updateSessionLastActiveTime(msg.message.roomId, result) } diff --git a/src/stores/contacts.ts b/src/stores/contacts.ts index f55fa097..3bb15b99 100644 --- a/src/stores/contacts.ts +++ b/src/stores/contacts.ts @@ -39,6 +39,19 @@ export const useContactStore = defineStore('contact', () => { contactsOptions.isLoading = false } + /** 好友申请未读数 */ + const getNewFriendCount = async () => { + const data = await apis + .newFriendCount() + .send() + .catch(() => { + // + }) + if (typeof data?.unReadCount === 'number') { + globalStore.unReadMark.newFriendUnreadCount = data.unReadCount + } + } + const getRequestFriendsList = async (isFresh = false) => { if (!isFresh) { if (requestFriendsOptions.isLast || requestFriendsOptions.isLoading) return @@ -53,6 +66,8 @@ export const useContactStore = defineStore('contact', () => { .catch(() => { requestFriendsOptions.isLoading = false }) + // 每次加载完新的好友邀请列表都要更新申请未读数 + getNewFriendCount() if (!data) return isFresh ? requestFriendsList.splice(0, requestFriendsList.length, ...data.list)