From 331ca65db6a0b905c7b33fe3d9b744613ca2e4e5 Mon Sep 17 00:00:00 2001 From: wangyifeng <812766448@qq.com> Date: Wed, 28 May 2025 15:40:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=96=B0=E7=89=88=E5=B7=B2?= =?UTF-8?q?=E8=AF=BB=E5=9B=9E=E6=89=A7=E8=A7=84=E5=88=99=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=EF=BC=8C=E5=A4=84=E7=90=86=E7=9B=B8=E5=BA=94=E7=9A=84socket?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E7=9B=91=E5=90=AC=E3=80=81=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=B7=B2=E8=AF=BB=E6=9C=AA=E8=AF=BB=E6=95=B0=E9=87=8F=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=92=8C=E8=AF=A6=E6=83=85=E5=88=97=E8=A1=A8=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/chat.js | 5 + src/components/search/searchByCondition.vue | 34 +- src/connect.ts | 13 +- src/event/read.js | 54 ++++ src/types/chat.ts | 4 +- src/views/message/inner/IndexContent.vue | 8 + .../message/inner/panel/PanelContent.vue | 300 +++++++++++++----- 7 files changed, 323 insertions(+), 95 deletions(-) create mode 100644 src/event/read.js diff --git a/src/api/chat.js b/src/api/chat.js index 3273fc5..df04eb1 100644 --- a/src/api/chat.js +++ b/src/api/chat.js @@ -94,3 +94,8 @@ export const ServeConfirmVoteHandle = (data = {}) => { export const ServeEmptyMessage = (data) => { return post('/api/v1/talk/message/empty', data) } + +//获取消息已读未读详情 +export const ServeMessageReadDetail = (data) => { + return post('/api/v1/talk/my-records/read/condition', data) +} diff --git a/src/components/search/searchByCondition.vue b/src/components/search/searchByCondition.vue index 0fe4f4f..9936ece 100644 --- a/src/components/search/searchByCondition.vue +++ b/src/components/search/searchByCondition.vue @@ -327,7 +327,7 @@ import { parseTime } from '@/utils/datetime' import { fileFormatSize, fileSuffix } from '@/utils/strings' import { NImage, NInfiniteScroll, NScrollbar, NIcon, NDatePicker } from 'naive-ui' -const emits = defineEmits(['clearSearchMemberByAlphabet', 'getDisabledDateArray']) +const emits = defineEmits(['clearSearchMemberByAlphabet', 'getDisabledDateArray', 'hideSearchResultModal']) const dialogueStore = useDialogueStore() // 当前对话参数 @@ -736,15 +736,29 @@ const downloadAndOpenFile = (item) => { //跳转到对应的记录位置 const toDialogueByMember = async (msgInfo) => { - const sessionId = await getSessionId(dialogueParams.talk_type, dialogueParams.receiver_id) - uni.navigateTo({ - url: - '/pages/dialog/index?sessionId=' + - sessionId + - '&keepDialogInfo=1' + - '&msgInfo=' + - encodeURIComponent(JSON.stringify(msgInfo)) - }) + console.error('====跳转到对应的记录位置====', msgInfo) + // 根据搜索结果, 指定用于查询指定消息上下文的sequence + dialogueStore.specifiedMsg = encodeURIComponent( + JSON.stringify({ + talk_type: msgInfo.talk_type, + receiver_id: msgInfo.receiver_id, + msg_id: msgInfo.msg_id, + cursor: msgInfo.sequence - 15 > 0 ? msgInfo.sequence - 15 : 0, + direction: 'down', + sort_sequence: 'asc', + create_time: msgInfo.created_at + }) + ) + emits('hideSearchResultModal') + // const sessionId = await getSessionId(dialogueParams.talk_type, dialogueParams.receiver_id) + // uni.navigateTo({ + // url: + // '/pages/dialog/index?sessionId=' + + // sessionId + + // '&keepDialogInfo=1' + + // '&msgInfo=' + + // encodeURIComponent(JSON.stringify(msgInfo)) + // }) } //重置部分搜索条件 diff --git a/src/connect.ts b/src/connect.ts index 96e1458..d07e3c3 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -7,6 +7,7 @@ import EventTalk from './event/talk' import EventKeyboard from './event/keyboard' import EventLogin from './event/login' import EventRevoke from './event/revoke' +import EventRead from './event/read' import { getAccessToken, isLoggedIn } from './utils/auth' const urlCallback = () => { @@ -85,6 +86,7 @@ class Connect { this.onImContactStatus() this.onImMessageRevoke() this.onImMessageKeyboard() + this.onImMessageListenRead() this.onImMessageListenReadIncr() } @@ -132,11 +134,14 @@ class Connect { this.conn.on('im.message.revoke', (data: any) => new EventRevoke(data)) } + onImMessageListenRead() { + // 消息已读回执监听事件(全量) + this.conn.on('im.message.listen.read', (data: any) => new EventRead(data, 'total')) + } + onImMessageListenReadIncr() { - // 消息已读回执监听事件 - this.conn.on('im.message.listen.read.incr', (data: any) => { - console.error('====接收到了新版已读回执增量=====', data) - }) + // 消息已读回执监听事件(增量) + this.conn.on('im.message.listen.read.incr', (data: any) => new EventRead(data, 'incr')) } onImContactApply() { diff --git a/src/event/read.js b/src/event/read.js new file mode 100644 index 0000000..5c74b49 --- /dev/null +++ b/src/event/read.js @@ -0,0 +1,54 @@ +import Base from './base' +import { useTalkStore, useDialogueStore } from '@/store' +import ws from '@/connect' +import { bus } from '@/utils/event-bus' + +/** + * 已读回执事件 + */ +class Read extends Base { + /** + * @var resource 资源 + */ + resource + + /** + * 场景类型 + */ + type + + /** + * 初始化构造方法 + * + * @param {Object} resource Socket消息 + */ + constructor(resource, type) { + super() + + this.resource = resource + this.type = type + this.handle() + } + + handle() { + if (this.type == 'total') { + console.error('====接收到了新版已读回执全量=====', this.resource) + const readList = this.resource.result + if (readList.length > 0) { + readList.forEach((item) => { + useDialogueStore().updateDialogueRecord({ + msg_id: item.msg_id, + read_total_num: item.read_total_num + }) + }) + } + } else if (this.type == 'incr') { + console.error('====接收到了新版已读回执增量=====', this.resource) + // 由于直接使用增量的数值,会导致消息列表的已读回执数量不准确,可能多可能少 + // 所以收到增量消息后,直接手动触发一次查询全量 + bus.emit('check-visible-out-elements', 'incr') + } + } +} + +export default Read diff --git a/src/types/chat.ts b/src/types/chat.ts index caef493..fe75240 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -49,8 +49,8 @@ export interface ITalkRecord { send_status: number float: string, is_convert_text?:number//语音记录的 是否是在展示转文本状态 1:是 0:否, - erp_user_id:number - + erp_user_id:number, + read_total_num:number } export interface ITalkRecordExtraText { diff --git a/src/views/message/inner/IndexContent.vue b/src/views/message/inner/IndexContent.vue index f744553..346cb99 100644 --- a/src/views/message/inner/IndexContent.vue +++ b/src/views/message/inner/IndexContent.vue @@ -481,6 +481,12 @@ const onDatePickShow = (show) => { // state.nowDateTime = new Date() } } + +// 隐藏搜索结果模态框 +const hideSearchResultModal = () => { + handleSearchRecordByConditionModalClose() + state.isShowGroupAside = false +}