增加自动创建搜索功能 增加搜索条件 增加数据库注释 增加插件功能(0.0.1版 请勿用于生产)

This commit is contained in:
pixel
2020-06-07 14:56:37 +08:00
parent 8173ff6fc2
commit fde276e159
20 changed files with 187 additions and 69 deletions

View File

@@ -2,9 +2,18 @@
<div>
<div class="search-term">
<el-form :inline="true" :model="searchInfo" class="demo-form-inline">
此处请使用表单生成器生成form填充 表单默认绑定 formData 如手动修改过请自行修改key
{{- range .Fields}}
{{- if .FieldSearchType}}
<el-form-item label="{{.FieldDesc}}">
<el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
</el-form-item>
{{ end }}
{{ end }}
<el-form-item>
<el-button @click="openDialog" type="primary">新增</el-button>
<el-button @click="onSubmit" type="primary">查询</el-button>
</el-form-item>
<el-form-item>
<el-button @click="openDialog" type="primary">新增api</el-button>
</el-form-item>
</el-form>
</div>
@@ -95,6 +104,12 @@ export default {
}
},
methods: {
//
onSubmit() {
this.page = 1
this.pageSize = 10
this.getTableData()
},
async update{{.StructName}}(row) {
const res = await find{{.StructName}}({ ID: row.ID });
this.type = "update";

View File

@@ -91,11 +91,11 @@ func Find{{.StructName}}(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取{{.StructName}}列表"
// @Param data body request.{{.StructName}}Search true "分页获取{{.StructName}}列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
func Get{{.StructName}}List(c *gin.Context) {
var pageInfo request.PageInfo
var pageInfo request.{{.StructName}}Search
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.Get{{.StructName}}InfoList(pageInfo)
if err != nil {

View File

@@ -5,7 +5,8 @@ import (
"github.com/jinzhu/gorm"
)
// 如果含有time.Time 请自行import time包
type {{.StructName}} struct {
gorm.Model {{range .Fields}}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" {{if .ColumnName}} gorm:"column:{{.ColumnName}}"{{end}}`{{ end }}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"`{{ end }}
}

View File

@@ -0,0 +1,8 @@
package request
import "gin-vue-admin/model"
type {{.StructName}}Search struct{
model.{{.StructName}}
PageInfo
}

View File

@@ -57,12 +57,39 @@ func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructNa
// @param info PageInfo
// @return error
func Get{{.StructName}}InfoList(info request.PageInfo) (err error, list interface{}, total int) {
func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
// db
db := global.GVA_DB
var {{.Abbreviation}}s []model.{{.StructName}}
var {{.Abbreviation}}s []model.{{.StructName}}
//
{{- range .Fields}}
{{- if .FieldSearchType}}
{{- if eq .FieldType "string" }}
if info.{{.FieldName}} != "" {
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 {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "int" }}
if info.{{.FieldName}} != 0 {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "float64" }}
if info.{{.FieldName}} != 0 {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- else if eq .FieldType "time.Time" }}
if !info.{{.FieldName}}.IsZero() {
db = db.Where("{{.ColumnName}} {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }})
}
{{- end }}
{{- end }}
{{- end }}
err = db.Find(&{{.Abbreviation}}s).Count(&total).Error
err = db.Limit(limit).Offset(offset).Find(&{{.Abbreviation}}s).Error
return err, {{.Abbreviation}}s, total
}
}