fix: 任务首次聊天发表情失败的情况

This commit is contained in:
kuaifan 2024-11-21 21:02:36 +08:00
parent 51efb07c17
commit bf4c4df939
4 changed files with 31 additions and 13 deletions

View File

@ -600,6 +600,17 @@ import {convertLocalResourcePath} from "../components/Replace/utils";
return 0; return 0;
}, },
/**
* 去除html内容中无效的部分
* @param content
* @returns {string}
*/
filterInvalidLine(content) {
return `${content}`
.replace(/^(<p>\s*<\/p>)+|(<p>\s*<\/p>)+$/gi, '')
.replace(/^(<p><br\/*><\/p>)+|(<p><br\/*><\/p>)+$/gi, '')
},
/** /**
* 加载 VConsole 日志组件 * 加载 VConsole 日志组件
* @param key * @param key

View File

@ -521,7 +521,7 @@ export default {
}, },
sendClass() { sendClass() {
if (this.filterInvalidLine(this.value)) { if ($A.filterInvalidLine(this.value)) {
return 'sender'; return 'sender';
} }
if (this.recordReady) { if (this.recordReady) {
@ -590,7 +590,7 @@ export default {
} }
} }
if (!this.simpleMode) { if (!this.simpleMode) {
this.$store.dispatch("saveDialogDraft", {id: this.dialogId, extra_draft_content: this.filterInvalidLine(val)}) this.$store.dispatch("saveDialogDraft", {id: this.dialogId, extra_draft_content: val})
} }
}, },
@ -1157,7 +1157,7 @@ export default {
this.emojiQuickShow = false; this.emojiQuickShow = false;
// //
setTimeout(_ => { setTimeout(_ => {
if (this.filterInvalidLine(this.value) === '') { if ($A.filterInvalidLine(this.value) === '') {
return return
} }
this.hidePopover('send') this.hidePopover('send')
@ -1270,12 +1270,11 @@ export default {
onEmojiQuick(item) { onEmojiQuick(item) {
if (item.type === 'online') { if (item.type === 'online') {
this.$emit('input', "")
this.$emit('on-send', `<img src="${item.src}"/>`) this.$emit('on-send', `<img src="${item.src}"/>`)
} else { } else {
this.$emit('input', "")
this.$emit('on-send', `<img class="emoticon" data-asset="${item.asset}" data-name="${item.name}" src="${item.src}"/>`) this.$emit('on-send', `<img class="emoticon" data-asset="${item.asset}" data-name="${item.name}" src="${item.src}"/>`)
} }
this.$emit('input', "")
this.emojiQuickShow = false this.emojiQuickShow = false
this.focus() this.focus()
}, },
@ -1830,11 +1829,6 @@ export default {
} }
}, },
filterInvalidLine(content) {
let value = (content + '').replace(/^(<p>\s*<\/p>)+|(<p>\s*<\/p>)+$/gi, '')
return value.replace(/^(<p><br\/*><\/p>)+|(<p><br\/*><\/p>)+$/gi, '')
},
updateTools() { updateTools() {
if (this.showEmoji) { if (this.showEmoji) {
this.$refs.emoji?.updatePopper() this.$refs.emoji?.updatePopper()

View File

@ -1540,7 +1540,11 @@ export default {
}, },
sendDialogMsg(msgText = null) { sendDialogMsg(msgText = null) {
if (this.msgFile.length > 0) { if (typeof msgText === 'string' && msgText) {
this.autoSaveTextDraft();
this.$refs.dialog.sendMsg(msgText);
} else if (this.msgFile.length > 0) {
this.autoSaveTextDraft();
this.$refs.dialog.sendFileMsg(this.msgFile.map(file => Object.assign(file, { this.$refs.dialog.sendFileMsg(this.msgFile.map(file => Object.assign(file, {
ajaxExtraData: { ajaxExtraData: {
image_attachment: this.imageAttachment ? 1 : 0 image_attachment: this.imageAttachment ? 1 : 0
@ -1548,13 +1552,21 @@ export default {
}))); })));
} else if (this.msgText) { } else if (this.msgText) {
this.$refs.dialog.sendMsg(this.msgText); this.$refs.dialog.sendMsg(this.msgText);
} else if (typeof msgText === 'string' && msgText) {
this.$refs.dialog.sendMsg(msgText);
} }
this.msgFile = []; this.msgFile = [];
this.msgText = ""; this.msgText = "";
}, },
autoSaveTextDraft() {
if (!this.msgText) {
return;
}
this.$store.dispatch("saveDialogDraft", {
id: this.taskDetail.dialog_id,
extra_draft_content: this.msgText
})
},
taskPasteDrag(e, type) { taskPasteDrag(e, type) {
this.dialogDrag = false; this.dialogDrag = false;
if ($A.dataHasFolder(type === 'drag' ? e.dataTransfer : e.clipboardData)) { if ($A.dataHasFolder(type === 'drag' ? e.dataTransfer : e.clipboardData)) {

View File

@ -3044,6 +3044,7 @@ export default {
* @param data {id, extra_draft_content} * @param data {id, extra_draft_content}
*/ */
saveDialogDraft({state, dispatch}, data) { saveDialogDraft({state, dispatch}, data) {
data.extra_draft_content = $A.filterInvalidLine(data.extra_draft_content)
state.dialogDraftTimer[data.id] && clearInterval(state.dialogDraftTimer[data.id]) state.dialogDraftTimer[data.id] && clearInterval(state.dialogDraftTimer[data.id])
state.dialogDraftTimer[data.id] = setTimeout(_ => { state.dialogDraftTimer[data.id] = setTimeout(_ => {
if (state.dialogId != data.id) { if (state.dialogId != data.id) {