From c821c609845fa6e84ebdf709356882f25ad7e108 Mon Sep 17 00:00:00 2001 From: hansonyu183 <95766183@qq.com> Date: Sat, 20 Jun 2020 13:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=98=E5=8C=96=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BB=A3=E7=A0=81=E4=B8=AD=E5=AF=B9bool=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=90=9C=E7=B4=A2=E5=AD=97=E6=AE=B5=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/template/fe/table.vue.tpl | 27 ++++++++++++++++++++++ server/resource/template/te/model.go.tpl | 9 ++++++-- server/resource/template/te/service.go.tpl | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/server/resource/template/fe/table.vue.tpl b/server/resource/template/fe/table.vue.tpl index 367d1207..c6fedf49 100644 --- a/server/resource/template/fe/table.vue.tpl +++ b/server/resource/template/fe/table.vue.tpl @@ -4,9 +4,32 @@ {{- range .Fields}} {{- if .FieldSearchType}} + {{- if eq .FieldType "bool" }} + + + + + + + + + + + + + {{- else }} + {{ end }} {{ end }} {{ end }} @@ -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) { diff --git a/server/resource/template/te/model.go.tpl b/server/resource/template/te/model.go.tpl index 873d5787..0a51ad59 100644 --- a/server/resource/template/te/model.go.tpl +++ b/server/resource/template/te/model.go.tpl @@ -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 }} +} } diff --git a/server/resource/template/te/service.go.tpl b/server/resource/template/te/service.go.tpl index 5ba589c3..16546c27 100644 --- a/server/resource/template/te/service.go.tpl +++ b/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 }}) } {{- 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" }}