From 0f66f0f015892c3afc58ffe3239315815256f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E4=BB=99=E9=83=BD=E6=B2=A1=E7=94=A8?= <615206459@qq.com> Date: Tue, 27 Feb 2024 15:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20editor-preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor-preview/components/preview.vue | 27 ++++++++++--------- src/plugins/editor-preview/config.ts | 4 +-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/plugins/editor-preview/components/preview.vue b/src/plugins/editor-preview/components/preview.vue index a006346..92abca0 100644 --- a/src/plugins/editor-preview/components/preview.vue +++ b/src/plugins/editor-preview/components/preview.vue @@ -50,9 +50,8 @@ import { useClipboard } from "@vueuse/core"; import { ElMessage } from "element-plus"; import { isObject, isString } from "lodash-es"; -import { nextTick, type PropType, ref, computed } from "vue"; +import { nextTick, ref, computed, type PropType } from "vue"; import { useCool } from "/@/cool"; -import "@wangeditor/editor/dist/css/style.css"; interface TabItem { name: string; @@ -64,7 +63,7 @@ const props = defineProps({ modelValue: String, title: String, name: { - type: String as PropType<"monaco" | "wang">, + type: String, required: true }, text: { @@ -109,20 +108,16 @@ const active = ref(0); // 列表 const list = ref([]); -// 标题 -const title = computed(() => { - return props.title || (props.name == "monaco" ? "代码预览" : "文本预览"); +// 是否代码预览 +const isCode = computed(() => { + return props.name == "monaco"; }); // 是否可以滚动 -const isScroll = computed(() => { - return props.name == "wang"; -}); +const isScroll = computed(() => !isCode.value); // 是否可以复制 -const isCopy = computed(() => { - return props.name == "monaco"; -}); +const isCopy = computed(() => isCode); // 编辑器配置 const editConfig = computed(() => { @@ -132,6 +127,11 @@ const editConfig = computed(() => { }; }); +// 标题 +const title = computed(() => { + return props.title || (isCode.value ? "代码预览" : "文本预览"); +}); + // 打开 async function open(data?: string | TabItem[]) { if (!data) { @@ -169,7 +169,8 @@ async function onTabChange(index: any) { await nextTick(); - if (props.name == "monaco") { + // 格式化代码 + if (isCode.value) { refs.editor?.formatCode?.(); } } diff --git a/src/plugins/editor-preview/config.ts b/src/plugins/editor-preview/config.ts index c8a4ec3..ce37b67 100644 --- a/src/plugins/editor-preview/config.ts +++ b/src/plugins/editor-preview/config.ts @@ -5,8 +5,8 @@ export default (): ModuleConfig => { label: "编辑器内容预览", description: "基于 monaco、wang 等编辑器的内容预览组件", author: "COOL", - version: "1.0.0", - updateTime: "2024-02-01", + version: "1.0.1", + updateTime: "2024-02-27", demo: [ { name: "基础用法",