This commit is contained in:
神仙都没用 2023-10-12 15:28:19 +08:00
parent 4d0e62b850
commit 7c7c98ec58

View File

@ -1,13 +1,16 @@
<template> <template>
<div class="cl-editor-wang" :class="{ disabled }" :ref="setRefs('editor')"> <div class="cl-editor-wang" :class="{ disabled }" :ref="setRefs('editor')">
<!-- 工具栏 --> <!-- 工具栏 -->
<toolbar :editor="Editor" :mode="mode" /> <toolbar :editor="Editor" :mode="mode" v-if="!preview" />
<!-- 编辑框 --> <!-- 编辑框 -->
<editor <editor
v-model="value" v-model="value"
:defaultConfig="editorConfig" :defaultConfig="editorConfig"
:mode="mode" :mode="mode"
:style="{
height: parsePx(height)
}"
@onCreated="onCreated" @onCreated="onCreated"
@onFocus="onFocus" @onFocus="onFocus"
@onBlur="onBlur" @onBlur="onBlur"
@ -58,8 +61,8 @@ export default defineComponent({
type: [String, Number], type: [String, Number],
default: 400 default: 400
}, },
maxHeight: [String, Number], disabled: Boolean,
disabled: Boolean preview: Boolean
}, },
emits: ["update:modelValue", "change", "focus", "blur"], emits: ["update:modelValue", "change", "focus", "blur"],
@ -110,7 +113,6 @@ export default defineComponent({
function onCreated(editor: any) { function onCreated(editor: any) {
Editor.value = editor; Editor.value = editor;
onDisabled(); onDisabled();
onHeight();
} }
// //
@ -144,32 +146,16 @@ export default defineComponent({
} }
} }
//
function onHeight() {
const { style } = refs.editor.querySelector(".w-e-text-container");
style.maxHeight = parsePx(props.maxHeight || "auto");
style.height = parsePx(props.height);
}
// //
function onDisabled() { function onDisabled() {
if (props.disabled) { if (props.disabled || props.preview) {
Editor.value?.disable(); Editor.value?.disable();
} else { } else {
Editor.value?.enable(); Editor.value?.enable();
} }
} }
watch(() => props.disabled, onDisabled); watch(() => [props.disabled, props.preview], onDisabled);
watch(
() => {
return [props.height, props.maxHeight];
},
() => {
onHeight();
}
);
onBeforeUnmount(() => { onBeforeUnmount(() => {
const editor = Editor.value; const editor = Editor.value;
@ -187,7 +173,8 @@ export default defineComponent({
onBlur, onBlur,
onChange, onChange,
editorConfig, editorConfig,
onFileConfirm onFileConfirm,
parsePx
}; };
} }
}); });