chat-pc/src/views/message/inner/panel/menu.ts
Phoenix ebd567a757 fix(消息面板): 修复消息菜单和撤回消息按钮的显示逻辑
修复消息菜单中缺少的is_self_action属性设置,确保撤回消息按钮仅在自身操作时显示
调整编辑器内容处理逻辑,优化草稿保存的数据结构
2025-06-10 15:03:29 +08:00

91 lines
2.3 KiB
TypeScript

import { reactive } from 'vue'
import dayjs from 'dayjs'
import { useDialogueStore } from '@/store/modules/dialogue.js'
interface IDropdown {
options: any[]
show: boolean
x: number
y: number
item: any
}
const isRevoke = (uid: any, item: any): boolean => {
if (uid != item.user_id) {
return false
}
const messageTime = dayjs(item.created_at)
const now = dayjs()
const diffInMinutes = now.diff(messageTime, 'minute')
return diffInMinutes <= 5
}
const dialogueStore = useDialogueStore()
export function useMenu() {
const dropdown: IDropdown = reactive({
options: [],
show: false,
x: 0,
y: 0,
item: {}
})
const showDropdownMenu = (e: any, uid: number, item: any) => {
// dropdown.item = Object.assign({}, item)
dropdown.item = item
dropdown.item.is_self_action = true
dropdown.options = []
if ([4].includes(item.msg_type)) {
if(item.is_convert_text === 1){
dropdown.options.push({ label: '关闭转文字', key: 'closeConvertText' })
}else{
dropdown.options.push({ label: '转文字', key: 'convertText' })
}
}
if ([1, 3].includes(item.msg_type)) {
dropdown.options.push({ label: '复制', key: 'copy' })
}
dropdown.options.push({ label: '多选', key: 'multiSelect' })
dropdown.options.push({ label: '引用', key: 'quote' })
//如果是单聊
if(item.talk_type===1){
//撤回时间限制内,并且是自己发的
if(isRevoke(uid, item)&&item.float==='right'){
dropdown.options.push({ label: `撤回`, key: 'revoke' })
}
//群聊
}else if(item.talk_type===2){
//管理员可以强制撤回所有成员信息
if ((dialogueStore.groupInfo as any).is_manager) {
dropdown.options.push({ label: `撤回`, key: 'revoke' })
}
}
dropdown.options.push({ label: '删除', key: 'delete' })
// if ([3, 4, 5].includes(item.msg_type)) {
// dropdown.options.push({ label: '下载', key: 'download' })
// }
// if ([3].includes(item.msg_type)) {
// dropdown.options.push({ label: '收藏', key: 'collect' })
// }
dropdown.x = e.clientX
dropdown.y = e.clientY
dropdown.show = true
}
const closeDropdownMenu = () => {
dropdown.show = false
dropdown.item = {}
}
return { dropdown, showDropdownMenu, closeDropdownMenu }
}