From bbb5dd99fc04f66ce2ff6ec18447f137f99838b6 Mon Sep 17 00:00:00 2001
From: wangyifeng <812766448@qq.com>
Date: Thu, 10 Apr 2025 19:57:41 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=81=8A=E5=A4=A9?=
=?UTF-8?q?=E6=99=AE=E9=80=9A=E8=BE=93=E5=85=A5=E6=A1=86=EF=BC=8C=E7=94=A8?=
=?UTF-8?q?=E4=BA=8E=E5=A4=84=E7=90=86=E6=89=8B=E6=9C=BA=E7=B3=BB=E7=BB=9F?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=E8=BF=87=E4=BD=8E=E6=97=B6=E4=B8=8D=E6=94=AF?=
=?UTF-8?q?=E6=8C=81quill-edior=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/pages/dialog/index.vue | 145 ++++++++++++++++++++++++++++++++++++-
1 file changed, 141 insertions(+), 4 deletions(-)
diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue
index c38bca9..9465d56 100644
--- a/src/pages/dialog/index.vue
+++ b/src/pages/dialog/index.vue
@@ -263,9 +263,20 @@
@editorChange="onEditorChange"
style="width: 100%; flex: 1; height: 100%;"
@click="onEditorClick"
+ v-if="state.canUseQuillEditor"
/>
-
+
-
+ {
+ if (!state.canUseQuillEditor) {
+ onTextAreaEmoticon(data)
+ } else {
+ onEmoticonEvent(data)
+ }
+ }" />
{
@@ -728,7 +747,74 @@ const onSendMessage = (data = {}, callBack, showLoading = false) => {
})
}
+const onTextAreaChange = (value) => {
+ state.value.textAreaValue = value
+
+ // 更新mentionUserIds数组,确保与输入框中的@内容一致
+ const atPattern = /@([^@\s]+)(?:\s|$)/g
+ const matches = Array.from(value.matchAll(atPattern))
+ const mentionedUsers = matches.map(match => match[1].trim().toLowerCase())
+
+ // 获取当前对话中的所有成员信息
+ const members = dialogueStore.members || []
+
+ // 根据@的用户名找到对应的user_id
+ const newMentionUserIds = mentionedUsers.map(username => {
+ if (username === '所有人') {
+ return 0 // 如果是@所有人,返回0
+ }
+ const member = members.find(m => m.nickname.trim().toLowerCase() === username)
+ return member ? member.id : null
+ }).filter(id => id !== null)
+
+ // 只有在输入框中有@内容时才更新mentionUserIds
+ if (value.includes('@')) {
+ state.value.mentionUserIds = newMentionUserIds
+ } else {
+ state.value.mentionUserIds = []
+ }
+}
+
+// 处理输入框输入事件
+const onTextAreaInput = (value) => {
+ console.log(value, 'value')
+ if(value.length > 0){
+ if(value[value.length - 1] === '@'){
+ if(talkParams.type === 1){
+ return
+ }
+ state.value.isShowMentionSelect = true
+ }
+ }
+}
+
const onSendMessageClick = () => {
+ if (!state.value.canUseQuillEditor) {
+ // 处理普通输入框的发送消息
+ if (state.value.textAreaValue.trim() === '') {
+ return
+ }
+ if (state.value.textAreaValue.length > 1024) {
+ return message.warning('发送内容超长,请分条发送')
+ }
+ let message = {
+ type: 'text',
+ content: state.value.textAreaValue,
+ quote_id: state.value.quoteInfo ? state.value.quoteInfo.msg_id : null, // 添加quote_id
+ mentions: state.value.mentionUserIds, // 使用最终的用户ID数组
+ }
+ console.log(message)
+ onSendMessage(
+ message,
+ (ok) => {
+ if (!ok) return
+ state.value.textAreaValue = ''
+ state.value.quoteInfo = null // 发送后清除引用信息
+ },
+ true,
+ )
+ return
+ }
// 发送前确保 mentionUserIds 是最新的
updateMentionUserIds()
@@ -1404,6 +1490,10 @@ const confirmMentionSelect = () => {
selectMemberByAlphabetRef.value.confirmSelectMembers()
}
hideMentionSelect()
+
+ // 重置选中人数和多选状态
+ state.value.selectedMembersNum = 0
+ state.value.mentionIsMulSelect = false
}
}
@@ -1415,6 +1505,14 @@ const getSelectResult = (mentionSelect) => {
//处理要提醒人的消息样式
const getMentionSelectLists = (mentionSelectList) => {
+ if(!state.value.canUseQuillEditor){
+ if(mentionSelectList.length > 0){
+ mentionSelectList.forEach(item => {
+ onTextAreaMention(item)
+ })
+ }
+ return
+ }
const quill = getQuill()
const mention = quill.getModule('mention')
@@ -1648,7 +1746,11 @@ let currentPressItem = null
const handleAvatarTouchStart = (item) => {
currentPressItem = item
avatarPressTimer = setTimeout(() => {
- doMentionUser(item)
+ if (!state.value.canUseQuillEditor) {
+ onTextAreaMention(item)
+ } else {
+ doMentionUser(item)
+ }
}, 500)
}
@@ -1749,6 +1851,36 @@ const showMentionSelectDebounced = (quill) => {
state.value.isShowMentionSelect = true
// quill.blur()
}
+
+// 处理普通输入框的表情插入
+const onTextAreaEmoticon = (data) => {
+ if (data.type == 1) {
+ if (data.img) {
+ // 如果是图片表情,插入对应的文本标记
+ state.value.textAreaValue += `${data.value}`
+ } else {
+ // 如果是文本表情,直接插入
+ state.value.textAreaValue += data.value
+ }
+ }
+}
+
+// 处理普通输入框的长按@功能
+const onTextAreaMention = (user) => {
+ if (talkParams.type === 1) {
+ return
+ }
+ if(state.value.textAreaValue.length > 0){
+ if(state.value.textAreaValue[state.value.textAreaValue.length - 1] === '@'){
+ state.value.textAreaValue = state.value.textAreaValue.slice(0, -1)
+ }
+ }
+ state.value.textAreaValue += `@${user.nickname} `
+ state.value.mentionUserIds.push(user.user_id)
+ if(state.value.isShowMentionSelect){
+ state.value.isShowMentionSelect = false
+ }
+}