Browse Source

修复优化自动代码中对bool类型搜索字段的支持

main
hansonyu183 4 years ago
parent
commit
c821c60984
  1. 27
      server/resource/template/fe/table.vue.tpl
  2. 9
      server/resource/template/te/model.go.tpl
  3. 2
      server/resource/template/te/service.go.tpl

27
server/resource/template/fe/table.vue.tpl

@ -4,11 +4,34 @@
<el-form :inline="true" :model="searchInfo" class="demo-form-inline"> <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
{{- range .Fields}} {{- range .Fields}}
{{- if .FieldSearchType}} {{- if .FieldSearchType}}
{{- if eq .FieldType "bool" }}
<el-form-item label="{{.FieldDesc}}" prop="{{.FieldJson}}">
<el-col :span="8">
<el-select v-model="searchInfo.{{.FieldJson}}" placeholder="请选择">
<el-option
key="true"
label="是"
value="true">
</el-option>
<el-option
key="false"
label="否"
value="false">
</el-option>
<el-option
label=""
value="">
</el-option>
</el-select>
</el-col>
</el-form-item>
{{- else }}
<el-form-item label="{{.FieldDesc}}"> <el-form-item label="{{.FieldDesc}}">
<el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input> <el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
</el-form-item> </el-form-item>
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ end }}
<el-form-item> <el-form-item>
<el-button @click="onSubmit" type="primary">查询</el-button> <el-button @click="onSubmit" type="primary">查询</el-button>
</el-form-item> </el-form-item>
@ -108,6 +131,10 @@ export default {
onSubmit() { onSubmit() {
this.page = 1 this.page = 1
this.pageSize = 10 this.pageSize = 10
{{- range .Fields}} {{- if eq .FieldType "bool" }}
if (this.searchInfo.{{.FieldJson}}==""){
this.searchInfo.{{.FieldJson}}=null
} {{ end }} {{ end }}
this.getTableData() this.getTableData()
}, },
async update{{.StructName}}(row) { async update{{.StructName}}(row) {

9
server/resource/template/te/model.go.tpl

@ -7,6 +7,11 @@ import (
// 如果含有time.Time 请自行import time包 // 如果含有time.Time 请自行import time包
type {{.StructName}} struct { type {{.StructName}} struct {
gorm.Model {{range .Fields}}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"`{{ end }}
gorm.Model {{- range .Fields}}
{{- if eq .FieldType "bool" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"`
{{- else }}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"`
{{- end }} {{- end }}
}
} }

2
server/resource/template/te/service.go.tpl

@ -71,7 +71,7 @@ func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error,
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+ {{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
} }
{{- else if eq .FieldType "bool" }} {{- else if eq .FieldType "bool" }}
if info.{{.FieldName}} != 0 {
if info.{{.FieldName}} != nil {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
} }
{{- else if eq .FieldType "int" }} {{- else if eq .FieldType "int" }}

Loading…
Cancel
Save