实现消息删除功能

This commit is contained in:
bob
2025-04-29 18:02:11 +08:00
parent f88b6a0388
commit 58e46fa09f
3 changed files with 33 additions and 6 deletions

View File

@@ -16,6 +16,10 @@ export const msgChatRevokeMsgService = (obj) => {
return request.post('/chat/revokeMsg', obj) return request.post('/chat/revokeMsg', obj)
} }
export const msgChatDeleteMsgService = (obj) => {
return request.post('/chat/deleteMsg', obj)
}
export const msgAtService = () => { export const msgAtService = () => {
return request.get('/chat/queryAt') return request.get('/chat/queryAt')
} }

View File

@@ -177,7 +177,7 @@ export const useMessageStore = defineStore('anylink-message', () => {
*/ */
const removeMsgRecord = (sessionId, msgKey) => { const removeMsgRecord = (sessionId, msgKey) => {
if (msgRecordsList.value[sessionId] && msgKey in msgRecordsList.value[sessionId]) { if (msgRecordsList.value[sessionId] && msgKey in msgRecordsList.value[sessionId]) {
delete msgRecordsList.value[sessionId][msgKey] msgRecordsList.value[sessionId][msgKey].delete = true
} }
} }

View File

@@ -23,7 +23,7 @@ import MsgBoxVideo from '@/views/message/components/MsgBoxVideo.vue'
import MsgBoxDocument from '@/views/message/components/MsgBoxDocument.vue' import MsgBoxDocument from '@/views/message/components/MsgBoxDocument.vue'
import MenuMsgItem from '@/views/message/components/MenuMsgItem.vue' import MenuMsgItem from '@/views/message/components/MenuMsgItem.vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { msgChatRevokeMsgService } from '@/api/message' import { msgChatDeleteMsgService, msgChatRevokeMsgService } from '@/api/message'
const props = defineProps([ const props = defineProps([
'sessionId', 'sessionId',
@@ -631,6 +631,10 @@ const isRevoke = computed(() => {
return msg.value.revoke return msg.value.revoke
}) })
const isDelete = computed(() => {
return msg.value.delete
})
const isReedit = computed(() => { const isReedit = computed(() => {
const contentJson = jsonParseSafe(msg.value.content) const contentJson = jsonParseSafe(msg.value.content)
if (!contentJson) { if (!contentJson) {
@@ -712,13 +716,13 @@ const onSelectMenuMsgItem = async (label) => {
case 'revoke': case 'revoke':
msgChatRevokeMsgService({ msgChatRevokeMsgService({
sessionId: props.sessionId, sessionId: props.sessionId,
revokeMsgId: msg.value.msgId, // 服务器上删除用msg.value.msgId revokeMsgId: msg.value.msgId, // 服务器上撤销用msg.value.msgId
isGroupChat: isGroupChatMsgType.value, isGroupChat: isGroupChatMsgType.value,
remoteId: messageData.sessionList[props.sessionId].remoteId remoteId: messageData.sessionList[props.sessionId].remoteId
}) })
.then((res) => { .then((res) => {
if (res.data.code === 0) { if (res.data.code === 0) {
// 本地删除用props.msgKey因为key有可能是发送消息时产生的本地UUID // 本地撤销用props.msgKey因为key有可能是发送消息时产生的本地UUID
messageData.revokeMsgRcord(props.sessionId, props.msgKey) messageData.revokeMsgRcord(props.sessionId, props.msgKey)
isReeditTimeOut.value = false isReeditTimeOut.value = false
setTimeout(() => { setTimeout(() => {
@@ -731,6 +735,22 @@ const onSelectMenuMsgItem = async (label) => {
console.error(error) console.error(error)
}) })
break break
case 'delete':
msgChatDeleteMsgService({
sessionId: props.sessionId,
deleteMsgId: msg.value.msgId // 服务器上删除用msg.value.msgId
})
.then((res) => {
if (res.data.code === 0) {
// 本地删除用props.msgKey因为key有可能是发送消息时产生的本地UUID
messageData.removeMsgRecord(props.sessionId, props.msgKey)
ElMessage.success('消息已删除')
}
})
.catch((error) => {
console.error(error)
})
break
default: default:
break break
} }
@@ -778,7 +798,7 @@ watch(
v-html="systemMsgContent" v-html="systemMsgContent"
@click="onClickSystemMsg" @click="onClickSystemMsg"
></div> ></div>
<div v-else-if="!isSystemMsg && isRevoke" class="revoke-wrapper"> <div v-else-if="!isSystemMsg && isRevoke" class="revoke-delete">
<div v-if="isSelf"> <div v-if="isSelf">
<span>你撤回了一条消息</span> <span>你撤回了一条消息</span>
<span <span
@@ -794,6 +814,9 @@ watch(
<div v-else>{{ `${objectInfo.nickName}撤回了一条消息` }}</div> <div v-else>{{ `${objectInfo.nickName}撤回了一条消息` }}</div>
</div> </div>
</div> </div>
<div v-else-if="!isSystemMsg && isDelete" class="revoke-delete">
<span>消息已删除</span>
</div>
<div v-else class="message-container-wrapper"> <div v-else class="message-container-wrapper">
<el-container class="el-container-right" v-if="isSelf"> <el-container class="el-container-right" v-if="isSelf">
<el-main class="el-main-right"> <el-main class="el-main-right">
@@ -949,7 +972,7 @@ watch(
user-select: text; user-select: text;
} }
.revoke-wrapper { .revoke-delete {
padding: 2px 4px 2px 4px; padding: 2px 4px 2px 4px;
margin-top: 10px; margin-top: 10px;
margin-bottom: 10px; margin-bottom: 10px;