mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-09 13:53:38 +08:00
feat: 添加Markdown示例 (#1193)
This commit is contained in:
@@ -17,14 +17,15 @@ const home = 0, // 平台规定只有 home 路由的 rank 才能为 0 ,所以
|
||||
monitor = 14,
|
||||
tabs = 15,
|
||||
about = 16,
|
||||
editor = 17,
|
||||
flowchart = 18,
|
||||
formdesign = 19,
|
||||
board = 20,
|
||||
ppt = 21,
|
||||
mind = 22,
|
||||
guide = 23,
|
||||
menuoverflow = 24;
|
||||
markdown = 17,
|
||||
editor = 18,
|
||||
flowchart = 19,
|
||||
formdesign = 20,
|
||||
board = 21,
|
||||
ppt = 22,
|
||||
mind = 23,
|
||||
guide = 24,
|
||||
menuoverflow = 25;
|
||||
|
||||
export {
|
||||
home,
|
||||
@@ -44,6 +45,7 @@ export {
|
||||
monitor,
|
||||
tabs,
|
||||
about,
|
||||
markdown,
|
||||
editor,
|
||||
flowchart,
|
||||
formdesign,
|
||||
|
||||
@@ -15,8 +15,7 @@ export default {
|
||||
name: "MqttClient",
|
||||
component: () => import("@/views/able/mqtt-client.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureMqtt"),
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
title: $t("menus.pureMqtt")
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -15,8 +15,7 @@ export default {
|
||||
name: "SchemaForm",
|
||||
component: () => import("@/views/schema-form/index.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureSchemaForm"),
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
title: $t("menus.pureSchemaForm")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -15,8 +15,7 @@ export default {
|
||||
name: "Ganttastic",
|
||||
component: () => import("@/views/ganttastic/index.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureGanttastic"),
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
title: $t("menus.pureGanttastic")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
23
src/router/modules/markdown.ts
Normal file
23
src/router/modules/markdown.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { $t } from "@/plugins/i18n";
|
||||
import { markdown } from "@/router/enums";
|
||||
|
||||
export default {
|
||||
path: "/markdown",
|
||||
redirect: "/markdown/index",
|
||||
meta: {
|
||||
icon: "ri:markdown-line",
|
||||
title: $t("menus.pureMarkdown"),
|
||||
rank: markdown
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/markdown/index",
|
||||
name: "Markdown",
|
||||
component: () => import("@/views/markdown/index.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureMarkdown"),
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
}
|
||||
}
|
||||
]
|
||||
} satisfies RouteConfigsTable;
|
||||
@@ -31,8 +31,7 @@ export default {
|
||||
name: "PureTableEdit",
|
||||
component: () => import("@/views/table/edit.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureTableEdit"),
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
title: $t("menus.pureTableEdit")
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -40,8 +39,7 @@ export default {
|
||||
name: "VxeTable",
|
||||
component: () => import("@/views/table/virtual.vue"),
|
||||
meta: {
|
||||
title: $t("menus.pureVxeTable"),
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
title: $t("menus.pureVxeTable")
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -14,8 +14,7 @@ export default {
|
||||
name: "VueFlow",
|
||||
component: () => import("@/views/vue-flow/layouting/index.vue"),
|
||||
meta: {
|
||||
title: "vue-flow",
|
||||
extraIcon: "IF-pure-iconfont-new svg"
|
||||
title: "vue-flow"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
105
src/views/markdown/components/Vditor.vue
Normal file
105
src/views/markdown/components/Vditor.vue
Normal file
@@ -0,0 +1,105 @@
|
||||
<script setup lang="ts">
|
||||
import "vditor/dist/index.css";
|
||||
import Vditor from "vditor";
|
||||
import { useDark } from "@pureadmin/utils";
|
||||
import { useIntervalFn } from "@vueuse/core";
|
||||
import { onMounted, ref, watch, toRaw, onUnmounted } from "vue";
|
||||
|
||||
const emit = defineEmits([
|
||||
"update:modelValue",
|
||||
"after",
|
||||
"focus",
|
||||
"blur",
|
||||
"esc",
|
||||
"ctrlEnter",
|
||||
"select"
|
||||
]);
|
||||
|
||||
const props = defineProps({
|
||||
options: {
|
||||
type: Object,
|
||||
default() {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: ""
|
||||
}
|
||||
});
|
||||
|
||||
const { isDark } = useDark();
|
||||
const editor = ref<Vditor | null>(null);
|
||||
const markdownRef = ref<HTMLElement | null>(null);
|
||||
|
||||
onMounted(() => {
|
||||
editor.value = new Vditor(markdownRef.value as HTMLElement, {
|
||||
...props.options,
|
||||
value: props.modelValue,
|
||||
cache: {
|
||||
enable: false
|
||||
},
|
||||
fullscreen: {
|
||||
index: 10000
|
||||
},
|
||||
after() {
|
||||
emit("after", toRaw(editor.value));
|
||||
},
|
||||
input(value: string) {
|
||||
emit("update:modelValue", value);
|
||||
},
|
||||
focus(value: string) {
|
||||
emit("focus", value);
|
||||
},
|
||||
blur(value: string) {
|
||||
emit("blur", value);
|
||||
},
|
||||
esc(value: string) {
|
||||
emit("esc", value);
|
||||
},
|
||||
ctrlEnter(value: string) {
|
||||
emit("ctrlEnter", value);
|
||||
},
|
||||
select(value: string) {
|
||||
emit("select", value);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
newVal => {
|
||||
if (newVal !== editor.value?.getValue()) {
|
||||
editor.value?.setValue(newVal);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => isDark.value,
|
||||
newVal => {
|
||||
const { pause } = useIntervalFn(() => {
|
||||
if (editor.value.vditor) {
|
||||
newVal
|
||||
? editor.value.setTheme("dark", "dark", "rose-pine")
|
||||
: editor.value.setTheme("classic", "light", "github");
|
||||
pause();
|
||||
}
|
||||
}, 20);
|
||||
}
|
||||
);
|
||||
|
||||
onUnmounted(() => {
|
||||
const editorInstance = editor.value;
|
||||
if (!editorInstance) return;
|
||||
try {
|
||||
editorInstance?.destroy?.();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="markdownRef" />
|
||||
</template>
|
||||
59
src/views/markdown/index.vue
Normal file
59
src/views/markdown/index.vue
Normal file
@@ -0,0 +1,59 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import Vditor from "./components/Vditor.vue";
|
||||
|
||||
defineOptions({
|
||||
name: "Markdown"
|
||||
});
|
||||
|
||||
const text = ref(`
|
||||
\`\`\`ts
|
||||
function sayHello(): void {
|
||||
\tconsole.log("Hello, World!");
|
||||
}
|
||||
sayHello();
|
||||
\`\`\`
|
||||
# 一级标题
|
||||
## 二级标题
|
||||
### 三级标题
|
||||
#### 四级标题
|
||||
##### 五级标题
|
||||
###### 六级标题
|
||||
`);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span class="font-medium">
|
||||
Markdown组件,采用开源的
|
||||
<el-link
|
||||
href="https://b3log.org/vditor/"
|
||||
target="_blank"
|
||||
style="margin: 0 4px 5px; font-size: 16px"
|
||||
>
|
||||
Vditor
|
||||
</el-link>
|
||||
</span>
|
||||
</div>
|
||||
<el-link
|
||||
class="mt-2"
|
||||
href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/markdown"
|
||||
target="_blank"
|
||||
>
|
||||
代码位置 src/views/markdown
|
||||
</el-link>
|
||||
</template>
|
||||
<h1 class="mb-2">
|
||||
双向绑定:<span class="text-red-500">{{ text }}</span>
|
||||
</h1>
|
||||
<Vditor
|
||||
v-model="text"
|
||||
:options="{
|
||||
height: 560, // 高度
|
||||
outline: { enable: true, position: 'right' } // 大纲
|
||||
}"
|
||||
/>
|
||||
</el-card>
|
||||
</template>
|
||||
Reference in New Issue
Block a user