feat: 增加添加字段功能,方便用户粘贴赋值字段到对应代码位置
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-tabs v-model="activeName" tab-position="left" class="h-[calc(100vh-110px)]">
|
||||
<el-tab-pane
|
||||
v-for="(item, key) in previewCode"
|
||||
v-for="(item, key) in useCode"
|
||||
:key="key"
|
||||
:label="key"
|
||||
:name="key"
|
||||
@@ -19,11 +19,24 @@ import { Marked } from "marked";
|
||||
import { markedHighlight } from "marked-highlight";
|
||||
import hljs from 'highlight.js'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { onMounted, ref, watchEffect } from 'vue'
|
||||
import {useAppStore} from "@/pinia";
|
||||
|
||||
const appStore = useAppStore()
|
||||
|
||||
const useCode = ref({})
|
||||
|
||||
const createKey = [
|
||||
"enter.go",
|
||||
"gorm_biz.go",
|
||||
"router_biz.go",
|
||||
"api",
|
||||
"router",
|
||||
"initialize",
|
||||
"gen.go",
|
||||
|
||||
]
|
||||
|
||||
onMounted(() => {
|
||||
const isDarkMode = appStore.config.darkMode === 'dark';
|
||||
if (isDarkMode) {
|
||||
@@ -39,6 +52,19 @@ const props = defineProps({
|
||||
default() {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
isAdd: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
watchEffect(() => {
|
||||
for (const key in props.previewCode) {
|
||||
if (props.isAdd && createKey.some(createKeyItem => key.includes(createKeyItem))) {
|
||||
continue;
|
||||
}
|
||||
useCode.value[key] = props.previewCode[key]
|
||||
}
|
||||
})
|
||||
|
||||
@@ -48,7 +74,6 @@ onMounted(() => {
|
||||
markedHighlight({
|
||||
langPrefix: 'hljs language-',
|
||||
highlight(code, lang, info) {
|
||||
console.log(code,lang,info)
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
if (lang === 'vue') {
|
||||
return hljs.highlight(code, { language: 'html' }).value;
|
||||
@@ -57,11 +82,11 @@ onMounted(() => {
|
||||
}
|
||||
})
|
||||
);
|
||||
for (const key in props.previewCode) {
|
||||
for (const key in useCode.value) {
|
||||
if (activeName.value === '') {
|
||||
activeName.value = key
|
||||
}
|
||||
document.getElementById(key).innerHTML = marked.parse(props.previewCode[key])
|
||||
document.getElementById(key).innerHTML = marked.parse(useCode.value[key])
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user