增加自动创建搜索功能 增加搜索条件 增加数据库注释 增加插件功能(0.0.1版 请勿用于生产)
This commit is contained in:
@@ -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";
|
||||
|
@@ -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 {
|
||||
|
@@ -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 }}
|
||||
}
|
||||
|
8
server/resource/template/te/request.go.tpl
Normal file
8
server/resource/template/te/request.go.tpl
Normal file
@@ -0,0 +1,8 @@
|
||||
package request
|
||||
|
||||
import "gin-vue-admin/model"
|
||||
|
||||
type {{.StructName}}Search struct{
|
||||
model.{{.StructName}}
|
||||
PageInfo
|
||||
}
|
@@ -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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user