From e926edbc5a9c13ffa2c193995d01c4ddc4952349 Mon Sep 17 00:00:00 2001 From: sws <1141121512@qq.com> Date: Fri, 23 Aug 2024 17:14:43 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=9D=E5=AD=98=E6=95=B0=E6=8D=AE=20sws=20?= =?UTF-8?q?2024-08-22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/upload.ts | 2 +- .../common/upload/form-upload-category.vue | 6 +- src/components/common/upload/index.vue | 9 +- src/components/model-rich-text/index.vue | 6 + .../model-rich-text-content.vue | 45 +++++++- src/layout/components/navbar/index.vue | 106 ++++++++++-------- src/layout/index.vue | 26 +++-- src/styles/common.scss | 6 + 8 files changed, 139 insertions(+), 67 deletions(-) diff --git a/src/api/upload.ts b/src/api/upload.ts index 0aa897f1..05a150ee 100644 --- a/src/api/upload.ts +++ b/src/api/upload.ts @@ -100,7 +100,7 @@ export interface Tree { /** 路径 */ path: string; /** 是否开启 */ - is_enable: Number; + is_enable: number | string; /** 排序 */ sort: number; /** 下级 */ diff --git a/src/components/common/upload/form-upload-category.vue b/src/components/common/upload/form-upload-category.vue index b103f234..7657a22c 100644 --- a/src/components/common/upload/form-upload-category.vue +++ b/src/components/common/upload/form-upload-category.vue @@ -17,7 +17,7 @@ - + @@ -67,7 +67,7 @@ const form = ref({ name: '', path: '', sort: 0, - is_enable: 1, + is_enable: '1', items: [], }); watch( @@ -82,7 +82,7 @@ watch( name: '', path: '', sort: 0, - is_enable: 1, + is_enable: '1', items: [], }; } diff --git a/src/components/common/upload/index.vue b/src/components/common/upload/index.vue index 821bd7c0..2f5e7289 100644 --- a/src/components/common/upload/index.vue +++ b/src/components/common/upload/index.vue @@ -252,8 +252,13 @@ watch( () => dialog_visible.value, (val) => { if (val) { - get_tree(); - get_attachment_list(); + if (val === true) { + upload_type.value = props.type; + // 获取分类 + get_tree(); + // 获取附件列表 + get_attachment_list(); + } } } ); diff --git a/src/components/model-rich-text/index.vue b/src/components/model-rich-text/index.vue index 72450087..b7fb7bf1 100644 --- a/src/components/model-rich-text/index.vue +++ b/src/components/model-rich-text/index.vue @@ -32,5 +32,11 @@ const safe_conten = computed(() => DOMPurify.sanitize(content.value)); .rich-text-content { white-space: normal; word-break: break-all; + img { + max-width: 100%; + } + video { + max-width: 100%; + } } diff --git a/src/components/model-rich-text/model-rich-text-content.vue b/src/components/model-rich-text/model-rich-text-content.vue index 2afa6b42..1c114f48 100644 --- a/src/components/model-rich-text/model-rich-text-content.vue +++ b/src/components/model-rich-text/model-rich-text-content.vue @@ -2,13 +2,13 @@
展示设置
-
+
- +
@@ -18,7 +18,7 @@ import { Editor, Toolbar } from '@wangeditor/editor-for-vue'; const props = defineProps({ value: { type: Object, - default: () => ({ html: '' }), + default: () => ({ html: '

' }), }, }); const form = reactive(props.value); @@ -26,9 +26,15 @@ const form = reactive(props.value); const mode = ref('default'); // 编辑器模式 // 编辑器实例,必须用 shallowRef const editor_ref = shallowRef(); +// 插入光标位置 +const cursor_position = ref(0); const toolbar_config = ref({}); // 工具条配置 +// 上传列表 const upload_list = ref([]); +// 上传弹窗显示 const visibleDialog = ref(false); +// 上传类型 +const rich_upload_type = ref('img'); // 编辑器配置 interface InsertFnType { (url: string, alt?: string, href?: string): void; @@ -36,10 +42,21 @@ interface InsertFnType { const editor_config = ref({ placeholder: '请输入内容...', MENU_CONF: { + // 自定义菜单配置 uploadImage: { // 自定义选择图片 customBrowseAndUpload(insertFn: InsertFnType) { + rich_upload_type.value = 'img'; visibleDialog.value = true; + cursor_position.value = editor_ref.value.selection; + }, + }, + uploadVideo: { + // 自定义上传视频 + customBrowseAndUpload(insertFn: InsertFnType) { + rich_upload_type.value = 'video'; + visibleDialog.value = true; + cursor_position.value = editor_ref.value.selection; }, }, }, @@ -53,16 +70,26 @@ const handle_change = (editor: any) => { form.html = editor.getHtml(); }; const upload_list_change = (arry: uploadList[]) => { - console.log(arry); const editor = editor_ref.value; let new_html = ''; if (editor) { arry.forEach((item: uploadList) => { const url = item.url; const alt = item.title; - new_html += `${alt}`; + if (rich_upload_type.value === 'img') { + new_html += `${alt}`; + } else if (rich_upload_type.value === 'video') { + new_html += `
- - + + +
+ + + + + + + + + + + + + + +
+ +