Merge branch 'xingyy' into dev

This commit is contained in:
Phoenix 2025-06-10 13:39:29 +08:00
commit 1ae317dbb3
4 changed files with 189 additions and 99 deletions

View File

@ -26,6 +26,7 @@
"@vueuse/core": "^10.7.0",
"ant-design-vue": "^4.2.6",
"axios": "^1.6.2",
"dayjs": "^1.11.13",
"highlight.js": "^11.5.0",
"js-audio-recorder": "^1.0.7",
"lodash-es": "^4.17.21",

View File

@ -44,6 +44,9 @@ importers:
axios:
specifier: ^1.6.2
version: 1.9.0
dayjs:
specifier: ^1.11.13
version: 1.11.13
highlight.js:
specifier: ^11.5.0
version: 11.11.1

View File

@ -76,7 +76,9 @@ const navs = ref([
const mentionList = ref([])
const currentMentionQuery = ref('')
setTimeout(() => {
console.log('props.members',props.members)
}, 1000)
//
const editorContent = ref('')
const editorHtml = ref('')
@ -100,6 +102,7 @@ const handleInput = (event) => {
const editorClone = target.cloneNode(true)
const quoteElements = editorClone.querySelectorAll('.editor-quote')
quoteElements.forEach(quote => quote.remove())
quoteElements.forEach(quote => quote.remove())
// alt
const emojiImages = editorClone.querySelectorAll('img.editor-emoji')
@ -119,7 +122,8 @@ const handleInput = (event) => {
editorContent.value = textContent
// placeholder
const isEmpty = textContent.trim() === '' &&
//
const isEmpty = textContent === '' &&
!target.querySelector('img, .editor-file, .mention')
if (isEmpty && target.innerHTML !== '') {
@ -163,11 +167,30 @@ const showMentionList = () => {
mentionList.value = props.members.filter(member => {
return member.value.toLowerCase().startsWith(query)
})
if(dialogueStore.groupInfo.is_manager){
mentionList.value.unshift({ id: 0, nickname: '全体成员', avatar: defAvatar, value: '全体成员' })
}
showMention.value = mentionList.value.length > 0
selectedMentionIndex.value = 0
}
// mention
const handleMentionSelectByMouse = (member) => {
const selection = window.getSelection();
if (selection && selection.rangeCount > 0) {
insertMention(member, selection.getRangeAt(0).cloneRange());
} else {
//
editorRef.value?.focus();
nextTick(() => {
const newSelection = window.getSelection();
if (newSelection && newSelection.rangeCount > 0) {
insertMention(member, newSelection.getRangeAt(0).cloneRange());
}
});
}
};
// mention
const hideMentionList = () => {
showMention.value = false
@ -187,65 +210,73 @@ const updateMentionPosition = (range) => {
}
// mention
const insertMention = (member) => {
const selection = window.getSelection()
if (!selection.rangeCount) return
const range = selection.getRangeAt(0)
const textNode = range.startContainer
const offset = range.startOffset
// @
const textContent = textNode.textContent || ''
const atIndex = textContent.lastIndexOf('@', offset - 1)
// mention
const mentionSpan = document.createElement('span')
mentionSpan.className = 'mention'
mentionSpan.setAttribute('data-user-id', member.id || member.user_id)
mentionSpan.textContent = `@${member.value || member.nickname}`
mentionSpan.contentEditable = 'false'
if (atIndex !== -1) {
// @
const beforeText = textContent.substring(0, atIndex)
const afterText = textContent.substring(offset)
//
const beforeNode = document.createTextNode(beforeText)
const afterNode = document.createTextNode(' ' + afterText)
//
const parent = textNode.parentNode
parent.insertBefore(beforeNode, textNode)
parent.insertBefore(mentionSpan, textNode)
parent.insertBefore(afterNode, textNode)
parent.removeChild(textNode)
const insertMention = (member, clonedRange) => {
console.log('插入mention', member);
const selection = window.getSelection();
if (!clonedRange || !selection) return;
const range = clonedRange; // 使 range
const textNode = range.startContainer;
const offset = range.startOffset;
const textContent = textNode.nodeType === Node.TEXT_NODE ? textNode.textContent || '' : '';
// @
const atIndex = (textNode.nodeType === Node.TEXT_NODE && offset > 0) ? textContent.lastIndexOf('@', offset - 1) : -1;
const mentionSpan = document.createElement('span');
mentionSpan.className = 'mention';
mentionSpan.setAttribute('data-user-id', String(member.id));
mentionSpan.textContent = `@${member.value || member.nickname}`;
mentionSpan.contentEditable = 'false';
if (atIndex !== -1 && textNode.nodeType === Node.TEXT_NODE) {
const parent = textNode.parentNode;
if (!parent) return; // Sanity check
// @
range.setStart(textNode, atIndex);
range.setEnd(textNode, offset);
range.deleteContents();
// mention
range.insertNode(mentionSpan);
} else {
// @
range.deleteContents()
// @
range.insertNode(mentionSpan)
// @
const spaceNode = document.createTextNode(' ')
range.setStartAfter(mentionSpan)
range.insertNode(spaceNode)
//
range.setStartAfter(spaceNode)
range.collapse(true)
selection.removeAllRanges()
selection.addRange(range)
// @
if (!range.collapsed) {
range.deleteContents();
}
range.insertNode(mentionSpan);
}
//
handleInput({ target: editorRef.value })
// mention
hideMentionList()
}
// mention
const spaceNode = document.createTextNode('\u00A0'); // 使
const currentParent = mentionSpan.parentNode;
if (currentParent) {
// mentionSpan
if (mentionSpan.nextSibling) {
currentParent.insertBefore(spaceNode, mentionSpan.nextSibling);
} else {
currentParent.appendChild(spaceNode);
}
//
range.setStartAfter(spaceNode);
range.collapse(true);
} else {
// Fallback: mentionSpan mentionSpan
range.setStartAfter(mentionSpan);
range.collapse(true);
}
selection.removeAllRanges();
selection.addRange(range);
editorRef.value?.focus(); //
nextTick(() => {
handleInput({ target: editorRef.value });
hideMentionList();
});
};
//
const handlePaste = (event) => {
@ -343,12 +374,15 @@ const handleKeydown = (event) => {
break
case 'Enter':
case 'Tab':
event.preventDefault()
const selectedMember = mentionList.value[selectedMentionIndex.value]
event.preventDefault();
const selectedMember = mentionList.value[selectedMentionIndex.value];
if (selectedMember) {
insertMention(selectedMember)
const selection = window.getSelection();
if (selection && selection.rangeCount > 0) {
insertMention(selectedMember, selection.getRangeAt(0).cloneRange());
}
}
break
break;
case 'Escape':
hideMentionList()
break
@ -391,6 +425,25 @@ const handleKeydown = (event) => {
}
prevSibling = prevSibling.previousSibling
}
} else {
//
// mention
if (!container.textContent.trim()) {
let prevSibling = container.previousSibling
while (prevSibling) {
if (prevSibling.nodeType === Node.ELEMENT_NODE &&
prevSibling.classList &&
prevSibling.classList.contains('mention')) {
targetMention = prevSibling
break
}
//
if (prevSibling.nodeType === Node.TEXT_NODE && prevSibling.textContent.trim()) {
break
}
prevSibling = prevSibling.previousSibling
}
}
}
} else if (container.nodeType === Node.ELEMENT_NODE) {
//
@ -525,24 +578,29 @@ const sendMessage = () => {
if (messageData.items.length === 0 ||
(messageData.items.length === 1 &&
messageData.items[0].type === 1 &&
!messageData.items[0].content.trim())) {
!messageData.items[0].content.trimEnd())) {
return //
}
//
messageData.items.forEach(item => {
//
if (item.type === 1 && item.content.trim()) {
if (item.type === 1 && item.content.trimEnd()) {
const data = {
items: [{
content: item.content,
type: 1
}],
mentionUids: messageData.mentionUids,
mentions: [],
mentions: messageData.mentionUids.map(uid => {
return {
atid: uid,
name: mentionList.value.find(member => member.id === uid)?.nickname || ''
}
}),
quoteId: messageData.quoteId,
}
console.log('data',data)
emit(
'editor-event',
emitCall('text_event', data)
@ -602,7 +660,7 @@ const parseEditorContent = () => {
// @
const userId = node.getAttribute('data-user-id')
if (userId) {
mentionUids.push(parseInt(userId))
mentionUids.push(Number(userId))
}
textContent += node.textContent
} else if (node.tagName === 'IMG') {
@ -634,7 +692,7 @@ const parseEditorContent = () => {
if (textContent.trim()) {
items.push({
type: 1,
content: textContent.trim()
content: textContent.trimEnd()
})
textContent = ''
}
@ -674,7 +732,7 @@ const parseEditorContent = () => {
if (textContent.trim()) {
items.push({
type: 1,
content: textContent.trim()
content: textContent.trimEnd()
})
textContent = ''
}
@ -696,7 +754,7 @@ const parseEditorContent = () => {
if (textContent.trim()) {
items.push({
type: 1,
content: textContent.trim()
content: textContent.trimEnd()
})
}
@ -918,27 +976,44 @@ const insertImageEmoji = (imgSrc, altText) => {
}
//
const onSubscribeMention = (data) => {
//
editorRef.value?.focus()
//
const selection = window.getSelection()
if (!selection.rangeCount || !editorRef.value.contains(selection.anchorNode)) {
const range = document.createRange()
if (editorRef.value.lastChild) {
range.setStartAfter(editorRef.value.lastChild)
const onSubscribeMention = async (data) => {
const editorNode = editorRef.value;
if (!editorNode) return;
editorNode.focus();
await nextTick(); //
let selection = window.getSelection();
if (!selection || selection.rangeCount === 0) {
const range = document.createRange();
if (editorNode.lastChild) {
range.setStartAfter(editorNode.lastChild);
} else {
range.setStart(editorRef.value, 0)
range.setStart(editorNode, 0);
}
range.collapse(true)
selection.removeAllRanges()
selection.addRange(range)
range.collapse(true);
if (selection) selection.removeAllRanges();
selection?.addRange(range);
await nextTick();
selection = window.getSelection();
} else if (!editorNode.contains(selection.anchorNode)) {
const range = document.createRange();
if (editorNode.lastChild) {
range.setStartAfter(editorNode.lastChild);
} else {
range.setStart(editorNode, 0);
}
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
await nextTick();
selection = window.getSelection();
}
// @
insertMention(data)
}
if (selection && selection.rangeCount > 0) {
insertMention(data, selection.getRangeAt(0).cloneRange());
}
};
const onSubscribeQuote = (data) => {
// 稿
@ -1431,7 +1506,7 @@ const handleEditorClick = (event) => {
<n-icon size="18" class="icon" :component="nav.icon" />
<p class="tip-title">{{ nav.title }}</p>
</div>
<n-button class="w-80px h-30px ml-auto" type="primary">
<n-button class="w-80px h-30px ml-auto" type="primary" @click="sendMessage">
<template #icon>
<n-icon>
<IosSend />
@ -1483,7 +1558,7 @@ const handleEditorClick = (event) => {
:key="member.user_id || member.id"
class="cursor-pointer px-14px h-42px"
:class="{ 'bg-#EEE9F9': index === selectedMentionIndex }"
@mousedown.prevent="insertMention(member)"
@mousedown.prevent="handleMentionSelectByMouse(member)"
@mouseover="selectedMentionIndex = index"
>
<div class="flex items-center border-b-1px border-b-solid border-b-#F8F8F8 h-full">

View File

@ -1,4 +1,5 @@
import { reactive } from 'vue'
import dayjs from 'dayjs'
import { useDialogueStore } from '@/store/modules/dialogue.js'
interface IDropdown {
@ -14,11 +15,10 @@ const isRevoke = (uid: any, item: any): boolean => {
return false
}
const datetime = item.created_at.replace(/-/g, '/')
const time = new Date().getTime() - Date.parse(datetime)
return Math.floor(time / 1000 / 60) <= 2
const messageTime = dayjs(item.created_at)
const now = dayjs()
const diffInMinutes = now.diff(messageTime, 'minute')
return diffInMinutes <= 5
}
const dialogueStore = useDialogueStore()
export function useMenu() {
@ -48,9 +48,20 @@ export function useMenu() {
dropdown.options.push({ label: '多选', key: 'multiSelect' })
dropdown.options.push({ label: '引用', key: 'quote' })
if (isRevoke(uid, item)|| (dialogueStore.groupInfo as any).is_manager) {
dropdown.options.push({ label: `撤回`, key: 'revoke' })
//如果是单聊
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' })