准备实现富文本编辑器
This commit is contained in:
parent
ea44620dee
commit
cefa6b2af5
@ -47,11 +47,22 @@ const renderRichText = (items: RichTextItem[]) => {
|
|||||||
|
|
||||||
const handleInput = (event: Event) => {
|
const handleInput = (event: Event) => {
|
||||||
if (editor.value) {
|
if (editor.value) {
|
||||||
console.log(editor.value);
|
|
||||||
|
|
||||||
const items: RichTextItem[] = [];
|
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);
|
emit('update:modelValue', items);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user