feat: markdown组件(开发中)
This commit is contained in:
parent
86a2539d27
commit
72ae9edd2c
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -220,7 +220,7 @@
|
|||||||
"commentTranslate.multiLineMerge": true,
|
"commentTranslate.multiLineMerge": true,
|
||||||
"vue.server.hybridMode": true,
|
"vue.server.hybridMode": true,
|
||||||
"vitest.disableWorkspaceWarning": true,
|
"vitest.disableWorkspaceWarning": true,
|
||||||
"cSpell.words": ["tinymce"],
|
"cSpell.words": ["tinymce", "vditor"],
|
||||||
"typescript.tsdk": "node_modules/typescript/lib",
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
"editor.linkedEditing": true, // 自动同步更改html标签,
|
"editor.linkedEditing": true, // 自动同步更改html标签,
|
||||||
"vscodeCustomCodeColor.highlightValue": "v-access", // v-access显示的颜色
|
"vscodeCustomCodeColor.highlightValue": "v-access", // v-access显示的颜色
|
||||||
|
15
apps/web-antd/src/views/演示使用自行删除/changelog/index.vue
Normal file
15
apps/web-antd/src/views/演示使用自行删除/changelog/index.vue
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { MarkdownEditor, Page } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import changelog from '../../../../../../CHANGELOG.md?raw';
|
||||||
|
|
||||||
|
const content = ref(changelog);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page :auto-content-height="true">
|
||||||
|
<MarkdownEditor id="changelog" v-model:value="content" height="100%" />
|
||||||
|
</Page>
|
||||||
|
</template>
|
@ -40,6 +40,7 @@
|
|||||||
"@vueuse/integrations": "catalog:",
|
"@vueuse/integrations": "catalog:",
|
||||||
"codemirror": "^6.0.1",
|
"codemirror": "^6.0.1",
|
||||||
"qrcode": "catalog:",
|
"qrcode": "catalog:",
|
||||||
|
"vditor": "^3.10.6",
|
||||||
"vue": "catalog:",
|
"vue": "catalog:",
|
||||||
"vue-codemirror6": "^1.3.4",
|
"vue-codemirror6": "^1.3.4",
|
||||||
"vue-json-pretty": "^2.4.0",
|
"vue-json-pretty": "^2.4.0",
|
||||||
|
@ -2,6 +2,7 @@ export * from './captcha';
|
|||||||
export * from './code-mirror';
|
export * from './code-mirror';
|
||||||
export * from './ellipsis-text';
|
export * from './ellipsis-text';
|
||||||
export * from './json-preview';
|
export * from './json-preview';
|
||||||
|
export * from './markdown';
|
||||||
export * from './page';
|
export * from './page';
|
||||||
export * from '@vben-core/form-ui';
|
export * from '@vben-core/form-ui';
|
||||||
export * from '@vben-core/popup-ui';
|
export * from '@vben-core/popup-ui';
|
||||||
|
@ -0,0 +1,93 @@
|
|||||||
|
<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: {
|
||||||
|
// string或者number类型
|
||||||
|
type: [String, Number],
|
||||||
|
default: 500,
|
||||||
|
},
|
||||||
|
// 编辑器唯一ID 缓存使用
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
enableCache: {
|
||||||
|
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: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
vditorInstance.value = new Vditor(vditorRef.value!, {
|
||||||
|
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() {
|
||||||
|
emit('mounted');
|
||||||
|
},
|
||||||
|
...props.options,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
vditorInstance.value?.destroy();
|
||||||
|
vditorInstance.value = null;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div ref="vditorRef"></div>
|
||||||
|
</template>
|
@ -0,0 +1,2 @@
|
|||||||
|
export { default as MarkdownEditor } from './editor.vue';
|
||||||
|
export { default as MarkdownPreview } from './preview.vue';
|
@ -0,0 +1,92 @@
|
|||||||
|
<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: {
|
||||||
|
type: Number,
|
||||||
|
default: 500,
|
||||||
|
},
|
||||||
|
// 编辑器唯一ID 缓存使用
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
enableCache: {
|
||||||
|
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: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
vditorInstance.value = new Vditor(vditorRef.value!, {
|
||||||
|
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() {
|
||||||
|
emit('mounted');
|
||||||
|
},
|
||||||
|
...props.options,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
vditorInstance.value?.destroy();
|
||||||
|
vditorInstance.value = null;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div ref="vditorRef"></div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user