This commit is contained in:
XiaLangQing 2024-10-15 08:42:08 +08:00
commit 2e2cd6d8a7
8 changed files with 253 additions and 1 deletions

View File

@ -220,7 +220,7 @@
"commentTranslate.multiLineMerge": true,
"vue.server.hybridMode": true,
"vitest.disableWorkspaceWarning": true,
"cSpell.words": ["tinymce"],
"cSpell.words": ["tinymce", "vditor"],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.linkedEditing": true, // html,
"vscodeCustomCodeColor.highlightValue": "v-access", // v-access

View File

@ -6,6 +6,7 @@
- 全局表格加上id 方便进行缓存列排序的操作
- 支持菜单名称i18n
- 登录页 验证码登录
- Markdown编辑/预览组件(基于vditor)
**BUG FIXES**

View File

@ -0,0 +1,24 @@
<script setup lang="ts">
import { ref } from 'vue';
import { MarkdownPreviewer, Page } from '@vben/common-ui';
import { Skeleton } from 'ant-design-vue';
import changelog from '../../../../../../CHANGELOG.md?raw';
const content = ref(changelog);
const loading = ref(true);
</script>
<template>
<Page :auto-content-height="true">
<Skeleton v-show="loading" active />
<MarkdownPreviewer
v-model:value="content"
height="100%"
@mounted="loading = false"
/>
</Page>
</template>

View File

@ -40,6 +40,7 @@
"@vueuse/integrations": "catalog:",
"codemirror": "^6.0.1",
"qrcode": "catalog:",
"vditor": "^3.10.6",
"vue": "catalog:",
"vue-codemirror6": "^1.3.4",
"vue-json-pretty": "^2.4.0",

View File

@ -2,6 +2,7 @@ export * from './captcha';
export * from './code-mirror';
export * from './ellipsis-text';
export * from './json-preview';
export * from './markdown';
export * from './page';
export * from '@vben-core/form-ui';
export * from '@vben-core/popup-ui';

View File

@ -0,0 +1,129 @@
<script setup lang="ts">
import {
onBeforeUnmount,
onMounted,
type PropType,
shallowRef,
useTemplateRef,
watch,
} from 'vue';
import { usePreferences } from '@vben/preferences';
import Vditor from 'vditor';
import 'vditor/dist/index.css';
const props = defineProps({
//
height: {
// stringnumber
type: [String, Number],
default: 500,
},
/**
* 编辑模式默认值: 'wysiwyg'
* wysiwyg: 所见即所得
* ir: 即时渲染
* sv: 分屏预览
*/
mode: {
type: String as PropType<'ir' | 'sv' | 'wysiwyg'>,
default: 'wysiwyg',
},
// ID 使
id: {
type: String,
required: false,
default: '',
validator(value, props) {
if (!value && props.enableCache) {
console.warn('The id is required when enableCache is true');
return false;
}
return true;
},
},
enableCache: {
type: Boolean,
default: false,
},
//
disabled: {
type: Boolean,
default: false,
},
//
options: {
type: Object as PropType<IOptions>,
default: () => ({}),
},
});
const emit = defineEmits<{
// cdn
mounted: [];
}>();
//
const vditorRef = useTemplateRef('vditorRef');
//
const vditorInstance = shallowRef<null | Vditor>(null);
// x
const { isDark, locale } = usePreferences();
watch(isDark, (dark) => {
const theme = dark ? 'dark' : 'light';
vditorInstance.value?.setTheme(dark ? 'dark' : 'classic', theme, theme);
});
//
const content = defineModel('value', {
type: String,
default: '',
});
//
function changeDisabled(disabled: boolean) {
if (disabled) {
vditorInstance.value?.disabled();
} else {
vditorInstance.value?.enable();
}
}
watch(() => props.disabled, changeDisabled);
onMounted(() => {
vditorInstance.value = new Vditor(vditorRef.value!, {
mode: props.mode,
value: content.value,
height: props.height,
lang: locale.value.replace('-', '_') as any,
cache: {
enable: props.enableCache,
id: props.id,
},
theme: isDark.value ? 'dark' : 'classic',
//
input(value) {
content.value = value;
},
//
after() {
//
changeDisabled(props.disabled);
emit('mounted');
},
...props.options,
});
});
onBeforeUnmount(() => {
vditorInstance.value?.destroy();
vditorInstance.value = null;
});
</script>
<template>
<div ref="vditorRef"></div>
</template>

View File

@ -0,0 +1,2 @@
export { default as MarkdownEditor } from './editor.vue';
export { default as MarkdownPreviewer } from './preview.vue';

View File

@ -0,0 +1,94 @@
<script setup lang="ts">
import {
onBeforeUnmount,
onMounted,
type PropType,
shallowRef,
useTemplateRef,
watch,
} from 'vue';
import { usePreferences } from '@vben/preferences';
import Vditor from 'vditor';
import 'vditor/dist/index.css';
const props = defineProps({
//
height: {
// stringnumber
type: [String, Number],
default: 500,
},
//
options: {
type: Object as PropType<IOptions>,
default: () => ({}),
},
});
const emit = defineEmits<{
// cdn
mounted: [];
}>();
//
const vditorRef = useTemplateRef('vditorRef');
//
const vditorInstance = shallowRef<null | Vditor>(null);
// x
const { isDark, locale } = usePreferences();
watch(isDark, (dark) => {
const theme = dark ? 'dark' : 'light';
vditorInstance.value?.setTheme(dark ? 'dark' : 'classic', theme, theme);
});
//
const content = defineModel('value', {
type: String,
default: '',
});
onMounted(() => {
vditorInstance.value = new Vditor(vditorRef.value!, {
value: content.value,
height: props.height,
lang: locale.value.replace('-', '_') as any,
cache: {
enable: false,
},
theme: isDark.value ? 'dark' : 'classic',
// ()
toolbar: [],
//
input(value) {
content.value = value;
},
//
after() {
emit('mounted');
//
vditorInstance.value?.disabled();
},
...props.options,
});
});
onBeforeUnmount(() => {
vditorInstance.value?.destroy();
vditorInstance.value = null;
});
</script>
<template>
<div ref="vditorRef"></div>
</template>
<style>
.vditor-ir pre.vditor-reset[contenteditable='false'] {
cursor: unset;
opacity: 1;
}
</style>