perf: 优化代码

This commit is contained in:
kuaifan 2023-12-30 02:11:32 +08:00
parent 40d56a0155
commit 63703a029f
7 changed files with 52 additions and 63 deletions

View File

@ -683,11 +683,13 @@ import {MarkdownPreview} from "../store/markdown";
} else { } else {
text = text.replace(/<img\s+class="browse"[^>]*?>/g, `[${$A.L('图片')}]`) text = text.replace(/<img\s+class="browse"[^>]*?>/g, `[${$A.L('图片')}]`)
} }
text = text.replace(/<[^>]+>/g,"") text = text
text = text.replace(/&nbsp;/g," ") .replace(/<[^>]+>/g, "")
text = text.replace(/&amp;/g,"&") .replace(/&nbsp;/g, " ")
text = text.replace(/&lt;/g,"<") .replace(/&quot;/g, "\"")
text = text.replace(/&gt;/g,">") .replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
if (imgClassName) { if (imgClassName) {
text = text.replace(/\[image:(.*?)\]/g, `<img class="${imgClassName}" src="$1">`) text = text.replace(/\[image:(.*?)\]/g, `<img class="${imgClassName}" src="$1">`)
text = text.replace(/\{\{RemoteURL\}\}/g, this.apiUrl('../')) text = text.replace(/\{\{RemoteURL\}\}/g, this.apiUrl('../'))

View File

@ -28,7 +28,7 @@
<div v-if="quoteData" class="chat-quote"> <div v-if="quoteData" class="chat-quote">
<div v-if="quoteUpdate" class="quote-label">{{$L('编辑消息')}}</div> <div v-if="quoteUpdate" class="quote-label">{{$L('编辑消息')}}</div>
<UserAvatar v-else :userid="quoteData.userid" :show-icon="false" :show-name="true"/> <UserAvatar v-else :userid="quoteData.userid" :show-icon="false" :show-name="true"/>
<div class="quote-desc">{{$A.getMsgSimpleDesc(quoteData)}}</div> <div class="quote-desc no-dark-content">{{$A.getMsgSimpleDesc(quoteData)}}</div>
<i class="taskfont" @click.stop="cancelQuote">&#xe6e5;</i> <i class="taskfont" @click.stop="cancelQuote">&#xe6e5;</i>
</div> </div>

View File

@ -100,10 +100,6 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
scrollIng: {
type: Number,
default: 0
},
readEnabled: { readEnabled: {
type: Boolean, type: Boolean,
default: false default: false
@ -154,9 +150,6 @@ export default {
windowActive() { windowActive() {
this.msgRead(); this.msgRead();
}, },
scrollIng() {
this.msgRead();
},
}, },
methods: { methods: {

View File

@ -156,9 +156,9 @@
:data-component="msgItem" :data-component="msgItem"
:item-class-add="itemClassAdd" :item-class-add="itemClassAdd"
:extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, scrollIng, readEnabled}" :extra-props="{dialogData, operateVisible, operateItem, isMyDialog, msgId, unreadMsgId, readEnabled}"
:estimate-size="dialogData.type=='group' ? 105 : 77" :estimate-size="dialogData.type=='group' ? 105 : 77"
:keeps="25" :keeps="keeps"
:disabled="scrollDisabled" :disabled="scrollDisabled"
@activity="onActivity" @activity="onActivity"
@scroll="onScroll" @scroll="onScroll"
@ -631,6 +631,7 @@ export default {
data() { data() {
return { return {
keeps: 25,
msgItem: DialogItem, msgItem: DialogItem,
msgText: '', msgText: '',
msgNew: 0, msgNew: 0,
@ -721,19 +722,17 @@ export default {
scrollDirection: null, scrollDirection: null,
scrollAction: 0, scrollAction: 0,
scrollTmp: 0, scrollTmp: 0,
scrollIng: 0,
approveDetails: {id: 0}, approveDetails: {id: 0},
approveDetailsShow: false, approveDetailsShow: false,
approvaUserStatus: '', approvaUserStatus: '',
footerObserver: null, observers: [],
unreadMsgId: 0, // id unreadMsgId: 0, // id
positionLoad: 0, // positionLoad: 0, //
positionShow: false, // positionShow: false, //
firstMsgLength: 0, // firstMsgLength: 0, //
isFirstShowTag: false, //
msgPreparedStatus: false, // msgPreparedStatus: false, //
listPreparedStatus: false, // listPreparedStatus: false, //
selectedTextStatus: false, // selectedTextStatus: false, //
@ -754,10 +753,9 @@ export default {
this.msgSubscribe.unsubscribe(); this.msgSubscribe.unsubscribe();
this.msgSubscribe = null; this.msgSubscribe = null;
} }
if (this.footerObserver) { this.observers.forEach(({observer}) => observer.disconnect())
this.footerObserver.disconnect() this.observers = []
this.footerObserver = null //
}
document.removeEventListener('selectionchange', this.onSelectionchange); document.removeEventListener('selectionchange', this.onSelectionchange);
}, },
@ -779,6 +777,7 @@ export default {
'cacheEmojis', 'cacheEmojis',
'readReqNum', 'readReqNum',
'readReqLoad',
'keyboardType', 'keyboardType',
'keyboardHeight', 'keyboardHeight',
'safeAreaBottom' 'safeAreaBottom'
@ -1089,27 +1088,24 @@ export default {
if (dialog_id) { if (dialog_id) {
this.msgNew = 0 this.msgNew = 0
this.msgType = '' this.msgType = ''
this.searchShow = false
this.unreadMsgId = 0 this.unreadMsgId = 0
this.searchShow = false
this.positionShow = false this.positionShow = false
this.firstMsgLength = this.allMsgList.length || 1
this.listPreparedStatus = false this.listPreparedStatus = false
this.scrollToBottomAndRefresh = false this.scrollToBottomAndRefresh = false
this.firstMsgLength = Math.min(this.keeps, this.allMsgList.length || 1)
this.allMsgs = this.allMsgList
// //
if (this.firstMsgLength > 0) {
this.allMsgs = this.allMsgList
requestAnimationFrame(this.onToBottom)
}
this.getMsgs({ this.getMsgs({
dialog_id, dialog_id,
msg_id: this.msgId, msg_id: this.msgId,
msg_type: this.msgType, msg_type: this.msgType,
}).then(_ => { }).then(_ => {
this.openId = dialog_id; this.openId = dialog_id
setTimeout(this.onSearchMsgId, 100) this.positionShow = this.readReqLoad === 0
}).catch(_ => {}).finally(_ => {
this.listPreparedStatus = true this.listPreparedStatus = true
}); setTimeout(this.onSearchMsgId, 100)
}).catch(_ => {});
// //
this.$store.dispatch('saveInDialog', { this.$store.dispatch('saveInDialog', {
uid: this._uid, uid: this._uid,
@ -1145,11 +1141,20 @@ export default {
return return
} }
this.$nextTick(_ => { this.$nextTick(_ => {
if (!this.$refs.footer && this.footerObserver) { if (this.$refs.footer) {
return if (!this.observers.find(({key}) => key === 'footer')) {
const footerObserver = new ResizeObserver(this.onResizeEvent)
footerObserver.observe(this.$refs.footer);
this.observers.push({key: 'footer', observer: footerObserver})
}
}
if (this.$refs.scroller) {
if (!this.observers.find(({key}) => key === 'scroller')) {
const scrollerObserver = new ResizeObserver(this.onResizeEvent)
scrollerObserver.observe(this.$refs.scroller.$el);
this.observers.push({key: 'scroller', observer: scrollerObserver})
}
} }
this.footerObserver = new ResizeObserver(this.onResizeEvent)
this.footerObserver.observe(this.$refs.footer);
}) })
}, },
immediate: true immediate: true
@ -1313,15 +1318,6 @@ export default {
} }
}, },
footerPaddingBottom(val) {
if (val) {
const {tail} = this.scrollInfo();
if (tail <= 55) {
requestAnimationFrame(this.onToBottom)
}
}
},
positionMsg() { positionMsg() {
const {unread, position_msgs} = this.dialogData const {unread, position_msgs} = this.dialogData
if (!$A.isArray(position_msgs) || unread < 2) { if (!$A.isArray(position_msgs) || unread < 2) {
@ -1333,16 +1329,6 @@ export default {
} }
}, },
tagShow(val) {
if (!this.isFirstShowTag && val) {
this.isFirstShowTag = true
const {tail} = this.scrollInfo();
if (tail <= 55) {
requestAnimationFrame(this.onToBottom)
}
}
},
readReqNum() { readReqNum() {
this.positionShow = true this.positionShow = true
}, },
@ -2036,6 +2022,8 @@ export default {
entries.some(({target}) => { entries.some(({target}) => {
if (target === this.$refs.footer) { if (target === this.$refs.footer) {
this.onFooterResize() this.onFooterResize()
} else if (target === this.$refs.scroller?.$el) {
this.onScrollerResize()
} }
}) })
}, },
@ -2051,6 +2039,16 @@ export default {
} }
}, },
onScrollerResize() {
if (!this.$refs.scroller) {
return
}
const {tail} = this.scrollInfo();
if (tail <= 55) {
requestAnimationFrame(this.onToBottom)
}
},
onActive() { onActive() {
this.$emit("on-active"); this.$emit("on-active");
}, },
@ -2467,9 +2465,6 @@ export default {
this.scrollAction = event.target.scrollTop; this.scrollAction = event.target.scrollTop;
this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up'; this.scrollDirection = this.scrollTmp <= this.scrollAction ? 'down' : 'up';
setTimeout(_ => this.scrollTmp = this.scrollAction, 0); setTimeout(_ => this.scrollTmp = this.scrollAction, 0);
//
this.scrollIng++;
setTimeout(_=> this.scrollIng--, 100);
}, },
onRange(range) { onRange(range) {
@ -2689,12 +2684,8 @@ export default {
}, },
onReply(type) { onReply(type) {
const {tail} = this.scrollInfo()
this.setQuote(this.operateItem.id, type) this.setQuote(this.operateItem.id, type)
this.inputFocus() this.inputFocus()
if (tail <= 55) {
requestAnimationFrame(this.onToBottom)
}
}, },
onUpdate() { onUpdate() {

View File

@ -3005,6 +3005,7 @@ export default {
return return
} }
// //
state.readReqLoad++
dispatch("call", { dispatch("call", {
url: 'dialog/msg/read', url: 'dialog/msg/read',
data: { data: {
@ -3017,6 +3018,7 @@ export default {
state.readWaitData[id] = id; state.readWaitData[id] = id;
}) })
}).finally(_ => { }).finally(_ => {
state.readReqLoad--
state.readReqNum++ state.readReqNum++
}); });
}, 50); }, 50);

View File

@ -124,6 +124,7 @@ export default {
messengerSearchKey: {dialog: '', contacts: ''}, messengerSearchKey: {dialog: '', contacts: ''},
// 阅读消息 // 阅读消息
readReqLoad: 0,
readReqNum: 0, readReqNum: 0,
readTimeout: null, readTimeout: null,
readWaitData: {}, readWaitData: {},

View File

@ -1449,7 +1449,7 @@
opacity: 0; opacity: 0;
transform: translateX(100%); transform: translateX(100%);
animation: position-in-animation 200ms ease-out forwards; animation: position-in-animation 200ms ease-out forwards;
animation-delay: 100ms; animation-delay: 300ms;
.position-label { .position-label {
display: flex; display: flex;