Browse Source

增加自动化生成表单功能,修改自动化生成文件的文件夹名称更加规范化,css样式调整。

main
pixel 4 years ago
parent
commit
2a2bf7f036
  1. 0
      server/resource/template/server/api.go.tpl
  2. 0
      server/resource/template/server/model.go.tpl
  3. 0
      server/resource/template/server/request.go.tpl
  4. 0
      server/resource/template/server/router.go.tpl
  5. 0
      server/resource/template/server/service.go.tpl
  6. 0
      server/resource/template/web/api.js.tpl
  7. 125
      server/resource/template/web/form.vue.tpl
  8. 2
      server/resource/template/web/table.vue.tpl
  9. 2
      server/service/sys_auto_code.go
  10. 6
      web/src/style/main.scss

0
server/resource/template/te/api.go.tpl → server/resource/template/server/api.go.tpl

0
server/resource/template/te/model.go.tpl → server/resource/template/server/model.go.tpl

0
server/resource/template/te/request.go.tpl → server/resource/template/server/request.go.tpl

0
server/resource/template/te/router.go.tpl → server/resource/template/server/router.go.tpl

0
server/resource/template/te/service.go.tpl → server/resource/template/server/service.go.tpl

0
server/resource/template/fe/api.js.tpl → server/resource/template/web/api.js.tpl

125
server/resource/template/web/form.vue.tpl

@ -0,0 +1,125 @@
<template>
<div>
<el-form :model="formData" label-position="right" label-width="80px">
{{- range .Fields}}
<el-form-item label="{{.FieldDesc}}:">
{{- if eq .FieldType "bool" }}
<el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
{{ end -}}
{{- if eq .FieldType "string" }}
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
{{ end -}}
{{- if eq .FieldType "int" }}
{{- if .DictType}}
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
</el-select>
{{ else -}}
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
{{ end -}}
{{ end -}}
{{- if eq .FieldType "time.Time" }}
<el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
{{ end -}}
{{- if eq .FieldType "float64" }}
<el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
{{ end -}}
</el-form-item>
{{ end -}}
<el-form-item>
<el-button @click="save" type="primary">保存</el-button>
<el-button @click="back" type="primary">返回</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import {
create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址
import infoList from "@/mixins/infoList";
export default {
name: "{{.StructName}}",
mixins: [infoList],
data() {
return {
type: "",
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options:[],
{{ end -}}
{{end -}}
formData: {
{{range .Fields}}
{{- if eq .FieldType "bool" -}}
{{.FieldJson}}:false,
{{ end -}}
{{- if eq .FieldType "string" -}}
{{.FieldJson}}:"",
{{ end -}}
{{- if eq .FieldType "int" -}}
{{.FieldJson}}:0,
{{ end -}}
{{- if eq .FieldType "time.Time" -}}
{{.FieldJson}}:new Date(),
{{ end -}}
{{- if eq .FieldType "float64" -}}
{{.FieldJson}}:0,
{{ end -}}
{{ end }}
}
};
},
methods: {
async save() {
let res;
switch (this.type) {
case "create":
res = await create{{.StructName}}(this.formData);
break;
case "update":
res = await update{{.StructName}}(this.formData);
break;
default:
res = await create{{.StructName}}(this.formData);
break;
}
if (res.code == 0) {
this.$message({
type:"success",
message:"创建/更改成功"
})
}
},
back(){
this.$router.go(-1)
}
},
async created() {
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if(this.$route.query.id){
const res = await find{{.StructName}}({ ID: this.$route.query.id })
if(res.code == 0){
this.formData = res.data.re{{.Abbreviation}}
this.type == "update"
}
}else{
this.type == "create"
}
{{ range .Fields -}}
{{- if .DictType }}
await this.getDict("{{.DictType}}");
{{ end -}}
{{- end }}
}
};
</script>
<style>
</style>

2
server/resource/template/fe/table.vue.tpl → server/resource/template/web/table.vue.tpl

@ -149,11 +149,13 @@ export default {
type: "", type: "",
deleteVisible: false, deleteVisible: false,
multipleSelection: [], multipleSelection: [],
{{- range .Fields}} {{- range .Fields}}
{{- if .DictType }} {{- if .DictType }}
{{ .DictType }}Options:[], {{ .DictType }}Options:[],
{{ end -}} {{ end -}}
{{end -}} {{end -}}
formData: { formData: {
{{range .Fields}} {{range .Fields}}
{{- if eq .FieldType "bool" -}} {{- if eq .FieldType "bool" -}}

2
server/service/sys_auto_code.go

@ -46,7 +46,7 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
} }
// 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理 // 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理
// resource/template/fe/api.js.tpl -> autoCode/fe/autoCode.PackageName/api/autoCode.PackageName.js
// resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js
// resource/template/readme.txt.tpl -> autoCode/readme.txt // resource/template/readme.txt.tpl -> autoCode/readme.txt
autoPath := "autoCode/" autoPath := "autoCode/"
for index, value := range dataList { for index, value := range dataList {

6
web/src/style/main.scss

@ -1066,6 +1066,8 @@ $mainHight: 100vh;
.layout-cont { .layout-cont {
.right-box { .right-box {
height: $height-header;
line-height: $height-header;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
margin-right: 40px; margin-right: 40px;
@ -1088,8 +1090,8 @@ $mainHight: 100vh;
padding: 0 24px; padding: 0 24px;
} }
.fl-right { .fl-right {
height: $height-header;
line-height: $height-header;
// height: $height-header;
// line-height: $height-header;
} }
&.el-main { &.el-main {
overflow: auto; overflow: auto;

Loading…
Cancel
Save