This commit is contained in:
zpc 2026-02-04 01:51:19 +08:00
parent 63a69bc215
commit 735a4947ef

View File

@ -157,6 +157,61 @@ const formRules: FormRules = {
]
}
// HTML
const cleanHtmlContent = (html: string): string => {
if (!html) return ''
// style style=";font-family:"
let cleaned = html.replace(/style=";/g, 'style="')
// style
cleaned = cleaned.replace(/style=""/g, '')
//
cleaned = cleaned.replace(/;;+/g, ';')
// style
cleaned = cleaned.replace(/style=";\s*/g, 'style="')
return cleaned
}
//
const safeSetEditorContent = (editor: IDomEditor, content: string) => {
if (!editor || editor.isDestroyed) return
try {
// HTML
const cleanedContent = cleanHtmlContent(content)
//
editor.clear()
// 使 setTimeout clear
setTimeout(() => {
if (!editor.isDestroyed) {
try {
editor.setHtml(cleanedContent)
} catch (e) {
console.error('[DanyeFormDialog] Error setting HTML content:', e)
//
try {
//
const tempDiv = document.createElement('div')
tempDiv.innerHTML = cleanedContent
const textContent = tempDiv.textContent || tempDiv.innerText || ''
editor.insertText(textContent)
} catch (e2) {
console.error('[DanyeFormDialog] Error setting text content:', e2)
}
}
}
}, 50)
} catch (e) {
console.error('[DanyeFormDialog] Error in safeSetEditorContent:', e)
}
}
//
const handleCreated = (editor: IDomEditor) => {
console.log('[DanyeFormDialog] handleCreated called, editor:', editor)
@ -164,17 +219,9 @@ const handleCreated = (editor: IDomEditor) => {
editorRef.value = editor
//
// 使 nextTick
if (formData.content) {
console.log('[DanyeFormDialog] Setting initial content to editor:', formData.content.substring(0, 100))
// operations
editor.clear()
// 使 setTimeout clear
setTimeout(() => {
if (!editor.isDestroyed) {
editor.setHtml(formData.content)
}
}, 0)
safeSetEditorContent(editor, formData.content)
}
}
@ -190,12 +237,7 @@ watch(() => props.modelValue, (visible) => {
//
if (editorRef.value && !editorRef.value.isDestroyed) {
editorRef.value.clear()
setTimeout(() => {
if (editorRef.value && !editorRef.value.isDestroyed) {
editorRef.value.setHtml(formData.content)
}
}, 0)
safeSetEditorContent(editorRef.value, formData.content)
}
}
})