优化前端防卡代码

This commit is contained in:
John Smith 2020-02-04 20:33:29 +08:00
parent b7e06652b4
commit 00e1f31f84

View File

@ -97,6 +97,14 @@ export default {
return this.atBottom/* || this.allowScroll*/
}
},
watch: {
css(val) {
this.styleElement.innerText = val
},
canScrollToBottom(val) {
this.cantScrollStartTime = val ? null : new Date()
}
},
mounted() {
this.styleElement.innerText = this.css
this.scrollToBottom()
@ -109,11 +117,6 @@ export default {
}
this.clearMessages()
},
watch: {
css(val) {
this.styleElement.innerText = val
}
},
methods: {
addMessage(message) {
this.addMessages([message])
@ -446,29 +449,18 @@ export default {
scrollToBottom() {
this.$refs.scroller.scrollTop = Math.pow(2, 24)
this.atBottom = true
if (this.canScrollToBottom) {
this.cantScrollStartTime = null
}
},
onScroll() {
this.refreshCantScrollStartTime()
let scroller = this.$refs.scroller
this.atBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < SCROLLED_TO_BOTTOM_EPSILON
if (this.canScrollToBottom) {
this.cantScrollStartTime = null
}
this.flushMessagesBuffer()
},
canScrollToBottomOrTimedOut() {
if (this.canScrollToBottom) {
this.cantScrollStartTime = null
return true
}
// OBS
if (!this.cantScrollStartTime) {
this.cantScrollStartTime = new Date()
return false
}
return new Date() - this.cantScrollStartTime >= 10 * 1000
},
refreshCantScrollStartTime() {