From df1cc68b5929497fc1ae74c07262945c37a58284 Mon Sep 17 00:00:00 2001
From: wangyifeng <812766448@qq.com>
Date: Fri, 11 Apr 2025 14:53:01 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9@=E5=8A=9F=E8=83=BD=E9=97=AE?=
=?UTF-8?q?=E9=A2=98=EF=BC=9B=E6=96=B0=E5=A2=9EIOS=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E5=8F=B7=E5=88=A4=E6=96=AD=E4=BD=BF=E7=94=A8=E5=93=AA=E4=B8=AA?=
=?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=EF=BC=9B=E5=A4=84=E7=90=86=E8=81=8A?=
=?UTF-8?q?=E5=A4=A9=E8=AE=B0=E5=BD=95=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/pages/dialog/index.vue | 143 +++++++++++++++++++++++++------------
src/plugins/ws-socket.js | 2 +-
2 files changed, 100 insertions(+), 45 deletions(-)
diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue
index 9465d56..4eacb20 100644
--- a/src/pages/dialog/index.vue
+++ b/src/pages/dialog/index.vue
@@ -337,13 +337,17 @@
- {
- if (!state.canUseQuillEditor) {
- onTextAreaEmoticon(data)
- } else {
- onEmoticonEvent(data)
- }
- }" />
+ {
+ if (!state.canUseQuillEditor) {
+ onTextAreaEmoticon(data)
+ } else {
+ onEmoticonEvent(data)
+ }
+ }
+ "
+ />
{
// 更新mentionUserIds数组,确保与输入框中的@内容一致
const atPattern = /@([^@\s]+)(?:\s|$)/g
const matches = Array.from(value.matchAll(atPattern))
- const mentionedUsers = matches.map(match => match[1].trim().toLowerCase())
+ 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)
+ 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('@')) {
@@ -778,9 +786,9 @@ const onTextAreaChange = (value) => {
// 处理输入框输入事件
const onTextAreaInput = (value) => {
console.log(value, 'value')
- if(value.length > 0){
- if(value[value.length - 1] === '@'){
- if(talkParams.type === 1){
+ if (value.length > 0) {
+ if (value[value.length - 1] === '@') {
+ if (talkParams.type === 1) {
return
}
state.value.isShowMentionSelect = true
@@ -965,8 +973,46 @@ const onEmoticonEvent = (data) => {
emit('editor-event', fn)
}
}
-
+let calcDelta = false
const onEditorChange = () => {
+ if(calcDelta){
+ calcDelta = false
+ return
+ }
+ // 以下逻辑是 光标与@之间存在其他内容时 不触发选人弹窗
+ const qtext = getQuill().getText()
+ let selectIdx = getQuill().getSelection().index
+ const textBeforeCursor = qtext.substring(0, selectIdx)
+ if (textBeforeCursor[0]?.charCodeAt(0) === 10) {
+ const delta = getQuill().getContents()
+ const ops = delta.ops || []
+ if (ops[0].insert === '\n') {
+ ops.splice(0, 1)
+ getQuill().setContents(delta)
+ getQuill().setSelection(getQuill().getText().length, 0)
+ }
+ // for (let i = 0; i < ops.length; i++) {
+ // if (ops[i].insert === '\n') {
+ // console.error('有空格')
+ // ops.splice(i, 1)
+ // calcDelta = true
+ // }
+ // }
+ // getQuill().setContents(delta)
+ // getQuill().setSelection(getQuill().getText().length, 0)
+ }
+ let endWithAt = false
+ if (
+ textBeforeCursor[textBeforeCursor.length - 1] === '@' ||
+ textBeforeCursor[textBeforeCursor.length - 2]?.charCodeAt(0) === 64
+ ) {
+ endWithAt = true
+ }
+ if (endWithAt) {
+ state.value.cursorMention = true
+ } else {
+ state.value.cursorMention = false
+ }
if (getQuill().getText() !== state.value.lastMentionText) {
state.value.lastMentionTriggered = false
}
@@ -1436,6 +1482,11 @@ const clearMultiSelect = () => {
const initData = async () => {
const dialogueList = getDialogueList(talkParams.index_name)
+ let doLocalPaging = false
+ if(dialogueList?.records?.length > 0){
+ doLocalPaging = true
+ }
+ console.error('dialogueList', dialogueList)
let objT = {
uid: talkParams.uid,
@@ -1446,7 +1497,9 @@ const initData = async () => {
no_limit: dialogueList ? 1 : 0,
}
await onLoad({ ...objT })
- zpagingRef.value?.setLocalPaging(records.value)
+ if(doLocalPaging){
+ zpagingRef.value?.setLocalPaging(dialogueList.records)
+ }
}
//点击跳转到聊天设置页面
@@ -1505,9 +1558,9 @@ const getSelectResult = (mentionSelect) => {
//处理要提醒人的消息样式
const getMentionSelectLists = (mentionSelectList) => {
- if(!state.value.canUseQuillEditor){
- if(mentionSelectList.length > 0){
- mentionSelectList.forEach(item => {
+ if (!state.value.canUseQuillEditor) {
+ if (mentionSelectList.length > 0) {
+ mentionSelectList.forEach((item) => {
onTextAreaMention(item)
})
}
@@ -1763,6 +1816,13 @@ const handleAvatarTouchEnd = () => {
}
onMounted(async () => {
+ if (uni.getSystemInfoSync().osName === 'ios') {
+ let versions = uni.getSystemInfoSync().osVersion.split('.')
+ if (Number(versions[0]) < 17) {
+ console.error('ios版本低于17')
+ state.value.canUseQuillEditor = false
+ }
+ }
if (typeof plus !== 'undefined') {
const webview = plus.webview.currentWebview()
webview.setStyle({
@@ -1818,23 +1878,9 @@ onUnmounted(() => {
// 修改防抖函数的实现
const showMentionSelectDebounced = (quill) => {
const text = quill.getText()
-
- // 以下逻辑是 光标与@之间存在其他内容时 不触发选人弹窗
- const selection = quill.getSelection()
- if (selection) {
- state.lastSelection = selection.index
- if (
- text[selection.index - 1].charCodeAt(0) !== 64 &&
- text[selection.index - 1].charCodeAt(0) !== 32 &&
- text[selection.index - 1].charCodeAt(0) !== 10
- ) {
- uni.showToast({
- title: text[selection.index - 1],
- icon: 'none',
- })
- state.value.lastMentionTriggered = false
- return
- }
+ // 光标不在@后第一位时,不触发选人弹窗
+ if (!state.value.cursorMention) {
+ return
}
// 以下逻辑是 记录触发@时,用户的输入框内容,下次一样内容得@不会再次触发
if (text !== state.value.lastMentionText) {
@@ -1870,14 +1916,23 @@ const onTextAreaMention = (user) => {
if (talkParams.type === 1) {
return
}
- if(state.value.textAreaValue.length > 0){
- if(state.value.textAreaValue[state.value.textAreaValue.length - 1] === '@'){
+ 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){
+
+ // 先创建新数组,再赋值
+ const newMentionUserIds = state.value.mentionUserIds
+ ? [...state.value.mentionUserIds]
+ : []
+ newMentionUserIds.push(user.nickname === '所有人' ? 0 : user.id)
+ state.value.mentionUserIds = newMentionUserIds
+
+ if (state.value.isShowMentionSelect) {
state.value.isShowMentionSelect = false
}
}
diff --git a/src/plugins/ws-socket.js b/src/plugins/ws-socket.js
index 110ccff..b6e3212 100644
--- a/src/plugins/ws-socket.js
+++ b/src/plugins/ws-socket.js
@@ -23,7 +23,7 @@ class WsSocket {
lockReconnect: false,
setTimeout: null, // 计时器对象
time: 3000, // 重连间隔时间
- number: 10000000 // 重连次数
+ number: 20 // 重连次数
}
}