diff --git a/src/js/event/receiveDeleteMsg.js b/src/js/event/receiveDeleteMsg.js index 2407a44..8ce2be6 100644 --- a/src/js/event/receiveDeleteMsg.js +++ b/src/js/event/receiveDeleteMsg.js @@ -4,7 +4,10 @@ export const onReceiveDeleteMsg = () => { return (msg) => { const messageData = useMessageStore() const sessionId = msg.body.sessionId - const deleteMsgId = msg.body.content - messageData.removeMsgRecord(sessionId, deleteMsgId) + const deleteMsgIds = msg.body.content + + deleteMsgIds.split(',').forEach((item) => { + messageData.removeMsgRecord(sessionId, item) + }) } } diff --git a/src/views/message/MessageLayout.vue b/src/views/message/MessageLayout.vue index 23ad6f8..c616445 100644 --- a/src/views/message/MessageLayout.vue +++ b/src/views/message/MessageLayout.vue @@ -33,7 +33,8 @@ import backgroupImage from '@/assets/svg/messagebx_bg.svg' import { msgChatPullMsgService, msgChatCreateSessionService, - msgChatQuerySessionService + msgChatQuerySessionService, + msgChatDeleteMsgService } from '@/api/message' import { groupInfoService, groupCreateService } from '@/api/group' import { MsgType } from '@/proto/msg' @@ -1182,9 +1183,24 @@ const handleCancleMultiSelect = () => { // } // } -// const handleDeleteMessages = async () => { -// // 实现批量删除逻辑 -// } +const handleBatchDeleteMsg = () => { + msgChatDeleteMsgService({ + sessionId: selectedSessionId.value, + deleteMsgIds: [...multiSelectedMsgIds.value] + }) + .then((res) => { + if (res.data.code === 0) { + multiSelectedMsgIds.value.forEach((item) => { + messageData.removeMsgRecord(selectedSessionId.value, item) + }) + handleCancleMultiSelect() + ElMessage.success('消息已删除') + } + }) + .catch((error) => { + console.error(error) + }) +} // const handleForwardSelected = () => { // // 实现批量转发逻辑 @@ -1651,6 +1667,7 @@ const onShowRecorder = () => { ref="inputMultiSelectRef" :selectedCount="multiSelectedMsgIds.size" @exit="handleCancleMultiSelect" + @batchDelete="handleBatchDeleteMsg" > diff --git a/src/views/message/components/InputMultiSelect.vue b/src/views/message/components/InputMultiSelect.vue index 3a0ab9b..4f5cd16 100644 --- a/src/views/message/components/InputMultiSelect.vue +++ b/src/views/message/components/InputMultiSelect.vue @@ -4,6 +4,7 @@ import ForwardIcon from '@/assets/svg/forward.svg' import ForwardoboIcon from '@/assets/svg/forwardobo.svg' import DeletemsgIcon from '@/assets/svg/deletemsg.svg' import CancleIcon from '@/assets/svg/cancle.svg' +import { ElMessageBox } from 'element-plus' const props = defineProps(['selectedCount']) const emit = defineEmits(['exit', 'forwardTogether', 'forwardOneByOne', 'batchDelete']) @@ -27,6 +28,18 @@ onMounted(() => { onUnmounted(() => { window.removeEventListener('keydown', handleKeyDown) }) + +const handleBatchDelete = () => { + if (props.selectedCount > 0) { + ElMessageBox.confirm(`确定删除选中的消息记录吗?`, '温馨提示', { + type: 'warning', + confirmButtonText: '确认', + cancelButtonText: '取消' + }).then(() => { + emit('batchDelete') + }) + } +}