perf: 移动端键盘发送

This commit is contained in:
kuaifan 2023-06-18 15:47:13 +08:00
parent a4e41ffb24
commit 9247860b50

View File

@ -271,7 +271,6 @@ export default {
showEmoji: false, showEmoji: false,
emojiQuickShow: false, emojiQuickShow: false,
emojiQuickTimer: null,
emojiQuickKey: '', emojiQuickKey: '',
emojiQuickItems: [], emojiQuickItems: [],
@ -296,7 +295,12 @@ export default {
isSpecVersion: this.checkIOSVersion(), isSpecVersion: this.checkIOSVersion(),
timer: null, emojiTimer: null,
scrollTimer: null,
selectTimer: null,
textTimer: null,
fileTimer: null,
moreTimer: null,
fullInput: false, fullInput: false,
fullQuill: null, fullQuill: null,
@ -363,20 +367,13 @@ export default {
'cacheDialogs', 'cacheDialogs',
'dialogMsgs', 'dialogMsgs',
'keyboardType',
'keyboardHeight',
]), ]),
isEnterSend({enterSend, keyboardType, keyboardHeight, windowTouch}) { isEnterSend({enterSend}) {
if (typeof enterSend === "boolean") { if (typeof enterSend === "boolean") {
return enterSend; return enterSend;
} else { } else {
// 120 return true;
if (windowTouch && keyboardType === "show" && keyboardHeight < 120) {
return true;
}
return !windowTouch
} }
}, },
@ -586,8 +583,8 @@ export default {
}, },
isFocus(val) { isFocus(val) {
if (this.timerScroll) { if (this.scrollTimer) {
clearInterval(this.timerScroll); clearInterval(this.scrollTimer);
} }
if (val) { if (val) {
this.$emit('on-focus') this.$emit('on-focus')
@ -596,11 +593,11 @@ export default {
// ios11.0-11.3 scrollTopscrolIntoViewbug // ios11.0-11.3 scrollTopscrolIntoViewbug
// //
} else if (this.windowPortrait) { } else if (this.windowPortrait) {
this.timerScroll = setInterval(() => { this.scrollTimer = setInterval(() => {
if (this.quill?.hasFocus()) { if (this.quill?.hasFocus()) {
this.windowScrollY > 0 && $A.scrollIntoViewIfNeeded(this.$refs.editor); this.windowScrollY > 0 && $A.scrollIntoViewIfNeeded(this.$refs.editor);
} else { } else {
clearInterval(this.timerScroll); clearInterval(this.scrollTimer);
} }
}, 200); }, 200);
} }
@ -701,8 +698,8 @@ export default {
if (!range && document.activeElement) { if (!range && document.activeElement) {
// //
if (['ql-editor', 'ql-clipboard'].includes(document.activeElement.className)) { if (['ql-editor', 'ql-clipboard'].includes(document.activeElement.className)) {
this.timer && clearTimeout(this.timer) this.selectTimer && clearTimeout(this.selectTimer)
this.timer = setTimeout(_ => { this.selectTimer = setTimeout(_ => {
this.quill.setSelection(document.activeElement.className === 'ql-editor' ? 0 : this.quill.getLength()) this.quill.setSelection(document.activeElement.className === 'ql-editor' ? 0 : this.quill.getLength())
}, 100) }, 100)
return return
@ -713,22 +710,26 @@ export default {
// Update model if text changes // Update model if text changes
this.quill.on('text-change', _ => { this.quill.on('text-change', _ => {
if (this.maxlength > 0 && this.quill.getLength() > this.maxlength) { this.textTimer && clearTimeout(this.textTimer)
this.quill.deleteText(this.maxlength, this.quill.getLength()); this.textTimer = setTimeout(_ => {
} console.log(11);
let html = this.$refs.editor.firstChild.innerHTML if (this.maxlength > 0 && this.quill.getLength() > this.maxlength) {
html = html.replace(/^(<p>\s*<\/p>)+|(<p>\s*<\/p>)+$/gi, '') this.quill.deleteText(this.maxlength, this.quill.getLength());
html = html.replace(/^(<p><br\/*><\/p>)+|(<p><br\/*><\/p>)+$/gi, '')
this.updateEmojiQuick(html)
this._content = html
this.$emit('input', this._content)
this.$nextTick(_ => {
const range = this.quill.getSelection();
if (range) {
const endText = this.quill.getText(range.index);
/^\n\n$/.test(endText) && this.quill.deleteText(range.index, 1);
} }
}) let html = this.$refs.editor.firstChild.innerHTML
html = html.replace(/^(<p>\s*<\/p>)+|(<p>\s*<\/p>)+$/gi, '')
html = html.replace(/^(<p><br\/*><\/p>)+|(<p><br\/*><\/p>)+$/gi, '')
this.updateEmojiQuick(html)
this._content = html
this.$emit('input', this._content)
this.$nextTick(_ => {
const range = this.quill.getSelection();
if (range) {
const endText = this.quill.getText(range.index);
/^\n\n$/.test(endText) && this.quill.deleteText(range.index, 1);
}
})
}, 100)
}) })
// Clipboard Matcher () // Clipboard Matcher ()
@ -761,6 +762,17 @@ export default {
return delta return delta
}) })
// Set enterkeyhint
this.$nextTick(_ => {
this.quill.root.addEventListener('keydown', e => {
if (e.key === '\r\r' && e.keyCode === 229) {
const length = this.quill.getSelection(true).index;
this.quill.insertText(length, "\r\n");
}
});
this.quill.root.setAttribute('enterkeyhint', 'send')
})
// Ready event // Ready event
this.$emit('on-ready', this.quill) this.$emit('on-ready', this.quill)
@ -857,8 +869,8 @@ export default {
this.emojiQuickShow = false this.emojiQuickShow = false
return return
} }
this.emojiQuickTimer && clearTimeout(this.emojiQuickTimer) this.emojiTimer && clearTimeout(this.emojiTimer)
this.emojiQuickTimer = setTimeout(_ => { this.emojiTimer = setTimeout(_ => {
text = text.replace(/&nbsp;/g," ") text = text.replace(/&nbsp;/g," ")
text = text.replace(/<[^>]+>/g, "") text = text.replace(/<[^>]+>/g, "")
if (text if (text
@ -1481,8 +1493,8 @@ export default {
const {owner_id, type} = this.dialogData const {owner_id, type} = this.dialogData
const permission = type === 'group' && [0, this.userId].includes(owner_id) const permission = type === 'group' && [0, this.userId].includes(owner_id)
if (this.taskId > 0 || permission) { if (this.taskId > 0 || permission) {
this.__getMoreTimer && clearTimeout(this.__getMoreTimer) this.moreTimer && clearTimeout(this.moreTimer)
this.__getMoreTimer = setTimeout(_ => { this.moreTimer = setTimeout(_ => {
this.$store.dispatch("call", { this.$store.dispatch("call", {
url: 'users/search', url: 'users/search',
data: { data: {