Browse Source

1.编辑框优化

2.修复"请求后发先至"导致的消息乱序问题
3.修复几个小bug
master
xsx 2 years ago
parent
commit
9bf4859e94
  1. 2
      im-commom/src/main/java/com/bx/imcommon/mq/RedisMQPullTask.java
  2. 58
      im-uniapp/pages/chat/chat-box.vue
  3. 6
      im-web/src/components/chat/ChatAtBox.vue
  4. 241
      im-web/src/components/chat/ChatBox.vue
  5. 316
      im-web/src/components/chat/ChatInput.vue
  6. 10
      im-web/src/components/chat/ChatMessageItem.vue
  7. 14
      im-web/src/view/Home.vue

2
im-commom/src/main/java/com/bx/imcommon/mq/RedisMQPullTask.java

@ -53,6 +53,8 @@ public class RedisMQPullTask implements CommandLineRunner {
List<Object> datas = new LinkedList<>();
try {
if(redisMQTemplate.isClose()){
// 如果redis未初始化或已断开,3s后再重新尝试消费
EXECUTOR.schedule(this, 3, TimeUnit.SECONDS);
return;
}
if (consumer.isReady()) {

58
im-uniapp/pages/chat/chat-box.vue

@ -132,9 +132,10 @@
showRecord: false,
keyboardHeight: 322,
atUserIds: [],
recordText: "",
needScrollToBottom: false, //
showMinIdx: 0 // showMinIdx
showMinIdx: 0, // showMinIdx
reqQueue: [], //
isSending: false //
}
},
methods: {
@ -154,11 +155,7 @@
}
// id
this.fillTargetId(msgInfo, this.chat.targetId);
this.$http({
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
@ -278,19 +275,14 @@
receipt: this.isReceipt,
type: 0
}
this.sendText = "";
// id
this.fillTargetId(msgInfo, this.chat.targetId);
this.sendText = "";
this.$http({
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
this.moveChatToTop();
this.sendText = "";
}).finally(() => {
//
this.scrollToBottom();
@ -408,11 +400,7 @@
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.content = JSON.stringify(res.data);
msgInfo.receipt = this.isReceipt
this.$http({
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = m.id;
this.isReceipt = false;
@ -463,11 +451,7 @@
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.content = JSON.stringify(data);
msgInfo.receipt = this.isReceipt
this.$http({
url: this.messageAction,
method: 'POST',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = m.id;
this.isReceipt = false;
@ -632,6 +616,32 @@
let px = info.windowWidth * rpx / 750;
return Math.floor(rpx);
},
sendMessageRequest(msgInfo){
return new Promise((resolve,reject)=>{
// ""
this.reqQueue.push({msgInfo,resolve,reject});
this.processReqQueue();
})
},
processReqQueue(){
if (this.reqQueue.length && !this.isSending) {
this.isSending = true;
const reqData = this.reqQueue.shift();
this.$http({
url: this.messageAction,
method: 'post',
data: reqData.msgInfo
}).then((res)=>{
reqData.resolve(res)
}).catch((e)=>{
reqData.reject(e)
}).finally(()=>{
this.isSending = false;
//
this.processReqQueue();
})
}
},
generateId(){
// id
return String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));

6
im-web/src/components/chat/ChatAtBox.vue

@ -1,5 +1,5 @@
<template>
<el-scrollbar v-show="show" ref="scrollBox" class="group-member-choose"
<el-scrollbar v-show="show&&showMembers.length" ref="scrollBox" class="group-member-choose"
:style="{'left':pos.x+'px','top':pos.y-300+'px'}">
<div v-for="(member,idx) in showMembers" :key="member.id">
<chat-group-member :member="member" :height="40" :active='activeIdx==idx'
@ -56,10 +56,6 @@
}
})
this.activeIdx = this.showMembers.length > 0 ? 0: -1;
console.log(this.showMembers.length)
if(this.showMembers.length == 0){
this.close();
}
},
open(pos) {
this.show = true;

241
im-web/src/components/chat/ChatBox.vue

@ -58,23 +58,8 @@
<div title="聊天记录" class="el-icon-chat-dot-round" @click="showHistoryBox()"></div>
</div>
<div class="send-content-area">
<!-- <div contenteditable="true" v-show="!sendImageUrl" ref="editBox" class="send-text-area"-->
<!-- :disabled="lockMessage" @paste.prevent="onEditorPaste"-->
<!-- @compositionstart="onEditorCompositionStart"-->
<!-- @compositionend="onEditorCompositionEnd" @input="onEditorInput"-->
<!-- :placeholder="placeholder" @blur="onEditBoxBlur()" @keydown.down="onKeyDown"-->
<!-- @keydown.up="onKeyUp" @keydown.enter.prevent="onKeyEnter($event)">x-->
<!-- </div>-->
<!-- <div v-show="sendImageUrl" class="send-image-area">-->
<!-- <div class="send-image-box">-->
<!-- <img class="send-image" :src="sendImageUrl" />-->
<!-- <span class="send-image-close el-icon-close" title="删除"-->
<!-- @click="removeSendImage()"></span>-->
<!-- </div>-->
<!-- </div>-->
<ChatInput :ownerId="group.ownerId" ref="chatInputEditor" :group-members="groupMembers"
@submit="sendMessage"/>
@submit="sendMessage" />
<div class="send-btn-area">
<el-button type="primary" size="small" @click="notifySend()">发送</el-button>
</div>
@ -88,8 +73,6 @@
</el-container>
</el-main>
<emotion ref="emoBox" @emotion="onEmotion"></Emotion>
<!-- <chat-at-box ref="atBox" :ownerId="group.ownerId" :members="groupMembers" :search-text="atSearchText"-->
<!-- @select="onAtSelect"></chat-at-box>-->
<chat-record :visible="showRecord" @close="closeRecordBox" @send="onSendRecord"></chat-record>
<group-member-selector ref="rtcSel" :groupId="group.id" @complete="onInviteOk"></group-member-selector>
<rtc-group-join ref="rtcJoin" :groupId="group.id"></rtc-group-join>
@ -100,19 +83,19 @@
</template>
<script>
import ChatGroupSide from "./ChatGroupSide.vue";
import ChatMessageItem from "./ChatMessageItem.vue";
import FileUpload from "../common/FileUpload.vue";
import Emotion from "../common/Emotion.vue";
import ChatRecord from "./ChatRecord.vue";
import ChatHistory from "./ChatHistory.vue";
import ChatAtBox from "./ChatAtBox.vue"
import GroupMemberSelector from "../group/GroupMemberSelector.vue"
import RtcGroupJoin from "../rtc/RtcGroupJoin.vue"
import ChatInput from "./ChatInput";
export default {
import ChatGroupSide from "./ChatGroupSide.vue";
import ChatMessageItem from "./ChatMessageItem.vue";
import FileUpload from "../common/FileUpload.vue";
import Emotion from "../common/Emotion.vue";
import ChatRecord from "./ChatRecord.vue";
import ChatHistory from "./ChatHistory.vue";
import ChatAtBox from "./ChatAtBox.vue"
import GroupMemberSelector from "../group/GroupMemberSelector.vue"
import RtcGroupJoin from "../rtc/RtcGroupJoin.vue"
import ChatInput from "./ChatInput";
export default {
name: "chatPrivate",
components: {
ChatInput,
@ -144,11 +127,9 @@ export default {
showSide: false, //
showHistory: false, //
lockMessage: false, //
showMinIdx: 0, // showMinIdx
atSearchText: "",
focusNode: null, //
focusOffset: null, //
zhLock: false //
showMinIdx: 0, // showMinIdx
reqQueue: [],
isSending : false
}
},
methods: {
@ -171,50 +152,11 @@ export default {
this.isReceipt = !this.isReceipt;
this.refreshPlaceHolder();
},
createSendText() {
let sendText = this.isReceipt ? "【回执消息】" : "";
this.$refs.editBox.childNodes.forEach((node) => {
if (node.nodeName == "#text") {
sendText += this.html2Escape(node.textContent);
} else if (node.nodeName == "SPAN") {
sendText += node.innerHTML;
} else if (node.nodeName == "IMG") {
sendText += node.dataset.code;
}
})
return sendText;
},
html2Escape(strHtml) {
return strHtml.replace(/[<>&"]/g, function (c) {
return {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;'
} [c];
});
},
createAtUserIds(sendContent) {
let ids = [];
let tempEl = document.createElement('div');
tempEl.innerHTML = sendContent;
tempEl.childNodes.forEach((node) => {
if (node.nodeName == "SPAN") {
ids.push(node.dataset.id);
}
})
return ids;
},
onImageSuccess(data, file) {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.content = JSON.stringify(data);
msgInfo.receipt = this.isReceipt;
this.$http({
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((id) => {
this.sendMessageRequest(msgInfo).then((id) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = id;
this.isReceipt = false;
@ -265,11 +207,7 @@ export default {
let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
msgInfo.content = JSON.stringify(data);
msgInfo.receipt = this.isReceipt
this.$http({
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
msgInfo.loadStatus = 'ok';
msgInfo.id = m.id;
this.isReceipt = false;
@ -337,22 +275,7 @@ export default {
})
},
onEmotion(emoText) {
//
// this.$refs.editBox.focus();
// let range = window.getSelection().getRangeAt(0);
// //
// range.setStart(this.focusNode, this.focusOffset)
// let element = document.createElement('IMG')
// element.className = "emo"
// element.dataset.code = emoText;
// element.contentEditable = 'true'
// element.setAttribute("src", this.$emo.textToUrl(emoText));
// //
// range.insertNode(element)
// //
// range.collapse()
this.$refs.chatInputEditor.insertEmoji(emoText);
},
showRecordBox() {
this.showRecord = true;
@ -382,7 +305,6 @@ export default {
let ids = [this.mine.id];
let maxChannel = this.$store.state.configStore.webrtc.maxChannel;
this.$refs.rtcSel.open(maxChannel, ids, ids);
}
})
@ -424,11 +346,7 @@ export default {
}
// id
this.fillTargetId(msgInfo, this.chat.targetId);
this.$http({
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
@ -441,7 +359,6 @@ export default {
this.showRecord = false;
this.isReceipt = false;
this.refreshPlaceHolder();
})
},
fillTargetId(msgInfo, targetId) {
@ -454,42 +371,29 @@ export default {
notifySend() {
this.$refs.chatInputEditor.submit();
},
sendMessage(fullList) {
// if (this.sendImageFile) {
// this.sendImageMessage();
// } else {
// this.sendTextMessage();
// }
// //
// this.readedMessage()
//
// console.log(arguments)
async sendMessage(fullList) {
this.resetEditor();
this.readedMessage();
let sendText = this.isReceipt ? "【回执消息】" : "";
let promiseList = [];
for (let i = 0; i < fullList.length; i++) {
let msg = fullList[i];
promiseList.push(new Promise(() => {
switch (msg.type) {
case "text":
this.sendTextMessage(sendText + msg.content);
await this.sendTextMessage(sendText + msg.content,msg.atUserIds);
break;
case "image":
this.sendImageMessage(msg.content.file);
await this.sendImageMessage(msg.content.file);
break;
case "file":
console.log(msg)
this.sendFileMessage(msg.content.file);
await this.sendFileMessage(msg.content.file);
break;
}
}))
}
Promise.all(promiseList);
// console.log(arguments)
this.$refs.chatInputEditor.clear();
},
sendImageMessage(file) {
return new Promise((resolve,reject)=>{
this.onImageBefore(file);
let formData = new FormData()
formData.append('file', file)
@ -499,15 +403,19 @@ export default {
}
}).then((data) => {
this.onImageSuccess(data, file);
resolve();
}).catch((res) => {
this.onImageSuccess(res, file);
this.onImageFail(res, file);
reject();
})
this.$nextTick(() => this.$refs.chatInputEditor.focus());
this.scrollToBottom();
});
},
sendTextMessage(sendText) {
sendTextMessage(sendText,atUserIds) {
return new Promise((resolve,reject)=>{
if (!sendText.trim()) {
return
reject();
}
let msgInfo = {
content: sendText,
@ -517,34 +425,30 @@ export default {
this.fillTargetId(msgInfo, this.chat.targetId);
// @
if (this.chat.type == "GROUP") {
msgInfo.atUserIds = this.createAtUserIds(sendText);
msgInfo.atUserIds = atUserIds;
msgInfo.receipt = this.isReceipt;
}
this.lockMessage = true;
this.$http({
url: this.messageAction,
method: 'post',
data: msgInfo
}).then((m) => {
this.sendMessageRequest(msgInfo).then((m) => {
m.selfSend = true;
this.$store.commit("insertMessage", m);
//
this.moveChatToTop();
}).finally(() => {
//
this.lockMessage = false;
this.scrollToBottom();
this.resetEditor();
this.isReceipt = false;
resolve();
});
});
},
sendFileMessage(file) {
return new Promise((resolve,reject)=>{
let check = this.$refs.fileUpload.beforeUpload(file);
if (check) {
this.$refs.fileUpload.onFileUpload({file});
this.$refs.fileUpload.onFileUpload({ file });
}
})
},
deleteMessage(msgInfo) {
this.$confirm('确认删除消息?', '删除消息', {
@ -588,8 +492,7 @@ export default {
this.$http({
url: url,
method: 'put'
}).then(() => {
})
}).then(() => {})
},
loadReaded(fId) {
this.$http({
@ -610,7 +513,6 @@ export default {
this.group = group;
this.$store.commit("updateChatFromGroup", group);
this.$store.commit("updateGroup", group);
});
this.$http({
@ -651,11 +553,8 @@ export default {
resetEditor() {
this.$nextTick(() => {
// this.$refs.editBox.innerHTML = "";
// this.$refs.editBox.focus();
this.$refs.chatInputEditor.clear();
this.$refs.chatInputEditor.focus();
});
},
scrollToBottom() {
@ -673,6 +572,32 @@ export default {
this.placeholder = "聊点什么吧~";
}
},
sendMessageRequest(msgInfo){
return new Promise((resolve,reject)=>{
// ""
this.reqQueue.push({msgInfo,resolve,reject});
this.processReqQueue();
})
},
processReqQueue(){
if (this.reqQueue.length && !this.isSending) {
this.isSending = true;
const reqData = this.reqQueue.shift();
this.$http({
url: this.messageAction,
method: 'post',
data: reqData.msgInfo
}).then((res)=>{
reqData.resolve(res)
}).catch((e)=>{
reqData.reject(e)
}).finally(()=>{
this.isSending = false;
//
this.processReqQueue();
})
}
},
generateId() {
// id
return String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));
@ -702,7 +627,6 @@ export default {
}
return this.chat.messages.length;
}
},
watch: {
chat: {
@ -747,11 +671,11 @@ export default {
let div = document.getElementById("chatScrollBox");
div.addEventListener('scroll', this.onScroll)
}
}
}
</script>
<style lang="scss">
.chat-box {
.chat-box {
position: relative;
width: 100%;
background: #f8f8f8;
@ -771,7 +695,6 @@ export default {
line-height: 50px;
font-size: 25px;
cursor: pointer;
}
}
@ -780,7 +703,7 @@ export default {
background-color: #f8f8f8;
.im-chat-box {
> ul {
>ul {
padding: 0 20px;
li {
@ -804,28 +727,31 @@ export default {
box-sizing: border-box;
border-top: #ccc solid 1px;
padding: 2px;
background-color: #f5f5f5;
background-color: #e8f2ff;
> div {
>div {
font-size: 22px;
cursor: pointer;
color: black;
line-height: 34px;
width: 34px;
height: 34px;
line-height: 30px;
width: 30px;
height: 30px;
text-align: center;
border-radius: 3px;
margin: 3px;
&:hover {
color: black;
}
&.chat-tool-active {
background: #ddd;
font-weight: 600;
color: #195ee2;
background-color: #ddd;
}
}
> div:hover {
>div:hover {
color: #949494;
}
}
@ -845,7 +771,6 @@ export default {
resize: none;
font-size: 16px;
color: black;
//outline-color: rgba(83, 160, 231, 0.61);
outline: none;
text-align: left;
@ -903,7 +828,6 @@ export default {
border: 1px solid #ccc;
}
}
}
.send-btn-area {
@ -913,12 +837,11 @@ export default {
right: 0;
}
}
}
.chat-group-side-box {
border: #dddddd solid 1px;
animation: rtl-drawer-in .3s 1ms;
}
}
}
</style>

316
im-web/src/components/chat/ChatInput.vue

@ -1,72 +1,54 @@
<template>
<div class="chat-input-area">
<div :class="['edit-chat-container',isEmpty?'':'not-empty']" contenteditable="true"
@paste.prevent="onPaste"
@keydown="onKeydown"
@compositionstart="compositionFlag=true"
@compositionend="compositionFlag=false;updateRange()"
@input="onEditorInput"
@mousedown="onMousedown"
v-html="contentHtml"
ref="content"
@blur="onBlur"
>
<div :class="['edit-chat-container',isEmpty?'':'not-empty']" contenteditable="true" @paste.prevent="onPaste"
@keydown="onKeydown" @compositionstart="compositionFlag=true" @compositionend="onCompositionEnd"
@input="onEditorInput" @mousedown="onMousedown" ref="content" @blur="onBlur">
</div>
<chat-at-box @select="onAtSelect"
:search-text="atSearchText"
ref="atBox"
:ownerId="ownerId"
:members="groupMembers"
></chat-at-box>
<chat-at-box @select="onAtSelect" :search-text="atSearchText" ref="atBox" :ownerId="ownerId"
:members="groupMembers"></chat-at-box>
</div>
</template>
<script>
import ChatAtBox from "./ChatAtBox";
import ChatAtBox from "./ChatAtBox";
export default {
export default {
name: "ChatInput",
components: {ChatAtBox},
components: { ChatAtBox },
props: {
ownerId: {
type: Number,
},
groupMembers: {
type: Array,
},
},
data() {
const defaultContentHtml = '<div></div>';
return {
// contentList: [],
// content: null,
defaultContentHtml,
contentHtml: defaultContentHtml + '',
imageList: [],
fileList: [],
currentId: 0,
atSearchText: null,
compositionFlag: false,
history: [defaultContentHtml],
atIng: false,
isEmpty: true,
changeStored: true,
blurRange: null
}
}, methods: {
},
methods: {
onPaste(e) {
this.isEmpty = false;
let txt = e.clipboardData.getData('Text')
let range = window.getSelection().getRangeAt(0)
if (range.startContainer !== range.endContainer || range.startOffset !== range.endOffset) {
range.deleteContents();
}
//
if (txt && typeof (txt) == 'string') {
if (txt && typeof(txt) == 'string') {
let textNode = document.createTextNode(txt);
range.insertNode(textNode)
range.collapse();
return;
}
let items = (e.clipboardData || window.clipboardData).items
@ -80,49 +62,37 @@ export default {
url: URL.createObjectURL(file)
};
this.imageList[imagePush.fileId] = (imagePush);
let divElement = this.newLine();
let text = document.createTextNode('\u00A0');
divElement.appendChild(text);
let line = this.newLine();
let imageElement = document.createElement('img');
imageElement.className = 'chat-image no-text';
imageElement.src = imagePush.url;
imageElement.dataset.imgId = imagePush.fileId;
divElement.appendChild(imageElement);
line.appendChild(imageElement);
let after = document.createTextNode('\u00A0');
divElement.appendChild(after);
line.appendChild(after);
this.selectElement(after, 1);
// range.insertNode(divElement);
} else {
let asFile = items[i].getAsFile();
if (!asFile) {
continue;
}
let filePush = {fileId: this.generateId(), file: asFile};
let filePush = { fileId: this.generateId(), file: asFile };
this.fileList[filePush.fileId] = (filePush)
let line = this.newLine();
let text = document.createTextNode('\u00A0');
line.appendChild(text);
let fileElement = this.createFile(filePush);
line.appendChild(fileElement);
let after = document.createTextNode('\u00A0');
line.appendChild(after);
this.selectElement(after, 1);
// fileElement.insertAdjacentHTML('afterend', '\u00A0');
}
}
}
range.collapse();
},
selectElement(element, endOffset) {
let selection = window.getSelection();
// vuedom
setTimeout(() => {
this.$nextTick(() => {
let t1 = document.createRange();
t1.setStart(element, 0);
t1.setEnd(element, endOffset || 0);
@ -130,7 +100,6 @@ export default {
t1.selectNodeContents(element.firstChild);
}
t1.collapse();
selection.removeAllRanges();
selection.addRange(t1);
//
@ -139,6 +108,10 @@ export default {
}
})
},
onCompositionEnd(e) {
this.compositionFlag = false;
this.onEditorInput(e);
},
onKeydown(e) {
if (e.keyCode === 13) {
e.preventDefault();
@ -148,10 +121,11 @@ export default {
this.$refs.atBox.select();
return;
}
if (e.shiftKey) {
let divElement = this.newLine();
this.selectElement(divElement);
if (e.ctrlKey) {
let line = this.newLine();
let after = document.createTextNode('\u00A0');
line.appendChild(after);
this.selectElement(line.childNodes[0], 0);
} else {
//
if (this.compositionFlag) {
@ -161,42 +135,15 @@ export default {
}
return;
}
if (e.keyCode === 90) {
// Ctrl+Zmaccommand+z
if (e.ctrlKey || e.metaKey) {
// ctrl+zctrl+zlow
e.preventDefault();
e.stopPropagation();
if (this.history.length <= 1) {
return;
}
if (this.changeStored) {
this.history.pop();
}
let last = this.history.pop();
// console.log('', last);
this.contentHtml = last;
if (this.history.length === 0) {
//
this.history.push(this.defaultContentHtml);
}
// dom
setTimeout(() => {
let t = this.$refs.content.lastElementChild.lastChild;
if (!t || !t.textContent) {
return;
}
this.selectElement(t, t.textContent.length);
})
}
}
//
if (e.keyCode === 8) {
console.log("delete")
// dom
setTimeout(() => {
let s = this.$refs.content.innerHTML.trim();
// domdom
if (s === '' || s === '<br>' || s === '<div><br></div>' || s === '<div><br/></div>') {
console.log(s);
if (s === '' || s === '<br>' || s === '<div>&nbsp;</div>' ) {
// dom
this.empty();
this.isEmpty = true;
@ -219,24 +166,27 @@ export default {
this.$refs.atBox.moveDown();
}
}
},
onAtSelect(member) {
this.atIng = false;
// @xx
let blurRange = this.blurRange;
let startOffset = blurRange.endOffset - this.atSearchText.length - 1;
let endContainer = blurRange.endContainer
let startOffset = endContainer.data.indexOf("@"+this.atSearchText);
let endOffset = startOffset + this.atSearchText.length + 1;
blurRange.setStart(blurRange.endContainer, startOffset);
blurRange.setEnd(blurRange.endContainer, endOffset);
blurRange.deleteContents()
blurRange.collapse();
console.log("onAtSelect")
this.focus();
//
let element = document.createElement('SPAN')
element.className = "chat-at-user";
element.dataset.id = member.userId;
element.contentEditable = 'false'
element.innerText = `@${member.aliasName}`
element.innerText = `@${member.showNickName}`
blurRange.insertNode(element)
//
blurRange.collapse()
@ -250,10 +200,8 @@ export default {
this.selectElement(textNode, 1);
},
onEditorInput(e) {
// timeoutcompositionend
this.isEmpty = false;
this.changeStored = false;
setTimeout(() => {
if (this.$props.groupMembers && !this.compositionFlag) {
let selection = window.getSelection()
let range = selection.getRangeAt(0);
@ -273,8 +221,7 @@ export default {
this.$refs.atBox.close();
return;
}
//
this.showAtBox(e)
let endIndex = endOffset;
for (let i = endOffset; i < textContent.length; i++) {
if (textContent[i] === ' ') {
@ -283,11 +230,16 @@ export default {
}
}
this.atSearchText = textContent.substring(startIndex + 1, endIndex).trim();
//
if (this.atSearchText == '') {
this.showAtBox(e)
}
})
}
},
onBlur(e) {
this.updateRange();
},
onMousedown() {
if (this.atIng) {
@ -337,8 +289,7 @@ export default {
container.appendChild(left);
let icon = document.createElement('div');
icon.className = 'file-icon';
icon.innerText = '?';
icon.className = 'el-icon-document';
left.appendChild(icon);
let right = document.createElement('div');
@ -376,24 +327,18 @@ export default {
newLine() {
let selection = window.getSelection();
let range = selection.getRangeAt(0);
let divElement = document.createElement('div');
let endContainer = range.endContainer;
let parentElement = endContainer.parentElement;
let newText = endContainer.textContent.substring(range.endOffset).trim();
if (parentElement.parentElement === this.$refs.content) {
divElement.innerHTML = endContainer.textContent.substring(range.endOffset).trim();
endContainer.textContent = endContainer.textContent.substring(0, range.endOffset);
divElement.innerHTML = newText || '';
// atparentbug
if (parentElement === this.$refs.content) {
this.$refs.content.append(divElement);
} else {
// div
parentElement.insertAdjacentElement('afterend', divElement);
} else {
divElement.innerHTML = '';
this.$refs.content.append(divElement);
}
this.isEmpty = false;
return divElement;
},
clear() {
@ -402,12 +347,11 @@ export default {
this.fileList = [];
},
empty() {
let emptyCount = Math.random() * 100 + 5;
let content = '';
for (let i = 0; i < emptyCount; i++) {
content += ' ';
}
this.contentHtml = this.defaultContentHtml + content;
this.$refs.content.innerHTML = "";
let line = this.newLine();
let after = document.createTextNode('\u00A0');
line.appendChild(after);
this.$nextTick(()=>this.selectElement(after));
},
showAtBox(e) {
this.atIng = true;
@ -424,17 +368,21 @@ export default {
//
this.updateRange();
},
html2Escape(strHtml) {
return strHtml.replace(/[<>&"]/g, function(c) {
return {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;'
} [c];
});
},
submit() {
// console.log(this.content)
let nodes = this.$refs.content.childNodes;
let textList = [];
let imageList = [];
let fileList = [];
let fullList = [];
let tempText = '';
let atUserIds = [];
let each = (nodes) => {
for (let i = 0; i < nodes.length; i++) {
let node = nodes[i];
@ -442,7 +390,7 @@ export default {
continue;
}
if (node.nodeType === 3) {
tempText += node.textContent;
tempText += this.html2Escape(node.textContent);
continue;
}
let nodeName = node.nodeName.toLowerCase();
@ -456,16 +404,16 @@ export default {
if (text) {
fullList.push({
type: 'text',
content: text
content: text,
atUserIds: atUserIds
})
tempText = '';
atUserIds = []
}
fullList.push({
type: 'image',
content: this.imageList[imgId]
})
imageList.push(this.imageList[imgId]);
textList.push(text);
tempText = '';
} else {
let emojiCode = node.dataset.emojiCode;
tempText += emojiCode;
@ -477,33 +425,27 @@ export default {
if (text) {
fullList.push({
type: 'text',
content: text
content: text,
atUserIds: atUserIds
})
tempText = '';
atUserIds = []
}
fullList.push({
type: 'file',
content: this.fileList[fileId]
})
fileList.push(this.fileList[fileId]);
textList.push(text);
tempText = '';
} else {
tempText += '\n';
each(node.childNodes);
}
} else if (nodeName === 'span') {
let userId = node.dataset.id;
if (userId !== null && userId !== undefined) {
tempText += node.outerHTML;
}
} else {
console.warn('未处理的标签');
if (getComputedStyle(node).display === 'block') {
tempText += '\n';
} else {
tempText += ' ';
if(node.dataset.id){
tempText += node.innerHTML;
atUserIds.push(node.dataset.id)
}else {
tempText += node.outerHtml;
}
each(node.childNodes);
}
}
}
@ -512,51 +454,27 @@ export default {
if (text !== '') {
fullList.push({
type: 'text',
content: text
content: text,
atUserIds: atUserIds
})
textList.push(text);
}
// console.log(textList, imageList, fileList)
this.$emit('submit', fullList, textList, imageList, fileList);
this.$emit('submit', fullList);
},
focus() {
this.$refs.content.focus();
}
},
mounted() {
// console.log(this.$props.groupMembers)
// this.$refs.content.firstElementChild.focus();
this.selectElement(this.$refs.content.firstElementChild);
setInterval(() => {
if (!this.$refs.content) {
return;
}
//
if (this.compositionFlag) {
return;
}
let last = this.history[this.history.length - 1];
let newContent = this.$refs.content.innerHTML;
if (last !== newContent) {
this.history.push(newContent);
}
this.changeStored = true;
}, 1000);
}
}
</script>
<style lang="scss">
.chat-input-area {
.chat-input-area {
width: 100%;
height: 100%;
position: relative;
.edit-chat-container {
//width: 100%;
//height: 100%;
position: absolute;
top: 0;
left: 0;
@ -564,19 +482,14 @@ export default {
bottom: 0;
border: 1px solid #c3c3c3;
outline: none;
padding: 10px 0;
padding: 5px;
line-height: 30px;
font-size: 16px;
text-align: left;
> div {
padding-left: 10px;
//width: 1px;
min-height: 30px;
}
overflow-y: scroll;
// bug
> div:before {
>div:before {
content: "\00a0";
font-size: 14px;
position: absolute;
@ -585,11 +498,11 @@ export default {
}
.chat-image {
display: block;
max-width: 200px;
max-height: 100px;
border: 1px solid #e6e6e6;
cursor: pointer;
//margin-left: 10px;
}
.chat-emoji {
@ -600,66 +513,59 @@ export default {
}
.chat-file-container {
width: 200px;
//height: 100px;
padding: 5px 7px;
border: 1px solid #4cd964;
max-width: 65%;
padding: 10px;
border: 2px solid #587ff0;
display: flex;
background: #eeeC;
border-radius: 10px;
.file-position-left {
width: 30%;
flex: 1;
display: flex;
width: 80px;
justify-content: center;
align-items: center;
.file-icon {
width: 30px;
height: 30px;
.el-icon-document {
font-size: 40px;
text-align: center;
justify-content: center;
align-items: center;
vertical-align: center;
border: 1px solid #e6e6e6;
color: #d42e07;
}
}
.file-position-right {
width: 70%;
flex: 3;
flex: 1;
.file-name {
font-size: 14px;
color: #333;
font-size: 16px;
font-weight: 600;
color: #66b1ff;
}
.file-size {
font-size: 12px;
color: #666;
font-size: 14px;
font-weight: 600;
color: black;
}
}
}
.chat-at-user {
background-color: #4cd964;
padding: 2px 5px;
color: white;
//border: 1px solid #c3c3c3;
color: #00f;
font-weight: 600;
border-radius: 3px;
}
}
.edit-chat-container > div:nth-of-type(1):empty:after {
content: '请输入消息(按Shift+Enter键换行)';
.edit-chat-container>div:nth-of-type(1):after {
content: '请输入消息(按Ctrl+Enter键换行)';
color: gray;
}
.edit-chat-container > div:nth-of-type(1):focus:after {
.edit-chat-container.not-empty>div:nth-of-type(1):after {
content: none;
}
.edit-chat-container.not-empty > div:nth-of-type(1):after {
content: none;
}
}
</style>

10
im-web/src/components/chat/ChatMessageItem.vue

@ -67,10 +67,8 @@
<span v-if="msgInfo.receiptOk" class="icon iconfont icon-ok" title="全体已读"></span>
<span v-else>{{msgInfo.readedCount}}人已读</span>
</div>
</div>
</div>
</div>
<right-menu v-show="menu && rightMenu.show" :pos="rightMenu.pos" :items="menuItems"
@close="rightMenu.show = false" @select="onSelectMenu"></right-menu>
@ -129,7 +127,6 @@
}
}
}
},
methods: {
onSendFail() {
@ -200,7 +197,7 @@
}
return items;
},
isAction(){
isAction() {
return this.$msgType.isAction(this.msgInfo.type);
},
isNormal() {
@ -410,11 +407,10 @@
}
.chat-at-user {
background-color: #4cd964;
padding: 2px 5px;
color: white;
//border: 1px solid #c3c3c3;
border-radius: 3px;
font-weight: 600;
cursor: pointer;
}
}
}

14
im-web/src/view/Home.vue

@ -126,16 +126,22 @@
})
},
pullPrivateOfflineMessage(minId) {
this.$store.commit("loadingPrivateMsg", true)
this.$http({
url: "/message/private/pullOfflineMessage?minId=" + minId,
method: 'get'
});
method: 'GET'
}).catch(() => {
this.$store.commit("loadingPrivateMsg", false)
})
},
pullGroupOfflineMessage(minId) {
this.$store.commit("loadingGroupMsg", true)
this.$http({
url: "/message/group/pullOfflineMessage?minId=" + minId,
method: 'get'
});
method: 'GET'
}).catch(() => {
this.$store.commit("loadingGroupMsg", false)
})
},
handlePrivateMessage(msg) {
//

Loading…
Cancel
Save