From 1dd4e8da71c84922730a1d7e9146cca41d25dcde Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 1 Mar 2025 11:19:50 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E8=87=AA=E5=8A=A8@=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/components/ChatInput/index.vue | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 5da4e582c..3f08aaec2 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -633,6 +633,10 @@ export default { this.loadInputDraft() }, + quoteData() { + this.quoteChanged = true + }, + showMenu(val) { if (val) { // this.showMenu = false; @@ -1460,15 +1464,23 @@ export default { this.$emit('input', '') } else if (this.quoteData) { // 取消回复 - if (this.$refs.editor.firstChild.querySelectorAll('img').length === 0) { - const quoteDiv = document.createElement('div') - quoteDiv.innerHTML = this.$refs.editor.firstChild.innerHTML - quoteDiv.querySelectorAll("span.mention").forEach(span => { - if (span.getAttribute("data-id") == this.quoteData.userid) { - span.innerHTML = ""; + const {firstChild} = this.$refs.editor; + if (firstChild && firstChild.querySelectorAll('img').length === 0) { + const mentions = firstChild.querySelectorAll("span.mention"); + if (mentions.length === 1) { + const element = mentions[0]; + if (element.getAttribute("data-id") == this.quoteData.userid) { + const parent = element.parentNode; + parent.normalize(); + const nodes = Array.from(parent.childNodes).filter(node => { + return node.nodeType !== Node.TEXT_NODE || !/^\s*$/.test(node.textContent); + }) + if (nodes.length === 1) { + element.remove(); + } } - }) - if (!quoteDiv.innerText.replace(/\s/g, '')) { + } + if (!firstChild.innerText.replace(/\s/g, '')) { this.$emit('input', '') } } @@ -1476,26 +1488,31 @@ export default { this.setQuote(0) }, - onQuoteUserResult(data) { - if (this.dialogData.type !== 'group') { + onQuoteUserResult(userData) { + if (!this.quoteChanged) { return } - if (this.quoteUpdate || !this.quoteData || !this.replyMsgAutoMention) { + this.quoteChanged = false + // 基本判断 + if ( + this.dialogData.type !== 'group' || // 非群聊 + this.quoteUpdate || // 修改消息 + !this.quoteData || // 无引用消息 + !this.replyMsgAutoMention || // 不自动@ + this.userId === userData.userid || // 自己 + this.quoteData.userid !== userData.userid // 不同人 + ) { return } - if (data.bot && !$A.rightExists(data.email, '@bot.system')) { - return - } - if (this.userId === data.userid || this.quoteData.userid !== data.userid) { - return - } - if (new RegExp(`]+?class="mention"[^>]+?data-id="${data.userid}"[^>]*?>`).test(this.$refs.editor.firstChild.innerHTML)) { + // 判断是否已经@过 + if (new RegExp(`]+?class="mention"[^>]+?data-id="${userData.userid}"[^>]*?>`).test(this.$refs.editor.firstChild?.innerHTML)) { return } + // 添加@ this.addMention({ denotationChar: "@", - id: data.userid, - value: data.nickname, + id: userData.userid, + value: userData.nickname, }) },