修改@功能问题;新增IOS版本号判断使用哪个输入框;处理聊天记录加载问题

This commit is contained in:
wangyifeng 2025-04-11 14:53:01 +08:00
parent bbb5dd99fc
commit df1cc68b59
2 changed files with 100 additions and 45 deletions

View File

@ -337,13 +337,17 @@
</div>
</div>
<div v-if="state.isOpenEmojiPanel" class="mt-[50rpx]">
<emojiPanel @on-select="(data) => {
if (!state.canUseQuillEditor) {
onTextAreaEmoticon(data)
} else {
onEmoticonEvent(data)
}
}" />
<emojiPanel
@on-select="
(data) => {
if (!state.canUseQuillEditor) {
onTextAreaEmoticon(data)
} else {
onEmoticonEvent(data)
}
}
"
/>
</div>
<div v-if="state.isOpenFilePanel" class="mt-[16rpx]">
<filePanel
@ -753,19 +757,23 @@ const onTextAreaChange = (value) => {
// 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
}
}

View File

@ -23,7 +23,7 @@ class WsSocket {
lockReconnect: false,
setTimeout: null, // 计时器对象
time: 3000, // 重连间隔时间
number: 10000000 // 重连次数
number: 20 // 重连次数
}
}