新增聊天普通输入框,用于处理手机系统版本过低时不支持quill-edior导致的问题

This commit is contained in:
wangyifeng 2025-04-10 19:57:41 +08:00
parent 2953d50e4b
commit bbb5dd99fc

View File

@ -263,9 +263,20 @@
@editorChange="onEditorChange" @editorChange="onEditorChange"
style="width: 100%; flex: 1; height: 100%;" style="width: 100%; flex: 1; height: 100%;"
@click="onEditorClick" @click="onEditorClick"
v-if="state.canUseQuillEditor"
/> />
<!-- <tm-input type=textarea autoHeight focusColor="#F9F9F9" color="#F9F9F9" :inputPadding="[12]" <tm-input
placeholder=""></tm-input> --> type="textarea"
autoHeight
focusColor="#F9F9F9"
color="#F9F9F9"
:inputPadding="[12]"
placeholder=""
v-if="!state.canUseQuillEditor"
@update:modelValue="onTextAreaChange"
v-model="state.textAreaValue"
@input="onTextAreaInput"
></tm-input>
<div class="quote-area" v-if="state?.quoteInfo"> <div class="quote-area" v-if="state?.quoteInfo">
<span <span
v-if="state?.quoteInfo?.msg_type === 1" v-if="state?.quoteInfo?.msg_type === 1"
@ -326,7 +337,13 @@
</div> </div>
</div> </div>
<div v-if="state.isOpenEmojiPanel" class="mt-[50rpx]"> <div v-if="state.isOpenEmojiPanel" class="mt-[50rpx]">
<emojiPanel @on-select="onEmoticonEvent" /> <emojiPanel @on-select="(data) => {
if (!state.canUseQuillEditor) {
onTextAreaEmoticon(data)
} else {
onEmoticonEvent(data)
}
}" />
</div> </div>
<div v-if="state.isOpenFilePanel" class="mt-[16rpx]"> <div v-if="state.isOpenFilePanel" class="mt-[16rpx]">
<filePanel <filePanel
@ -629,6 +646,8 @@ const state = ref({
lastMentionPosition: -1, // @ lastMentionPosition: -1, // @
isLoading: false, //loading isLoading: false, //loading
lastSelection: 0, lastSelection: 0,
canUseQuillEditor: true, //使quill使
textAreaValue: '', //
}) })
uniOnload(async (options) => { uniOnload(async (options) => {
@ -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 = () => { 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 // mentionUserIds
updateMentionUserIds() updateMentionUserIds()
@ -1404,6 +1490,10 @@ const confirmMentionSelect = () => {
selectMemberByAlphabetRef.value.confirmSelectMembers() selectMemberByAlphabetRef.value.confirmSelectMembers()
} }
hideMentionSelect() hideMentionSelect()
//
state.value.selectedMembersNum = 0
state.value.mentionIsMulSelect = false
} }
} }
@ -1415,6 +1505,14 @@ const getSelectResult = (mentionSelect) => {
// //
const getMentionSelectLists = (mentionSelectList) => { const getMentionSelectLists = (mentionSelectList) => {
if(!state.value.canUseQuillEditor){
if(mentionSelectList.length > 0){
mentionSelectList.forEach(item => {
onTextAreaMention(item)
})
}
return
}
const quill = getQuill() const quill = getQuill()
const mention = quill.getModule('mention') const mention = quill.getModule('mention')
@ -1648,7 +1746,11 @@ let currentPressItem = null
const handleAvatarTouchStart = (item) => { const handleAvatarTouchStart = (item) => {
currentPressItem = item currentPressItem = item
avatarPressTimer = setTimeout(() => { avatarPressTimer = setTimeout(() => {
doMentionUser(item) if (!state.value.canUseQuillEditor) {
onTextAreaMention(item)
} else {
doMentionUser(item)
}
}, 500) }, 500)
} }
@ -1749,6 +1851,36 @@ const showMentionSelectDebounced = (quill) => {
state.value.isShowMentionSelect = true state.value.isShowMentionSelect = true
// quill.blur() // 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
}
}
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.dialog-page { .dialog-page {
@ -2045,6 +2177,11 @@ const showMentionSelectDebounced = (quill) => {
display: inline-block; display: inline-block;
} }
} }
:deep(.round-3) {
max-height: 320rpx;
overflow-y: scroll;
}
} }
:deep(.wd-action-sheet) { :deep(.wd-action-sheet) {