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 @@