diff --git a/src/components/editor/TiptapEditor.vue b/src/components/editor/TiptapEditor.vue index 7969b2a..8194aca 100644 --- a/src/components/editor/TiptapEditor.vue +++ b/src/components/editor/TiptapEditor.vue @@ -209,6 +209,9 @@ const editor = useEditor({ }, suggestion: { ...suggestion, + char: '@', + allowSpaces: false, + allowedPrefixes: null, items: ({ query }) => { return suggestion.items({ query, @@ -496,7 +499,36 @@ function tiptapToMessage() { function tiptapToString() { if (!editor.value) return '' - return editor.value.getText() + const json = editor.value.getJSON() + let result = '' + + const processInlines = nodes => { + nodes.forEach(node => { + if (node.type === 'text') { + result += node.text + } else if (node.type === 'mention') { + result += `@${node.attrs.label} ` + } else if (node.type === 'emoji') { + // 关键修改:使用表情的alt文本而不是忽略 + result += node.attrs.alt || '' + } else if (node.type === 'hardBreak') { + result += '\n' + } + }) + } + + if (json.content) { + json.content.forEach(node => { + if (node.type === 'paragraph') { + if (node.content) { + processInlines(node.content) + } + result += '\n' + } + }) + } + + return result.trim() }