feat: code-view组件
This commit is contained in:
parent
6f5172a2ac
commit
1689a497d0
@ -1,10 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<code-mirror
|
<code-mirror
|
||||||
basic
|
|
||||||
v-model="codeValue"
|
v-model="codeValue"
|
||||||
:extensions="extensions"
|
:extensions="extensions"
|
||||||
:tab-size="config.tabSize"
|
|
||||||
:basic="config.basic"
|
:basic="config.basic"
|
||||||
|
:tab-size="config.tabSize"
|
||||||
:dark="config.dark"
|
:dark="config.dark"
|
||||||
:readonly="config.readonly"
|
:readonly="config.readonly"
|
||||||
/>
|
/>
|
||||||
@ -26,21 +25,25 @@ interface Props {
|
|||||||
// withDefaults为defineProps标注类型
|
// withDefaults为defineProps标注类型
|
||||||
// https://cn.vuejs.org/guide/typescript/composition-api.html#typing-component-props
|
// https://cn.vuejs.org/guide/typescript/composition-api.html#typing-component-props
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
type: "javascript",
|
type: "javascript", // 默认类型
|
||||||
codeJson: ""
|
codeJson: "" // 默认值
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 通过计算属性实现数据实时更新
|
||||||
|
// 将序列化的字符串美观输出,\t 换行
|
||||||
const codeValue = computed(() => JSON.stringify(props.codeJson, null, "\t"));
|
const codeValue = computed(() => JSON.stringify(props.codeJson, null, "\t"));
|
||||||
|
|
||||||
const defaultConfig = {
|
// 基础配置
|
||||||
|
const config = ref({
|
||||||
tabSize: 2,
|
tabSize: 2,
|
||||||
basic: true,
|
basic: true,
|
||||||
dark: true,
|
dark: true,
|
||||||
readonly: true
|
readonly: true
|
||||||
};
|
});
|
||||||
const config = defaultConfig;
|
|
||||||
|
|
||||||
// 扩展
|
// 扩展
|
||||||
|
// 基础扩展:黑暗模式
|
||||||
|
// 根据默认值来判断添加什么扩展
|
||||||
const extensions = computed(() => {
|
const extensions = computed(() => {
|
||||||
const arr = [oneDark];
|
const arr = [oneDark];
|
||||||
if (props.type === "javascript") {
|
if (props.type === "javascript") {
|
||||||
@ -59,6 +62,12 @@ const extensions = computed(() => {
|
|||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
// 修改code中的字体样式
|
// 修改code中的字体样式
|
||||||
:deep(.ͼ1 .cm-scroller) {
|
:deep(.ͼ1 .cm-scroller) {
|
||||||
font-family: source-code-pro, Menlo, Monaco, Consolas, Courier New, monospace;
|
font-family:
|
||||||
|
source-code-pro,
|
||||||
|
Menlo,
|
||||||
|
Monaco,
|
||||||
|
Consolas,
|
||||||
|
Courier New,
|
||||||
|
monospace;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>动态表单</div>
|
<div class="dc-page">动态表单</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts"></script>
|
<script setup lang="ts"></script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user