From fa2098c56557d61553b962f8bd1ae553a23e1fe7 Mon Sep 17 00:00:00 2001 From: wangyifeng <812766448@qq.com> Date: Mon, 24 Mar 2025 20:03:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86oa=E5=BA=95=E9=83=A8tabbar?= =?UTF-8?q?=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E6=95=B0=E9=87=8F=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 2 + src/api/chat/index.js | 14 ++++- src/event/talk.js | 65 +++++++++++++------- src/pages/chooseChat/components/chatItem.vue | 43 ++++++++----- src/pages/chooseChat/index.vue | 2 +- src/pages/dialog/index.vue | 3 +- src/pages/index/components/chatItem.vue | 22 ++++--- src/pages/index/index.vue | 22 ++++--- src/store/modules/dialogue.js | 5 ++ src/store/modules/dialogueList.js | 1 + 10 files changed, 120 insertions(+), 59 deletions(-) diff --git a/components.d.ts b/components.d.ts index 2811a17..334d110 100644 --- a/components.d.ts +++ b/components.d.ts @@ -30,6 +30,8 @@ declare module 'vue' { LoginMessage: typeof import('./src/components/talk/message/LoginMessage.vue')['default'] Message: typeof import('./src/components/x-message/message/index.vue')['default'] MixedMessage: typeof import('./src/components/talk/message/MixedMessage.vue')['default'] + NButton: typeof import('naive-ui')['NButton'] + NIcon: typeof import('naive-ui')['NIcon'] PageAnimation: typeof import('./src/components/page-animation/index.vue')['default'] RevokeMessage: typeof import('./src/components/talk/message/RevokeMessage.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] diff --git a/src/api/chat/index.js b/src/api/chat/index.js index e3a0491..83ad329 100644 --- a/src/api/chat/index.js +++ b/src/api/chat/index.js @@ -38,7 +38,19 @@ export const ServeTopTalkList = (data) => { } // 清除聊天消息未读数服务接口 -export const ServeClearTalkUnreadNum = (data) => { +export const ServeClearTalkUnreadNum = (data, unReadNum) => { + console.log("=======chatApp==UnreadNum",unReadNum) + if (typeof plus !== 'undefined') { + let OAWebView = plus.webview.all() + //all里面第一个是入口webview + OAWebView[0].evalJS(`updateUnreadMsgNumReduce('${unReadNum}')`) + } else { + document.addEventListener('plusready', () => { + let OAWebView = plus.webview.all() + //all里面第一个是入口webview + OAWebView[0].evalJS(`updateUnreadMsgNumReduce('${unReadNum}')`) + }) + } return request({ url: '/api/v1/talk/unread/clear', method: 'POST', diff --git a/src/event/talk.js b/src/event/talk.js index 5c0dbfd..420d285 100644 --- a/src/event/talk.js +++ b/src/event/talk.js @@ -5,8 +5,16 @@ import { parseTime } from '@/utils/datetime' import * as message from '@/constant/message' import { formatTalkItem, palyMusic, formatTalkRecord } from '@/utils/talk' // import { isElectronMode } from '@/utils/common' -import { ServeClearTalkUnreadNum, ServeCreateTalkList } from '@/api/chat/index.js' -import { useTalkStore, useDialogueStore,useDialogueListStore,useGroupStore } from '@/store' +import { + ServeClearTalkUnreadNum, + ServeCreateTalkList, +} from '@/api/chat/index.js' +import { + useTalkStore, + useDialogueStore, + useDialogueListStore, + useGroupStore, +} from '@/store' /** * 好友状态事件 @@ -49,7 +57,7 @@ class Talk extends Base { this.receiver_id = resource.receiver_id this.talk_type = resource.talk_type // this.fileNum = resource.file_num - if(resource.file_num){ + if (resource.file_num) { resource.data.file_num = resource.file_num } this.resource = resource.data @@ -98,7 +106,6 @@ class Talk extends Base { play() { // 客户端有消息提示 // if (isElectronMode()) return - // useSettingsStore().isPromptTone && palyMusic() } @@ -118,6 +125,17 @@ class Talk extends Base { this.insertTalkRecord() } else { this.updateTalkItem() + if (typeof plus !== 'undefined') { + let OAWebView = plus.webview.all() + //all里面第一个是入口webview + OAWebView[0].evalJS(`updateUnreadMsgNumAdd()`) + } else { + document.addEventListener('plusready', () => { + let OAWebView = plus.webview.all() + //all里面第一个是入口webview + OAWebView[0].evalJS(`updateUnreadMsgNumAdd()`) + }) + } } } @@ -132,7 +150,6 @@ class Talk extends Base { // lang: 'zh-CN', // body: '您有新的消息请注意查收' // }) - // notification.onclick = () => { // notification.close() // } @@ -160,7 +177,7 @@ class Talk extends Base { ServeCreateTalkList({ talk_type, - receiver_id + receiver_id, }).then(({ code, data }) => { if (code == 200) { let item = formatTalkItem(data) @@ -175,8 +192,8 @@ class Talk extends Base { */ insertTalkRecord() { let record = this.resource - let newRecord = formatTalkRecord(this.getAccountId(), this.resource); - const {addDialogueRecord,addChatRecord} = useDialogueListStore() + let newRecord = formatTalkRecord(this.getAccountId(), this.resource) + const { addDialogueRecord, addChatRecord } = useDialogueListStore() // 群成员变化的消息,需要更新群成员列表 if ([1102, 1103, 1104, 1115].includes(record.msg_type)) { useDialogueStore().updateGroupMembers() @@ -194,13 +211,15 @@ class Talk extends Base { avatar: record.extra.group_avatar, }) // 更新会话列表中的会话信息 - const dialogue = useDialogueListStore().getDialogueList(`${record.talk_type}_${record.receiver_id}`) + const dialogue = useDialogueListStore().getDialogueList( + `${record.talk_type}_${record.receiver_id}`, + ) if (dialogue) { dialogue.talk.username = record.extra.group_name } } - addDialogueRecord([newRecord],'add') - addChatRecord(this.getIndexName(),newRecord) + addDialogueRecord([newRecord], 'add') + addChatRecord(this.getIndexName(), newRecord) useDialogueStore().addDialogueRecord(newRecord) if (!this.isCurrSender()) { @@ -208,7 +227,7 @@ class Talk extends Base { setTimeout(() => { ws.emit('im.message.read', { receiver_id: this.sender_id, - msg_ids: [this.resource.msg_id] + msg_ids: [this.resource.msg_id], }) }, 1000) } @@ -218,7 +237,8 @@ class Talk extends Base { if (!el) return // 判断的滚动条是否在底部 - const isBottom = Math.ceil(el.scrollTop) + el.clientHeight >= el.scrollHeight + const isBottom = + Math.ceil(el.scrollTop) + el.clientHeight >= el.scrollHeight if (isBottom || record.user_id == this.getAccountId()) { nextTick(() => { @@ -231,14 +251,15 @@ class Talk extends Base { useTalkStore().updateItem({ index_name: this.getIndexName(), msg_text: this.getTalkText(), - updated_at: parseTime(new Date()) + updated_at: parseTime(new Date()), }) if (this.talk_type == 1 && this.getAccountId() !== this.sender_id) { - ServeClearTalkUnreadNum({ - talk_type: 1, - receiver_id: this.sender_id - }) + //不在此处维护未读消息数量 + // ServeClearTalkUnreadNum({ + // talk_type: 1, + // receiver_id: this.sender_id, + // }) } } @@ -249,11 +270,13 @@ class Talk extends Base { useTalkStore().updateMessage({ index_name: this.getIndexName(), msg_text: this.getTalkText(), - updated_at: parseTime(new Date()) + updated_at: parseTime(new Date()), }) - if(this.resource.msg_type == 1116){ + if (this.resource.msg_type == 1116) { // 更新会话列表中的会话信息 - const dialogue = useDialogueListStore().getDialogueList(`${this.resource.talk_type}_${this.resource.receiver_id}`) + const dialogue = useDialogueListStore().getDialogueList( + `${this.resource.talk_type}_${this.resource.receiver_id}`, + ) if (dialogue) { dialogue.talk.username = this.resource.extra.group_name } diff --git a/src/pages/chooseChat/components/chatItem.vue b/src/pages/chooseChat/components/chatItem.vue index 97d5f18..9fb2e3c 100644 --- a/src/pages/chooseChat/components/chatItem.vue +++ b/src/pages/chooseChat/components/chatItem.vue @@ -17,10 +17,17 @@
@@ -30,16 +37,18 @@ class="text-[#171717] text-[32rpx] font-medium leading-[44rpx]" > {{ props.data.name }} - ({{ props.data.group_member_num }}) + + ({{ props.data.group_member_num }}) + - 部门 - - - 项目 - - - 公司 - + 部门 + + + 项目 + + + 公司 +
@@ -127,7 +136,7 @@ const cellClick = () => { opacity: 40%; } -.tag{ +.tag { display: inline-flex; align-items: center; text-align: center; @@ -142,16 +151,16 @@ const cellClick = () => { font-weight: bold; } .companyTag { - border: 1px solid #7a58de; - color: #7a58de; + border: 1px solid #7a58de; + color: #7a58de; } .depTag { - border: 1px solid #377ec6; - color: #377ec6; + border: 1px solid #377ec6; + color: #377ec6; } .projectTag { - border: 1px solid #c1681c; - color: #c1681c; + border: 1px solid #c1681c; + color: #c1681c; } .textEllipsis { diff --git a/src/pages/chooseChat/index.vue b/src/pages/chooseChat/index.vue index 16c5e9d..89e0aea 100644 --- a/src/pages/chooseChat/index.vue +++ b/src/pages/chooseChat/index.vue @@ -219,7 +219,7 @@ watch( onMounted(() => { talkStore.loadTalkList() console.log(talkStore.talkItems) - items.value = lodash.cloneDeep(talkStore.talkItems) + items.value = lodash.cloneDeep(talkStore.talkItems).filter(item=>item.is_dismiss === 0 && item.is_quit === 0) }) onUnmounted(() => { dialogueStore.setForwardType('') diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue index 0e11345..0d60671 100644 --- a/src/pages/dialog/index.vue +++ b/src/pages/dialog/index.vue @@ -544,6 +544,7 @@ const talkParams = reactive({ isDismiss: computed(() => dialogueStore.isDismiss), isQuit: computed(() => dialogueStore.isQuit), adminList: computed(() => dialogueStore.getAdminList), + unReadNum: computed(() => dialogueStore.unreadNum), }) const state = ref({ @@ -597,7 +598,7 @@ uniOnUnload(() => { ServeClearTalkUnreadNum({ talk_type: Number(talkParams.type), receiver_id: Number(talkParams.receiver_id), - }).then(() => { + },talkParams.unReadNum).then(() => { talkStore.updateItem({ index_name: talkParams.index_name, unread_num: 0, diff --git a/src/pages/index/components/chatItem.vue b/src/pages/index/components/chatItem.vue index acdbb4f..7e194cf 100644 --- a/src/pages/index/components/chatItem.vue +++ b/src/pages/index/components/chatItem.vue @@ -107,6 +107,9 @@ import { useSessionMenu } from '@/hooks' const talkStore = useTalkStore() const { onToTopTalk, onRemoveTalk } = useSessionMenu() const dialogueStore = useDialogueStore() +const dialogueParams = reactive({ + unReadNum: computed(() => dialogueStore.unreadNum), +}) const props = defineProps({ data: { type: Object, @@ -132,15 +135,16 @@ const cellClick = () => { // 清空消息未读数 if (props.data.unread_num > 0) { - ServeClearTalkUnreadNum({ - talk_type: props.data.talk_type, - receiver_id: props.data.receiver_id, - }).then(() => { - talkStore.updateItem({ - index_name: props.data.index_name, - unread_num: 0, - }) - }) + //不在此处维护未读消息数量 + // ServeClearTalkUnreadNum({ + // talk_type: props.data.talk_type, + // receiver_id: props.data.receiver_id, + // },dialogueParams.unReadNum).then(() => { + // talkStore.updateItem({ + // index_name: props.data.index_name, + // unread_num: 0, + // }) + // }) } uni.navigateTo({ url: `/pages/dialog/index?sessionId=${props.data.id}`, diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 4122846..8422900 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -138,6 +138,9 @@ const isEmptyViewShow = ref(false) const talkStore = useTalkStore() const userStore = useUserStore() const dialogueStore = useDialogueStore() +const dialogueParams = reactive({ + unReadNum: computed(() => dialogueStore.unreadNum), +}) const { userInfo } = useAuth() const topItems = computed(() => talkStore.topItems) @@ -241,15 +244,16 @@ onLoad((options) => { setTimeout(() => { dialogueStore.setDialogue(openSession) if (openSession.unread_num > 0) { - ServeClearTalkUnreadNum({ - talk_type: openSession.talk_type, - receiver_id: openSession.receiver_id, - }).then(() => { - talkStore.updateItem({ - index_name: openSession.index_name, - unread_num: 0, - }) - }) + //不在此处维护未读消息数量 + // ServeClearTalkUnreadNum({ + // talk_type: openSession.talk_type, + // receiver_id: openSession.receiver_id, + // },dialogueParams.unReadNum).then(() => { + // talkStore.updateItem({ + // index_name: openSession.index_name, + // unread_num: 0, + // }) + // }) } uni.navigateTo({ url: `/pages/dialog/index?sessionId=${openSession.id}`, diff --git a/src/store/modules/dialogue.js b/src/store/modules/dialogue.js index 69844b7..1f568e8 100644 --- a/src/store/modules/dialogue.js +++ b/src/store/modules/dialogue.js @@ -54,6 +54,9 @@ export const useDialogueStore = defineStore('dialogue', { //是否退群/移出群 isQuit: false, + //未读消息数量 + unreadNum:0, + // 群成员列表 members: [], @@ -107,6 +110,8 @@ export const useDialogueStore = defineStore('dialogue', { this.isDismiss = data?.is_dismiss === 1 ? true : false this.isQuit = data?.is_quit === 1 ? true : false + this.unreadNum = data?.unread_num || 0 + this.members = [] if (data.talk_type == 2) { this.updateGroupMembers() diff --git a/src/store/modules/dialogueList.js b/src/store/modules/dialogueList.js index bb9c073..3c3cdc5 100644 --- a/src/store/modules/dialogueList.js +++ b/src/store/modules/dialogueList.js @@ -42,6 +42,7 @@ export const useDialogueListStore = createGlobalState(() => { isShowSessionList: dialogue.isShowSessionList, isDismiss: dialogue.isDismiss, isQuit: dialogue.isQuit, + unreadNum: dialogue.unreadNum, members: dialogue.members.map(member => ({ id: member.id, nickname: member.nickname,