Files
qhmes/jeecgboot-vue3/src/views/system/im/ImChatModal.vue

111 lines
3.7 KiB
Vue
Raw Normal View History

2026-05-28 14:37:05 +08:00
<template>
<BasicModal
v-bind="$attrs"
title="IM聊天"
:width="980"
:footer="null"
:canFullscreen="true"
:destroyOnClose="false"
wrapClassName="im-chat-modal-wrap"
@register="registerModal"
@open-change="handleOpenChange"
>
<div class="im-chat-modal-body">
<ImChat ref="imChatRef" embedded />
</div>
</BasicModal>
</template>
<script lang="ts" setup>
2026-05-28 17:08:34 +08:00
import { ref, nextTick, onMounted, onUnmounted } from 'vue';
2026-05-28 14:37:05 +08:00
import { BasicModal, useModalInner } from '/@/components/Modal';
import ImChat from './ImChat.vue';
2026-05-28 17:08:34 +08:00
import { setImChatWindowOpen } from './imCache';
import { canOpenImChatModal, onImChatModalCloseRequest, openImChat, setImPageContext } from './imSession';
import { refreshImUnread } from './useImUnread';
2026-05-28 14:37:05 +08:00
defineOptions({ name: 'ImChatModal' });
const imChatRef = ref<InstanceType<typeof ImChat>>();
2026-05-28 17:08:34 +08:00
const pendingTargetUserId = ref('');
2026-05-28 14:37:05 +08:00
function restoreChatSession() {
2026-05-28 17:08:34 +08:00
nextTick(async () => {
const targetUserId = pendingTargetUserId.value;
if (targetUserId) {
pendingTargetUserId.value = '';
await imChatRef.value?.openTargetChat?.(targetUserId);
return;
}
2026-05-28 14:37:05 +08:00
imChatRef.value?.restoreSessionIfNeeded?.();
});
}
2026-05-28 17:08:34 +08:00
const [registerModal, { closeModal }] = useModalInner((data?: { targetUserId?: string }) => {
//update-begin---author:xsl ---date:20260528 for【IM聊天-OA】全页 IM 已打开时拒绝弹窗,改由全页承接-----------
if (!canOpenImChatModal()) {
closeModal();
openImChat({ targetUserId: data?.targetUserId });
return;
}
//update-end---author:xsl ---date:20260528 for【IM聊天-OA】全页 IM 已打开时拒绝弹窗,改由全页承接-----------
setImChatWindowOpen(true);
pendingTargetUserId.value = data?.targetUserId || '';
2026-05-28 14:37:05 +08:00
restoreChatSession();
});
function handleOpenChange(open: boolean) {
2026-05-28 17:08:34 +08:00
//update-begin---author:xsl ---date:20260528 for【IM聊天-OA】全页 IM 已打开时不展示弹窗-----------
if (open && !canOpenImChatModal()) {
closeModal();
return;
}
//update-end---author:xsl ---date:20260528 for【IM聊天-OA】全页 IM 已打开时不展示弹窗-----------
setImChatWindowOpen(open);
2026-05-28 14:37:05 +08:00
if (open) {
restoreChatSession();
2026-05-28 17:08:34 +08:00
} else {
//update-begin---author:xsl ---date:20260528 for【IM聊天-OA】弹窗关闭不清空消息全页 IM 从缓存恢复-----------
imChatRef.value?.pauseActiveSession?.();
//update-end---author:xsl ---date:20260528 for【IM聊天-OA】弹窗关闭不清空消息全页 IM 从缓存恢复-----------
//update-begin---author:xsl ---date:20260528 for【IM聊天-OA】弹窗关闭清除功能页快照-----------
setImPageContext(null);
//update-end---author:xsl ---date:20260528 for【IM聊天-OA】弹窗关闭清除功能页快照-----------
refreshImUnread(true);
2026-05-28 14:37:05 +08:00
}
}
2026-05-28 17:08:34 +08:00
//update-begin---author:xsl ---date:20260528 for【IM聊天-OA】业务明细消息链接跳转时关闭 IM 弹窗-----------
let unsubscribeCloseModal: (() => void) | null = null;
onMounted(() => {
unsubscribeCloseModal = onImChatModalCloseRequest(() => {
closeModal();
});
});
onUnmounted(() => {
unsubscribeCloseModal?.();
});
//update-end---author:xsl ---date:20260528 for【IM聊天-OA】业务明细消息链接跳转时关闭 IM 弹窗-----------
2026-05-28 14:37:05 +08:00
</script>
<style lang="less">
.im-chat-modal-wrap {
.im-chat-modal-body {
height: 70vh;
min-height: 480px;
}
.im-chat-page--embedded {
height: 100% !important;
padding: 0 !important;
background: transparent !important;
}
.im-chat-row {
border-radius: 4px;
}
}
</style>