From cefa6b2af53ae6bb21291cfa05b8cc12ae532f09 Mon Sep 17 00:00:00 2001 From: Kirigaya <1193466151@qq.com> Date: Wed, 7 May 2025 02:50:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E5=AE=9E=E7=8E=B0=E5=AF=8C?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/k-rich-textarea/index.vue | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/renderer/src/components/k-rich-textarea/index.vue b/renderer/src/components/k-rich-textarea/index.vue index 0918e4c..9a306ab 100644 --- a/renderer/src/components/k-rich-textarea/index.vue +++ b/renderer/src/components/k-rich-textarea/index.vue @@ -47,11 +47,22 @@ const renderRichText = (items: RichTextItem[]) => { const handleInput = (event: Event) => { if (editor.value) { - console.log(editor.value); - const items: RichTextItem[] = []; - // 解析编辑器内容并转换为 RichTextItem[] - // ... 实现解析逻辑 + const nodes = editor.value.childNodes; + nodes.forEach(node => { + if (node.nodeType === Node.TEXT_NODE) { + items.push({ type: 'text', text: node.textContent || '' }); + } else if (node.nodeType === Node.ELEMENT_NODE) { + const element = node as HTMLElement; + if (element.classList.contains('rich-item-prompt')) { + items.push({ type: 'prompt', text: element.textContent || '' }); + } else if (element.classList.contains('rich-item-resource')) { + items.push({ type: 'resource', text: element.textContent || '' }); + } else { + items.push({ type: 'text', text: element.textContent || '' }); + } + } + }); emit('update:modelValue', items); } };