2024-12-24 08:14:21 +00:00
|
|
|
|
import { reactive } from 'vue'
|
2025-06-10 05:28:54 +00:00
|
|
|
|
import dayjs from 'dayjs'
|
2025-05-22 07:07:27 +00:00
|
|
|
|
import { useDialogueStore } from '@/store/modules/dialogue.js'
|
2024-12-24 08:14:21 +00:00
|
|
|
|
|
|
|
|
|
interface IDropdown {
|
|
|
|
|
options: any[]
|
|
|
|
|
show: boolean
|
|
|
|
|
x: number
|
|
|
|
|
y: number
|
|
|
|
|
item: any
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 01:44:17 +00:00
|
|
|
|
const isRevoke = (uid: number, item: any): boolean => {
|
|
|
|
|
// 不是自己发的消息不能撤回
|
|
|
|
|
if (uid !== item.user_id) {
|
|
|
|
|
return false;
|
2024-12-24 08:14:21 +00:00
|
|
|
|
}
|
2025-06-11 01:44:17 +00:00
|
|
|
|
|
|
|
|
|
// 检查消息是否在撤回时间限制内(5分钟)
|
|
|
|
|
const messageTime = dayjs(item.created_at);
|
|
|
|
|
const now = dayjs();
|
|
|
|
|
const diffInMinutes = now.diff(messageTime, 'minute');
|
|
|
|
|
return diffInMinutes <= 5;
|
|
|
|
|
}
|
|
|
|
|
// 判断是否可以添加撤回选项的函数
|
|
|
|
|
const canAddRevokeOption = (uid: number, item: any, isManager: boolean): boolean => {
|
|
|
|
|
// 单聊情况:自己发的且在时间限制内
|
|
|
|
|
if (item.talk_type === 1) {
|
|
|
|
|
return isRevoke(uid, item) && item.float === 'right';
|
|
|
|
|
}
|
|
|
|
|
// 群聊情况
|
|
|
|
|
else if (item.talk_type === 2) {
|
|
|
|
|
// 管理员可以撤回任何消息
|
|
|
|
|
if (isManager) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// 普通成员只能撤回自己的且在时间限制内的消息
|
|
|
|
|
return isRevoke(uid, item) && item.float === 'right';
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2024-12-24 08:14:21 +00:00
|
|
|
|
}
|
2025-05-22 07:07:27 +00:00
|
|
|
|
const dialogueStore = useDialogueStore()
|
2024-12-24 08:14:21 +00:00
|
|
|
|
export function useMenu() {
|
|
|
|
|
const dropdown: IDropdown = reactive({
|
|
|
|
|
options: [],
|
|
|
|
|
show: false,
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
item: {}
|
|
|
|
|
})
|
2025-06-24 06:59:07 +00:00
|
|
|
|
// 判断时间是否超过一个月
|
|
|
|
|
function isOneMonthBefore(date) {
|
|
|
|
|
const oneMonthAgo = new Date()
|
|
|
|
|
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1)
|
|
|
|
|
const inputDate = new Date(date)
|
|
|
|
|
return !(inputDate <= oneMonthAgo)
|
|
|
|
|
}
|
2024-12-24 08:14:21 +00:00
|
|
|
|
const showDropdownMenu = (e: any, uid: number, item: any) => {
|
2025-05-16 07:20:35 +00:00
|
|
|
|
// dropdown.item = Object.assign({}, item)
|
|
|
|
|
dropdown.item = item
|
2025-06-10 07:03:29 +00:00
|
|
|
|
dropdown.item.is_self_action = true
|
2024-12-24 08:14:21 +00:00
|
|
|
|
dropdown.options = []
|
2025-05-16 07:20:35 +00:00
|
|
|
|
if ([4].includes(item.msg_type)) {
|
2025-06-24 06:59:07 +00:00
|
|
|
|
if (item.is_convert_text === 1) {
|
2025-05-16 07:20:35 +00:00
|
|
|
|
dropdown.options.push({ label: '关闭转文字', key: 'closeConvertText' })
|
2025-06-24 06:59:07 +00:00
|
|
|
|
} else {
|
2025-05-16 07:20:35 +00:00
|
|
|
|
dropdown.options.push({ label: '转文字', key: 'convertText' })
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-24 08:14:21 +00:00
|
|
|
|
if ([1, 3].includes(item.msg_type)) {
|
|
|
|
|
dropdown.options.push({ label: '复制', key: 'copy' })
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 06:59:07 +00:00
|
|
|
|
if (isOneMonthBefore(new Date(item.created_at.split(' ')[0]))) {
|
|
|
|
|
// 根据时间判断只有近一个月内的消息才能支持多选
|
|
|
|
|
dropdown.options.push({ label: '多选', key: 'multiSelect' })
|
|
|
|
|
}
|
2025-05-12 05:44:13 +00:00
|
|
|
|
dropdown.options.push({ label: '引用', key: 'quote' })
|
2025-06-11 01:44:17 +00:00
|
|
|
|
if (canAddRevokeOption(uid, item, (dialogueStore.groupInfo as any).is_manager)) {
|
|
|
|
|
dropdown.options.push({ label: '撤回', key: 'revoke' });
|
2024-12-24 08:14:21 +00:00
|
|
|
|
}
|
2025-06-09 07:29:24 +00:00
|
|
|
|
|
2024-12-24 08:14:21 +00:00
|
|
|
|
dropdown.options.push({ label: '删除', key: 'delete' })
|
|
|
|
|
|
2025-05-22 07:07:27 +00:00
|
|
|
|
// if ([3, 4, 5].includes(item.msg_type)) {
|
|
|
|
|
// dropdown.options.push({ label: '下载', key: 'download' })
|
|
|
|
|
// }
|
2024-12-24 08:14:21 +00:00
|
|
|
|
|
2025-05-22 07:07:27 +00:00
|
|
|
|
// if ([3].includes(item.msg_type)) {
|
|
|
|
|
// dropdown.options.push({ label: '收藏', key: 'collect' })
|
|
|
|
|
// }
|
2024-12-24 08:14:21 +00:00
|
|
|
|
|
|
|
|
|
dropdown.x = e.clientX
|
|
|
|
|
dropdown.y = e.clientY
|
|
|
|
|
dropdown.show = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const closeDropdownMenu = () => {
|
|
|
|
|
dropdown.show = false
|
|
|
|
|
dropdown.item = {}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 06:59:07 +00:00
|
|
|
|
return { dropdown, showDropdownMenu, closeDropdownMenu, isOneMonthBefore }
|
2024-12-24 08:14:21 +00:00
|
|
|
|
}
|