增强IM聊天功能,支持群聊会话的打开与处理,优化消息过滤逻辑,提升用户体验。
This commit is contained in:
@@ -223,10 +223,19 @@
|
||||
async function showMessageDetail(record){
|
||||
if (isImChatNotice(record)) {
|
||||
//update-begin---author:xsl ---date:20260528 for:【IM聊天-OA】统一 IM 打开入口,全页优先-----------
|
||||
//update-begin---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息支持打开群聊会话-----------
|
||||
if (record.imConvType === 'group') {
|
||||
const mode = await openImChat({ conversationId: record.imConversationId });
|
||||
if (mode === 'modal') {
|
||||
openImChatModal(true, { conversationId: record.imConversationId });
|
||||
}
|
||||
} else {
|
||||
const mode = await openImChat({ targetUserId: record.imTargetUserId, pageContext: null });
|
||||
if (mode === 'modal') {
|
||||
openImChatModal(true, { targetUserId: record.imTargetUserId, pageContext: null });
|
||||
}
|
||||
}
|
||||
//update-end---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息支持打开群聊会话-----------
|
||||
//update-end---author:xsl ---date:20260528 for:【IM聊天-OA】统一 IM 打开入口,全页优先-----------
|
||||
emit('close-modal');
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
import { fetchDeptMembers } from '/@/views/system/im/im.api';
|
||||
//update-begin---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
import { fetchDeptMembers, fetchGroups } from '/@/views/system/im/im.api';
|
||||
//update-end---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
import { formatImMessagePreview } from '/@/views/system/im/imMessageUtil';
|
||||
|
||||
export const IM_CHAT_BUS_TYPE = 'im_chat';
|
||||
@@ -27,6 +29,12 @@ export interface ImChatNoticeRecord {
|
||||
imTargetUsername?: string;
|
||||
imAvatar?: string;
|
||||
imUnreadCount?: number;
|
||||
//update-begin---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
/** 会话类型:single 单聊 / group 群聊 */
|
||||
imConvType?: 'single' | 'group';
|
||||
/** 群聊会话 ID(群聊提醒打开会话时使用) */
|
||||
imConversationId?: string;
|
||||
//update-end---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
}
|
||||
|
||||
interface ImContactLike {
|
||||
@@ -40,6 +48,16 @@ interface ImContactLike {
|
||||
unreadCount?: number;
|
||||
}
|
||||
|
||||
//update-begin---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
interface ImGroupLike {
|
||||
conversationId: string;
|
||||
groupName?: string;
|
||||
lastContent?: string;
|
||||
lastTime?: string;
|
||||
unreadCount?: number;
|
||||
}
|
||||
//update-end---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
|
||||
/** 标星列表不包含 IM;全部消息或未指定类型、聊天类型时合并 IM */
|
||||
export function shouldIncludeImChatInList(params: ImChatSearchParams) {
|
||||
if (params.starFlag === '1') {
|
||||
@@ -142,14 +160,49 @@ export function mapImContactToNotice(contact: ImContactLike): ImChatNoticeRecord
|
||||
imTargetUsername: contact.username,
|
||||
imAvatar: contact.avatar,
|
||||
imUnreadCount: contact.unreadCount || 0,
|
||||
//update-begin---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
imConvType: 'single',
|
||||
//update-end---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
};
|
||||
}
|
||||
|
||||
export function filterImChatNotices(contacts: ImContactLike[], params: ImChatSearchParams) {
|
||||
let list = (contacts || [])
|
||||
//update-begin---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
/** 将群聊会话映射为聊天提醒记录 */
|
||||
export function mapImGroupToNotice(group: ImGroupLike): ImChatNoticeRecord | null {
|
||||
if (!group?.conversationId || !group?.lastTime) {
|
||||
return null;
|
||||
}
|
||||
const name = group.groupName || '群聊';
|
||||
const preview = formatImMessagePreview(group.lastContent) || '发来一条新消息';
|
||||
const timeText = dayjs(group.lastTime).isValid() ? dayjs(group.lastTime).format('YYYY-MM-DD HH:mm:ss') : String(group.lastTime);
|
||||
return {
|
||||
id: `im_chat_group_${group.conversationId}`,
|
||||
busType: IM_CHAT_BUS_TYPE,
|
||||
titile: `${name}:${preview}`,
|
||||
msgContent: preview,
|
||||
sendTime: timeText,
|
||||
createTime: timeText,
|
||||
readFlag: (group.unreadCount || 0) > 0 ? '0' : '1',
|
||||
noticeType: IM_CHAT_NOTICE_TYPE,
|
||||
starFlag: '0',
|
||||
imTargetUserId: '',
|
||||
imUnreadCount: group.unreadCount || 0,
|
||||
imConvType: 'group',
|
||||
imConversationId: group.conversationId,
|
||||
};
|
||||
}
|
||||
|
||||
export function filterImChatNotices(contacts: ImContactLike[], groups: ImGroupLike[], params: ImChatSearchParams) {
|
||||
const singleList = (contacts || [])
|
||||
.map(mapImContactToNotice)
|
||||
.filter((item): item is ImChatNoticeRecord => !!item)
|
||||
.filter((item) => isInRange(item.sendTime, params.rangeDateKey, params.rangeDate));
|
||||
.filter((item): item is ImChatNoticeRecord => !!item);
|
||||
|
||||
// 指定发件人筛选时,仅匹配单聊(群聊不属于单个发件人)
|
||||
const groupList = params.fromUser
|
||||
? []
|
||||
: (groups || []).map(mapImGroupToNotice).filter((item): item is ImChatNoticeRecord => !!item);
|
||||
|
||||
let list = [...singleList, ...groupList].filter((item) => isInRange(item.sendTime, params.rangeDateKey, params.rangeDate));
|
||||
|
||||
if (params.fromUser) {
|
||||
list = list.filter((item) => item.imTargetUsername === params.fromUser || item.imTargetUserId === params.fromUser);
|
||||
@@ -159,9 +212,13 @@ export function filterImChatNotices(contacts: ImContactLike[], params: ImChatSea
|
||||
}
|
||||
|
||||
export async function fetchImChatNoticeList(params: ImChatSearchParams) {
|
||||
const contacts = ((await fetchDeptMembers()) || []) as ImContactLike[];
|
||||
return filterImChatNotices(contacts, params);
|
||||
const [contacts, groups] = (await Promise.all([
|
||||
Promise.resolve(fetchDeptMembers()).catch(() => []),
|
||||
Promise.resolve(fetchGroups()).catch(() => []),
|
||||
])) as [ImContactLike[], ImGroupLike[]];
|
||||
return filterImChatNotices(contacts || [], groups || [], params);
|
||||
}
|
||||
//update-end---author:cursor ---date:20260529 for:【IM聊天-OA】全部消息补充群聊提醒-----------
|
||||
|
||||
export function mergeMessageList(systemList: any[] = [], imList: ImChatNoticeRecord[] = []) {
|
||||
if (!imList.length) {
|
||||
|
||||
Reference in New Issue
Block a user