feature:自动化代码增加数据源配置功能

This commit is contained in:
pixelmaxQM
2024-04-27 21:35:29 +08:00
parent 6c62d73afb
commit d9a43ea1d6
12 changed files with 207 additions and 59 deletions

View File

@@ -4,6 +4,11 @@
<el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
{{- range .Fields}}
<el-form-item label="{{.FieldDesc}}:" prop="{{.FieldJson}}">
{{- if .CheckDataSource}}
<el-select v-model="formData.{{.FieldJson}}" placeholder="请选择{{.FieldDesc}}" style="width:100%" :clearable="{{.Clearable}}" >
<el-option v-for="(item,key) in dataSource.{{.FieldJson}}" :key="key" :label="item.label" :value="item.value" />
</el-select>
{{- else }}
{{- if eq .FieldType "bool" }}
<el-switch v-model="formData.{{.FieldJson}}" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" clearable ></el-switch>
{{- end }}
@@ -20,14 +25,8 @@
<RichEdit v-model="formData.{{.FieldJson}}"/>
{{- end }}
{{- if eq .FieldType "int" }}
{{- if .DictType }}
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" :clearable="{{.Clearable}}">
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value" />
</el-select>
{{- else }}
<el-input v-model.number="formData.{{ .FieldJson }}" :clearable="{{.Clearable}}" placeholder="请输入" />
{{- end }}
{{- end }}
{{- if eq .FieldType "time.Time" }}
<el-date-picker v-model="formData.{{ .FieldJson }}" type="date" placeholder="选择日期" :clearable="{{.Clearable}}"></el-date-picker>
{{- end }}
@@ -55,6 +54,7 @@
// 此字段为json结构可以前端自行控制展示和数据绑定模式 需绑定json的key为 formData.{{.FieldJson}} 后端会按照json的类型进行存取
{{"{{"}} formData.{{.FieldJson}} {{"}}"}}
{{- end }}
{{- end }}
</el-form-item>
{{- end }}
<el-form-item>
@@ -68,6 +68,9 @@
<script setup>
import {
{{- if .HasDataSource }}
get{{.StructName}}DataSource,
{{- end }}
create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
@@ -153,6 +156,16 @@ const rule = reactive({
const elFormRef = ref()
{{- if .HasDataSource }}
const dataSource = ref([])
const getDataSourceFunc = async()=>{
const res = await get{{.StructName}}DataSource()
if (res.code === 0) {
dataSource.value = res.data
}
}
{{- end }}
// 初始化方法
const init = async () => {
// url传参获取目标数据ID find方法进行查询数据操作 create还是update id作为url参数示例