feat: 增加添加字段功能,方便用户粘贴赋值字段到对应代码位置

This commit is contained in:
pixelmaxQM
2024-10-17 22:29:52 +08:00
parent f237ac981e
commit efac72ecbb
14 changed files with 1278 additions and 28 deletions

View File

@@ -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])
}
})

View File

@@ -693,6 +693,7 @@
<div class="gva-btn-list justify-end mt-4">
<el-button
type="primary"
:disabled="isAdd"
@click="exportJson()"
>
导出json
@@ -703,32 +704,35 @@
show-file-list="false"
accept=".json"
>
<el-button type="primary" class="mx-2">导入json</el-button>
<el-button type="primary" class="mx-2" :disabled="isAdd">导入json</el-button>
</el-upload>
<el-button
type="primary"
:disabled="isAdd"
@click="clearCatch()"
>
清除暂存
</el-button>
<el-button
type="primary"
:disabled="isAdd"
@click="catchData()"
>
暂存
</el-button>
<el-button
type="primary"
@click="enterForm(true)"
>
预览代码
</el-button>
<el-button
type="primary"
:disabled="isAdd"
@click="enterForm(false)"
>
生成代码
</el-button>
<el-button
type="primary"
@click="enterForm(true)"
>
{{isAdd?'查看代码':'预览代码'}}
</el-button>
</div>
</div>
<!-- 组件弹窗 -->
@@ -790,6 +794,7 @@
</template>
<PreviewCodeDialog
v-if="previewFlag"
:is-add="isAdd"
ref="previewNode"
:preview-code="preViewCode"
/>
@@ -1217,7 +1222,7 @@ const enterForm = async(isPreview) => {
form.value.humpPackageName = toSQLLine(form.value.packageName)
delete form.value.primaryField
if (isPreview) {
const data = await preview(form.value)
const data = await preview({...form.value,isAdd:!!isAdd.value,fields:form.value.fields.filter(item => !item.disabled)})
preViewCode.value = data.data.autoCode
previewFlag.value = true
} else {

View File

@@ -60,6 +60,9 @@
>
增加方法
</el-button>
<el-button type="primary" link @click="goAutoCode(scope.row,1)">
增加字段
</el-button>
<el-button
type="primary"
link
@@ -194,7 +197,7 @@
</el-select>
</el-form-item>
<el-form-item label="是否鉴权:">
<el-switch v-model="autoFunc.isAuth" active-text="是" inactive-text="否" />
<el-switch v-model="autoFunc.isAuth" active-text="是" inactive-text="否" />
</el-form-item>
<el-form-item label="路由path:">
<el-input v-model="autoFunc.router" placeholder="路由path" @input="autoFunc.router = autoFunc.router.replace(/\//g, '')" />
@@ -383,13 +386,16 @@ const enterDialog = async () => {
}
};
const goAutoCode = (row) => {
const goAutoCode = (row,isAdd) => {
if (row) {
router.push({
name: "autoCodeEdit",
params: {
id: row.ID,
},
query: {
isAdd: isAdd
},
});
} else {
router.push({ name: "autoCode" });