From fd271709463d2795fa2cb385b5f0301e1c585fa2 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sun, 13 Sep 2020 17:57:11 +0800 Subject: [PATCH] feat:update tpl --- app/admin/apis/tools/systables.go | 9 +++++- app/admin/models/config.go | 6 ---- template/js.go.template | 48 +++++++++++++++---------------- template/model.go.template | 9 +++--- template/v2/dto.go.template | 17 +++++++---- template/v2/model.go.template | 7 +++-- 6 files changed, 52 insertions(+), 44 deletions(-) diff --git a/app/admin/apis/tools/systables.go b/app/admin/apis/tools/systables.go index 7b9896a..f4c9dc8 100644 --- a/app/admin/apis/tools/systables.go +++ b/app/admin/apis/tools/systables.go @@ -191,6 +191,8 @@ func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables, column.IsPk = "1" column.Pk = true data.PkColumn = dbcolumn[i].ColumnName + column.GoField = strings.ToUpper(column.GoField) + column.JsonField = strings.ToUpper(column.JsonField) data.PkGoField = column.GoField data.PkJsonField = column.JsonField } @@ -202,7 +204,9 @@ func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables, if strings.Contains(dbcolumn[i].ColumnType, "int") { if strings.Contains(dbcolumn[i].ColumnKey, "PR") { - column.GoType = "int" + column.GoType = "uint" + } else if strings.Contains(dbcolumn[i].ColumnType, "unsigned") { + column.GoType = "uint" } else { column.GoType = "string" } @@ -210,6 +214,9 @@ func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables, } else if strings.Contains(dbcolumn[i].ColumnType, "timestamp") { column.GoType = "time.Time" column.HtmlType = "datetime" + } else if strings.Contains(dbcolumn[i].ColumnType, "datetime") { + column.GoType = "time.Time" + column.HtmlType = "datetime" } else { column.GoType = "string" column.HtmlType = "input" diff --git a/app/admin/models/config.go b/app/admin/models/config.go index 6835bce..2dcfa55 100644 --- a/app/admin/models/config.go +++ b/app/admin/models/config.go @@ -22,12 +22,6 @@ type SysConfig struct { BaseModel } -func DataInit() { - //config1:=SysConfig{1, "主框架页-默认皮肤样式名称", "sys_index_skinName", "skin-blue", "Y", "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow", "1", "1", "","",BaseModel{time.Now(), time.Now(), nil}} - // - //orm.Eloquent.Create(&config1) -} - func (SysConfig) TableName() string { return "sys_config" } diff --git a/template/js.go.template b/template/js.go.template index fb91a49..db3d4a2 100644 --- a/template/js.go.template +++ b/template/js.go.template @@ -2,46 +2,46 @@ import request from '@/utils/request' // 查询{{.ClassName}}列表 export function list{{.ClassName}}(query) { -return request({ -url: '/api/v1/{{.ModuleName}}', -method: 'get', -params: query -}) + return request({ + url: '/api/v1/{{.ModuleName}}', + method: 'get', + params: query + }) } // 查询{{.ClassName}}详细 export function get{{.ClassName}} ({{.PkJsonField}}) { -return request({ -url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}}, -method: 'get' -}) + return request({ + url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}}, + method: 'get' + }) } // 新增{{.ClassName}} export function add{{.ClassName}}(data) { -return request({ -url: '/api/v1/{{.ModuleName}}', -method: 'post', -data: data -}) + return request({ + url: '/api/v1/{{.ModuleName}}', + method: 'post', + data: data + }) } // 修改{{.ClassName}} export function update{{.ClassName}}(data) { -return request({ -url: '/api/v1/{{.ModuleName}}/'+data.{{.PkJsonField}}, -method: 'put', -data: data -}) + return request({ + url: '/api/v1/{{.ModuleName}}/'+data.{{.PkJsonField}}, + method: 'put', + data: data + }) } // 删除{{.ClassName}} export function del{{.ClassName}}(data) { -return request({ -url: '/api/v1/{{.ModuleName}}', -method: 'delete', -data: data -}) + return request({ + url: '/api/v1/{{.ModuleName}}', + method: 'delete', + data: data + }) } diff --git a/template/model.go.template b/template/model.go.template index 7efd5ff..3e47a8b 100644 --- a/template/model.go.template +++ b/template/model.go.template @@ -1,7 +1,7 @@ package models import ( - "strconv" + "gorm.io/gorm" "go-admin/common/dto" orm "go-admin/common/global" @@ -29,7 +29,8 @@ type {{.ClassName}} struct { {{- else if eq .GoField "CreateBy" -}} {{- else if eq .GoField "UpdateBy" -}} {{- else }} - {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` {{end -}} + {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` + {{end -}} {{- end }} DataScope string `json:"dataScope" gorm:"-"` Params string `json:"params" gorm:"-"` @@ -50,11 +51,11 @@ func (e *{{.ClassName}}) GetId() interface{} { } func (e *{{.ClassName}}) SetCreateBy(createBy uint) { - e.CreateBy = strconv.Itoa(int(createBy)) + e.CreateBy = createBy } func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) { - e.UpdateBy = strconv.Itoa(int(updateBy)) + e.UpdateBy = updateBy } // 创建{{.ClassName}} diff --git a/template/v2/dto.go.template b/template/v2/dto.go.template index 8f044fd..f4a6b5d 100644 --- a/template/v2/dto.go.template +++ b/template/v2/dto.go.template @@ -2,6 +2,8 @@ package dto import ( "github.com/gin-gonic/gin" + "gorm.io/gorm" + "go-admin/app/admin/models" "go-admin/common/dto" common "go-admin/common/models" @@ -48,14 +50,16 @@ type {{.ClassName}}Control struct { {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} - {{- else if eq .GoField "CreateBy" -}} - + {{- else if eq .GoField "CreateBy" }} + {{.GoField}} uint `json:"{{.JsonField}}"` // {{.ColumnComment}} - {{- else if eq .GoField "UpdateBy" -}} + {{- else if eq .GoField "UpdateBy" }} {{.GoField}} uint `json:"{{.JsonField}}"` // {{.ColumnComment}} {{- else }} - {{.GoField}} {{.GoType}} `json:"{{.JsonField}}"` // {{.ColumnComment}}{{end -}} + + {{.GoField}} {{.GoType}} `json:"{{.JsonField}}"` // {{.ColumnComment}} + {{end -}} {{- end }} } @@ -73,7 +77,7 @@ func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) { {{ range .Columns -}} {{$x := .Pk}} {{- if ($x) }} - Model: gorm.Model{ID: s.Id}, + Model: gorm.Model{ID: s.ID}, {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} @@ -82,7 +86,8 @@ func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) { CreateBy: s.CreateBy, UpdateBy: s.UpdateBy, }, - {{- else if eq .GoField "UpdateBy" -}} + + {{- else if eq .GoField "UpdateBy" -}} {{- else }} {{.GoField}}: s.{{.GoField}}, {{- end }} diff --git a/template/v2/model.go.template b/template/v2/model.go.template index 7f31a69..017cfc7 100644 --- a/template/v2/model.go.template +++ b/template/v2/model.go.template @@ -1,7 +1,8 @@ package models import ( - "strconv" + "gorm.io/gorm" + {{- if eq .IsActions 2 -}} "go-admin/common/dto" @@ -44,9 +45,9 @@ func (e *{{.ClassName}}) GetId() interface{} { } func (e *{{.ClassName}}) SetCreateBy(createBy uint) { - e.CreateBy = strconv.Itoa(int(createBy)) + e.CreateBy = createBy } func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) { - e.UpdateBy = strconv.Itoa(int(updateBy)) + e.UpdateBy = updateBy } \ No newline at end of file