mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-02 02:48:13 +00:00
perf: 优化回复消息自动@逻辑
This commit is contained in:
parent
543015a36e
commit
1dd4e8da71
@ -633,6 +633,10 @@ export default {
|
|||||||
this.loadInputDraft()
|
this.loadInputDraft()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
quoteData() {
|
||||||
|
this.quoteChanged = true
|
||||||
|
},
|
||||||
|
|
||||||
showMenu(val) {
|
showMenu(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
// this.showMenu = false;
|
// this.showMenu = false;
|
||||||
@ -1460,15 +1464,23 @@ export default {
|
|||||||
this.$emit('input', '')
|
this.$emit('input', '')
|
||||||
} else if (this.quoteData) {
|
} else if (this.quoteData) {
|
||||||
// 取消回复
|
// 取消回复
|
||||||
if (this.$refs.editor.firstChild.querySelectorAll('img').length === 0) {
|
const {firstChild} = this.$refs.editor;
|
||||||
const quoteDiv = document.createElement('div')
|
if (firstChild && firstChild.querySelectorAll('img').length === 0) {
|
||||||
quoteDiv.innerHTML = this.$refs.editor.firstChild.innerHTML
|
const mentions = firstChild.querySelectorAll("span.mention");
|
||||||
quoteDiv.querySelectorAll("span.mention").forEach(span => {
|
if (mentions.length === 1) {
|
||||||
if (span.getAttribute("data-id") == this.quoteData.userid) {
|
const element = mentions[0];
|
||||||
span.innerHTML = "";
|
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', '')
|
this.$emit('input', '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1476,26 +1488,31 @@ export default {
|
|||||||
this.setQuote(0)
|
this.setQuote(0)
|
||||||
},
|
},
|
||||||
|
|
||||||
onQuoteUserResult(data) {
|
onQuoteUserResult(userData) {
|
||||||
if (this.dialogData.type !== 'group') {
|
if (!this.quoteChanged) {
|
||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
if (data.bot && !$A.rightExists(data.email, '@bot.system')) {
|
// 判断是否已经@过
|
||||||
return
|
if (new RegExp(`<span[^>]+?class="mention"[^>]+?data-id="${userData.userid}"[^>]*?>`).test(this.$refs.editor.firstChild?.innerHTML)) {
|
||||||
}
|
|
||||||
if (this.userId === data.userid || this.quoteData.userid !== data.userid) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (new RegExp(`<span[^>]+?class="mention"[^>]+?data-id="${data.userid}"[^>]*?>`).test(this.$refs.editor.firstChild.innerHTML)) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 添加@
|
||||||
this.addMention({
|
this.addMention({
|
||||||
denotationChar: "@",
|
denotationChar: "@",
|
||||||
id: data.userid,
|
id: userData.userid,
|
||||||
value: data.nickname,
|
value: userData.nickname,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user