提交 c821c609 编写于 作者: H hansonyu183

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

上级 51fcf447
......@@ -4,9 +4,32 @@
<el-form :inline="true" :model="searchInfo" class="demo-form-inline">
{{- range .Fields}}
{{- 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-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
</el-form-item>
{{ end }}
{{ end }}
{{ end }}
<el-form-item>
......@@ -108,6 +131,10 @@ export default {
onSubmit() {
this.page = 1
this.pageSize = 10
{{- range .Fields}} {{- if eq .FieldType "bool" }}
if (this.searchInfo.{{.FieldJson}}==""){
this.searchInfo.{{.FieldJson}}=null
} {{ end }} {{ end }}
this.getTableData()
},
async update{{.StructName}}(row) {
......
......@@ -7,6 +7,11 @@ import (
// 如果含有time.Time 请自行import time包
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 }}
}
}
......@@ -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 }})
}
{{- 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 }})
}
{{- else if eq .FieldType "int" }}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册