富文本添加内容显示

v1.0.0
于肖磊 2024-08-23 17:53:11 +08:00
parent 7ce3af502a
commit ca360e7564
1 changed files with 14 additions and 7 deletions

View File

@ -46,6 +46,7 @@ const editor_config = ref({
uploadImage: { uploadImage: {
// //
customBrowseAndUpload(insertFn: InsertFnType) { customBrowseAndUpload(insertFn: InsertFnType) {
upload_insert.value = insertFn;
rich_upload_type.value = 'img'; rich_upload_type.value = 'img';
visibleDialog.value = true; visibleDialog.value = true;
cursor_position.value = editor_ref.value.selection; cursor_position.value = editor_ref.value.selection;
@ -54,6 +55,7 @@ const editor_config = ref({
uploadVideo: { uploadVideo: {
// //
customBrowseAndUpload(insertFn: InsertFnType) { customBrowseAndUpload(insertFn: InsertFnType) {
upload_insert.value = insertFn;
rich_upload_type.value = 'video'; rich_upload_type.value = 'video';
visibleDialog.value = true; visibleDialog.value = true;
cursor_position.value = editor_ref.value.selection; cursor_position.value = editor_ref.value.selection;
@ -61,6 +63,8 @@ const editor_config = ref({
}, },
}, },
}); });
//
const upload_insert = ref<any>(null);
const handle_created = (editor: any) => { const handle_created = (editor: any) => {
editor_ref.value = editor; // editor editor_ref.value = editor; // editor
}; };
@ -76,20 +80,23 @@ const upload_list_change = (arry: uploadList[]) => {
arry.forEach((item: uploadList) => { arry.forEach((item: uploadList) => {
const url = item.url; const url = item.url;
const alt = item.title; const alt = item.title;
if (rich_upload_type.value === 'img') { // if (rich_upload_type.value === 'img') {
new_html += `<img src="${url}" alt="${alt}" />`; // new_html += `<img src="${url}" alt="${alt}" />`;
} else if (rich_upload_type.value === 'video') { // } else if (rich_upload_type.value === 'video') {
new_html += `<video src="${url}" />`; // new_html += `<video src="${url}" />`;
} // }
//
upload_insert.value(url, alt);
}); });
//
upload_insert.value = null;
// //
console.log(editor);
// if (editor.isDisabled()) editor.enable(); // if (editor.isDisabled()) editor.enable();
// if (!editor.isFocused()) editor.focus(); // if (!editor.isFocused()) editor.focus();
// editor.select(cursor_position.value); // editor.select(cursor_position.value);
// // editor.deleteFragment(); // // editor.deleteFragment();
editor.dangerouslyInsertHtml(new_html); // editor.dangerouslyInsertHtml(new_html);
} }
upload_list.value = []; upload_list.value = [];
}; };