fix(components): 修复wang-editor样式和聚焦问题
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onBeforeUnmount, shallowRef, watch } from 'vue';
|
import { nextTick, onBeforeUnmount, shallowRef, watch } from 'vue';
|
||||||
import '@wangeditor-next/editor/dist/css/style.css';
|
import '@wangeditor-next/editor/dist/css/style.css';
|
||||||
import { Editor, Toolbar } from '@wangeditor-next/editor-for-vue';
|
import { Editor, Toolbar } from '@wangeditor-next/editor-for-vue';
|
||||||
import { i18nChangeLanguage } from '@wangeditor-next/editor';
|
import { i18nChangeLanguage } from '@wangeditor-next/editor';
|
||||||
@@ -12,6 +12,10 @@ defineOptions({
|
|||||||
name: 'WangEditor'
|
name: 'WangEditor'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
visible?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
|
|
||||||
const editorRef = shallowRef<IDomEditor>();
|
const editorRef = shallowRef<IDomEditor>();
|
||||||
@@ -58,39 +62,51 @@ const handleCreated = (editor: IDomEditor) => {
|
|||||||
editorRef.value = editor;
|
editorRef.value = editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch([() => appStore.locale, () => props.visible], ([locale, show]) => {
|
||||||
() => appStore.locale,
|
const localeMap = {
|
||||||
() => {
|
'zh-CN': 'zh-CN',
|
||||||
const localeMap = {
|
'en-US': 'en'
|
||||||
'zh-CN': 'zh-CN',
|
};
|
||||||
'en-US': 'en'
|
|
||||||
};
|
i18nChangeLanguage(localeMap[locale]);
|
||||||
i18nChangeLanguage(localeMap[appStore.locale]);
|
|
||||||
}
|
if (!show) return;
|
||||||
);
|
nextTick(() => {
|
||||||
|
editorRef.value?.focus(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
const editor = editorRef.value;
|
const editor = editorRef.value;
|
||||||
if (editor === null) return;
|
if (!editor) return;
|
||||||
|
|
||||||
editorRef.value?.destroy();
|
editorRef.value?.destroy();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NCard size="small" class="size-full min-h-500px" content-class="size-full">
|
<NCard size="small" class="wang-editor size-full min-h-500px" content-class="size-full">
|
||||||
<Toolbar :editor="editorRef" :default-config="toolbarConfig" class="border-b-1px border-gray-200" />
|
<Toolbar :editor="editorRef" :default-config="toolbarConfig" class="border-b-1px border-gray-200" />
|
||||||
<Editor v-model="value" :default-config="editorConfig" @on-created="handleCreated" />
|
<Editor v-model="value" :default-config="editorConfig" @on-created="handleCreated" />
|
||||||
</NCard>
|
</NCard>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style lang="scss">
|
||||||
:deep(.w-e-toolbar) {
|
html.dark .wang-editor {
|
||||||
background: inherit !important;
|
/* 编辑区 */
|
||||||
border-color: #999 !important;
|
--w-e-textarea-bg-color: #1e1e1e;
|
||||||
|
--w-e-textarea-color: #c8c8c8;
|
||||||
|
--w-e-textarea-border-color: #4d4d4d;
|
||||||
|
|
||||||
|
/* 工具栏 */
|
||||||
|
--w-e-toolbar-bg-color: #2c2c2c;
|
||||||
|
--w-e-toolbar-color: #999;
|
||||||
|
--w-e-toolbar-active-color: #d4d4d4;
|
||||||
|
--w-e-toolbar-active-bg-color: #3a3a3a;
|
||||||
|
--w-e-toolbar-border-color: #3d3d3d;
|
||||||
}
|
}
|
||||||
:deep(.w-e-text-container) {
|
|
||||||
background: inherit;
|
.w-e-select-list {
|
||||||
border-color: #999 !important;
|
@include scrollbar();
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ watch(visible, () => {
|
|||||||
</NFormItem>
|
</NFormItem>
|
||||||
</div>
|
</div>
|
||||||
<NFormItem :show-label="false" path="noticeContent">
|
<NFormItem :show-label="false" path="noticeContent">
|
||||||
<WangEditor v-model:value="model.noticeContent!" />
|
<WangEditor v-model:value="model.noticeContent!" :visible="visible" />
|
||||||
</NFormItem>
|
</NFormItem>
|
||||||
</NForm>
|
</NForm>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user