perf: 优化输入框自动高度

This commit is contained in:
kuaifan 2023-12-20 15:36:02 +08:00
parent c99f6cfcf2
commit 6eabba9679
5 changed files with 77 additions and 37 deletions

View File

@ -36,10 +36,12 @@
<div <div
ref="editor" ref="editor"
class="no-dark-content" class="no-dark-content"
:style="editorStyle"
@click.stop="onClickEditor" @click.stop="onClickEditor"
@paste="handlePaste"></div> @paste="handlePaste"></div>
<!-- 工具栏占位 -->
<div class="chat-space"></div>
<!-- 工具栏 --> <!-- 工具栏 -->
<ul class="chat-toolbar" @click.stop> <ul class="chat-toolbar" @click.stop>
<!-- 桌面端表情漂浮 --> <!-- 桌面端表情漂浮 -->
@ -293,10 +295,8 @@ export default {
emojiQuickKey: '', emojiQuickKey: '',
emojiQuickItems: [], emojiQuickItems: [],
observer: null, wrapperObserver: null,
wrapperWidth: 0,
wrapperHeight: 0, wrapperHeight: 0,
editorHeight: 0,
recordReady: false, recordReady: false,
recordRec: null, recordRec: null,
@ -330,18 +330,8 @@ export default {
mounted() { mounted() {
this.init(); this.init();
// //
this.observer = new ResizeObserver(entries => { this.wrapperObserver = new ResizeObserver(this.onResizeEvent)
entries.some(({target, contentRect}) => { this.wrapperObserver.observe(this.$el);
if (target === this.$el) {
this.wrapperWidth = contentRect.width;
this.wrapperHeight = contentRect.height;
} else if (target === this.$refs.editor) {
this.editorHeight = contentRect.height;
}
})
});
this.observer.observe(this.$el);
this.observer.observe(this.$refs.editor);
// //
this.recordInter = setInterval(_ => { this.recordInter = setInterval(_ => {
if (this.recordState === 'ing') { if (this.recordState === 'ing') {
@ -374,9 +364,9 @@ export default {
if (this.recordRec) { if (this.recordRec) {
this.recordRec = null this.recordRec = null
} }
if (this.observer) { if (this.wrapperObserver) {
this.observer.disconnect() this.wrapperObserver.disconnect()
this.observer = null this.wrapperObserver = null
} }
if (this.recordInter) { if (this.recordInter) {
clearInterval(this.recordInter) clearInterval(this.recordInter)
@ -410,17 +400,6 @@ export default {
return this.dialogData.type === 'user' && !this.dialogData.bot return this.dialogData.type === 'user' && !this.dialogData.bot
}, },
editorStyle() {
const {wrapperWidth, editorHeight} = this;
const style = {};
if (wrapperWidth > 0
&& editorHeight > 0
&& (wrapperWidth < 280 || editorHeight > 40)) {
style.width = '100%';
}
return style;
},
recordTransferStyle() { recordTransferStyle() {
const {windowScrollY} = this; const {windowScrollY} = this;
return windowScrollY > 0 ? { return windowScrollY > 0 ? {
@ -840,6 +819,14 @@ export default {
} }
}, },
onResizeEvent(entries) {
entries.some(({target, contentRect}) => {
if (target === this.$el) {
this.wrapperHeight = contentRect.height;
}
})
},
quillMention() { quillMention() {
return { return {
allowedChars: /^\S*$/, allowedChars: /^\S*$/,
@ -1286,10 +1273,6 @@ export default {
}) })
}, },
onMoreVisibleChange(v) {
this.showMore = v;
},
setQuote(id, type = 'reply') { setQuote(id, type = 'reply') {
this.dialogId > 0 && this.$store.dispatch("saveDialog", { this.dialogId > 0 && this.$store.dispatch("saveDialog", {
id: this.dialogId, id: this.dialogId,

View File

@ -696,6 +696,8 @@ export default {
approveDetailsShow: false, approveDetailsShow: false,
approvaUserStatus: '', approvaUserStatus: '',
footerObserver: null,
unreadMsgId: 0, // id unreadMsgId: 0, // id
positionLoad: 0, // positionLoad: 0, //
msgPreparedStatus: false, // msgPreparedStatus: false, //
@ -718,6 +720,10 @@ export default {
this.msgSubscribe.unsubscribe(); this.msgSubscribe.unsubscribe();
this.msgSubscribe = null; this.msgSubscribe = null;
} }
if (this.footerObserver) {
this.footerObserver.disconnect()
this.footerObserver = null
}
document.removeEventListener('selectionchange', this.onSelectionchange); document.removeEventListener('selectionchange', this.onSelectionchange);
}, },
@ -1096,6 +1102,22 @@ export default {
immediate: true immediate: true
}, },
isReady: {
handler(ready) {
if (!ready) {
return
}
this.$nextTick(_ => {
if (!this.$refs.footer && this.footerObserver) {
return
}
this.footerObserver = new ResizeObserver(this.onResizeEvent)
this.footerObserver.observe(this.$refs.footer);
})
},
immediate: true
},
msgType() { msgType() {
this.getMsgs({ this.getMsgs({
dialog_id: this.dialogId, dialog_id: this.dialogId,
@ -1773,7 +1795,7 @@ export default {
onTouchEnd() { onTouchEnd() {
if (typeof this.wrapperStart === 'number' && $A.isIos()) { if (typeof this.wrapperStart === 'number' && $A.isIos()) {
$A.scrollToView(this.$refs.footer) $A.scrollToView(this.$refs.footer, false)
} }
}, },
@ -1934,6 +1956,7 @@ export default {
}, },
onHeightChange({newVal, oldVal}) { onHeightChange({newVal, oldVal}) {
this.onFooterResize();
const diff = newVal - oldVal; const diff = newVal - oldVal;
if (diff !== 0) { if (diff !== 0) {
const {offset, tail} = this.scrollInfo() const {offset, tail} = this.scrollInfo()
@ -1943,6 +1966,22 @@ export default {
} }
}, },
onResizeEvent(entries) {
entries.some(({target}) => {
if (target === this.$refs.footer) {
this.onFooterResize()
}
})
},
onFooterResize() {
const footer = this.$refs.footer;
const marginSize = parseInt($A.css(footer, 'marginTop')) + parseInt($A.css(footer, 'marginBottom'))
if (this.$refs.scroller) {
this.$refs.scroller.$el.style.marginBottom = `${footer.getBoundingClientRect().height + marginSize}px`;
}
},
onActive() { onActive() {
this.$emit("on-active"); this.$emit("on-active");
}, },

View File

@ -141,6 +141,10 @@
margin: 4px 7px; margin: 4px 7px;
line-height: 22px; line-height: 22px;
&::-webkit-scrollbar {
display: none;
}
img { img {
max-width: 150px; max-width: 150px;
max-height: 150px; max-height: 150px;
@ -210,8 +214,16 @@
} }
} }
.chat-toolbar { .chat-space {
float: right; float: right;
width: 170px;
height: 30px;
}
.chat-toolbar {
position: absolute;
right: 2px;
bottom: 8px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-end; justify-content: flex-end;

View File

@ -1438,7 +1438,11 @@
} }
.dialog-footer { .dialog-footer {
position: relative; position: absolute;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
padding: 0 24px; padding: 0 24px;
margin-bottom: 16px; margin-bottom: 16px;

View File

@ -629,6 +629,8 @@
padding: 0 4px 0 6px; padding: 0 4px 0 6px;
background-color: #F4F5F7; background-color: #F4F5F7;
.chat-toolbar { .chat-toolbar {
right: 4px;
bottom: 0;
> li { > li {
&.chat-record-recwave { &.chat-record-recwave {
background-color: #F4F5F7; background-color: #F4F5F7;