修复输入内容换行引起的一些问题、修复IE浏览器下报错的问题

This commit is contained in:
fan
2021-01-29 21:03:47 +08:00
parent 177d610b68
commit abf9abac25
15 changed files with 128 additions and 112 deletions
+4 -1
View File
@@ -128,11 +128,14 @@ export default {
+e(content)
font-size 12px
color #999
padding-top 3px
height 14px
line-height 14px
ellipsis()
img
height 14px
display inline-block
vertical-align middle
vertical-align top
margin 0 1px
+m(name-center)
+e(label)
+17 -20
View File
@@ -1,5 +1,5 @@
<script>
import { toEmojiName,useScopedSlot } from "utils";
import { toEmojiName,useScopedSlot,clearHtml } from "utils";
const exec = (val, command = "insertHTML") => {
document.execCommand(command, false, val);
};
@@ -95,7 +95,6 @@ export default {
on-keydown={this._handleKeydown}
on-paste={this._handlePaste}
on-click={this._handleClick}
on-input={this._handleInput}
spellcheck="false"
/>
</div>
@@ -182,9 +181,6 @@ export default {
_handleClick() {
this._saveLastRange();
},
_handleInput() {
this._checkSubmitDisabled();
},
_renderEmojiTabs() {
const renderImageGrid = items => {
return items.map(item => (
@@ -225,17 +221,17 @@ export default {
},
_handlePaste(e) {
e.preventDefault();
const { clipboardData } = e;
const text = clipboardData.getData("text");
exec(text, "insertText");
// Array.from(clipboardData.items).forEach(item => {
// console.log(item.type);
// });
//e.target.innerText = text;
const clipboardData = e.clipboardData || window.clipboardData;
const text = clipboardData.getData("Text");
if(window.clipboardData){
this.$refs.textarea.innerHTML = text;
}else{
exec(text, "insertText");
}
},
_handleKeyup(e) {
this._saveLastRange();
//this._checkSubmitDisabled();
this._checkSubmitDisabled();
},
_handleKeydown(e) {
if(this.submitDisabled == false && this.sendKey(e)){
@@ -243,15 +239,16 @@ export default {
}
},
getFormatValue() {
return toEmojiName(
this.$refs.textarea.innerHTML
.replace(/<br>|<\/br>/, "")
.replace(/<div>|<p>/g, "\r\n")
.replace(/<\/div>|<\/p>/g, "")
);
// return toEmojiName(
// this.$refs.textarea.innerHTML
// .replace(/<br>|<\/br>/, "")
// .replace(/<div>|<p>/g, "\r\n")
// .replace(/<\/div>|<\/p>/g, "")
// );
return toEmojiName(this.$refs.textarea.innerHTML);
},
_checkSubmitDisabled() {
this.submitDisabled = !this.$refs.textarea.innerHTML.trim();
this.submitDisabled = !this.$refs.textarea.innerText.trim();
},
_handleSend(e) {
const text = this.getFormatValue();
+12 -14
View File
@@ -653,11 +653,16 @@ export default {
* EmojiItem = {name: wx,title: 微笑,src: url} 无分组
*/
initEmoji(data) {
let flatData = [];
this.$refs.editor.initEmoji(data);
if (data[0].label) {
data = data.flatMap(item => item.children);
data.forEach(item=>{
flatData.push(...item.children);
})
}else{
flatData = data;
}
data.forEach(({ name, src }) => (emojiMap[name] = src));
flatData.forEach(({ name, src }) => (emojiMap[name] = src));
},
initEditorTools(data){
this.editorTools = data;
@@ -802,19 +807,11 @@ export default {
return this.findContactIndexById(contactId) !== -1;
},
findMessage(messageId){
return Object.values(allMessages).flat().find(({id})=>id == messageId);
for(const key in allMessages){
const message = allMessages[key].find(({id})=>id == messageId)
if(message) return message;
}
},
// findMessageIndexById(messageId, contactId) {
// const msg = messages[contactId];
// if (isEmpty(msg)) {
// return -1;
// }
// return msg.findIndex(item => item.id == messageId);
// },
// findMessageById(messageId, contactId) {
// const index = this.findMessageIndexById(messageId, contactId);
// if (index !== -1) return messages[contactId][index];
// },
/**
* 返回所有联系人
* @return {Array<Contact>}
@@ -858,6 +855,7 @@ bezier = cubic-bezier(0.645, 0.045, 0.355, 1)
+b(lemon-wrapper)
display flex
font-size 14px
font-family "Microsoft YaHei"
//mask-image radial-gradient(circle, white 100%, black 100%)
background #efefef
transition all .4s bezier
+2 -1
View File
@@ -1,3 +1,4 @@
import {clearHtml } from 'utils';
export default {
file(message) {
return "[文件]";
@@ -6,7 +7,7 @@ export default {
return "[图片]";
},
text(message) {
return this.replaceEmojiName(message.content);
return this.replaceEmojiName(clearHtml(message.content));
},
event(message){
return '[通知]';
+4
View File
@@ -70,6 +70,10 @@ export function funCall(event, callback) {
export function arrayIntersect(a, b) {
return a.filter(x => b.includes(x));
}
//清除字符串内的所有HTML标签
export function clearHtml(str){
return str.replace(/<.*?>/ig,"");
}
export function error(text) {
throw new Error(text);