Merge branch 'dev' of github.com:wenjianzhang/go-admin into table/dev
Conflicts: template/v2/dto.go.template template/v2/model.go.template
This commit is contained in:
commit
ca4ed89536
15 files changed
+61
-48
No files matched your search
@@ -191,6 +191,8 @@ func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables,
|
|||||||
column.IsPk = "1"
|
column.IsPk = "1"
|
||||||
column.Pk = true
|
column.Pk = true
|
||||||
data.PkColumn = dbcolumn[i].ColumnName
|
data.PkColumn = dbcolumn[i].ColumnName
|
||||||
|
column.GoField = strings.ToUpper(column.GoField)
|
||||||
|
column.JsonField = strings.ToUpper(column.JsonField)
|
||||||
data.PkGoField = column.GoField
|
data.PkGoField = column.GoField
|
||||||
data.PkJsonField = column.JsonField
|
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].ColumnType, "int") {
|
||||||
if strings.Contains(dbcolumn[i].ColumnKey, "PR") {
|
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 {
|
} else {
|
||||||
column.GoType = "string"
|
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") {
|
} else if strings.Contains(dbcolumn[i].ColumnType, "timestamp") {
|
||||||
column.GoType = "time.Time"
|
column.GoType = "time.Time"
|
||||||
column.HtmlType = "datetime"
|
column.HtmlType = "datetime"
|
||||||
|
} else if strings.Contains(dbcolumn[i].ColumnType, "datetime") {
|
||||||
|
column.GoType = "time.Time"
|
||||||
|
column.HtmlType = "datetime"
|
||||||
} else {
|
} else {
|
||||||
column.GoType = "string"
|
column.GoType = "string"
|
||||||
column.HtmlType = "input"
|
column.HtmlType = "input"
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ type SysConfig struct {
|
|||||||
BaseModel
|
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 {
|
func (SysConfig) TableName() string {
|
||||||
return "sys_config"
|
return "sys_config"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SysDept struct {
|
type SysDept struct {
|
||||||
DeptId int `json:"deptId" gorm:"primary_key;AUTO_INCREMENT"` //部门编码
|
DeptId int `json:"deptId" gorm:"primary_key;auto_increment;"` //部门编码
|
||||||
ParentId int `json:"parentId" gorm:""` //上级部门
|
ParentId int `json:"parentId" gorm:""` //上级部门
|
||||||
DeptPath string `json:"deptPath" gorm:"size:255;"` //
|
DeptPath string `json:"deptPath" gorm:"size:255;"` //
|
||||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DictData struct {
|
type DictData struct {
|
||||||
DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码
|
DictCode int `gorm:"primary_key;auto_increment;" json:"dictCode" example:"1"` //字典编码
|
||||||
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
DictSort int `gorm:"" json:"dictSort"` //显示顺序
|
||||||
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签
|
||||||
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DictType struct {
|
type DictType struct {
|
||||||
DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"`
|
DictId int `gorm:"primary_key;auto_increment;" json:"dictId"`
|
||||||
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
|
DictName string `gorm:"size:128;" json:"dictName"` //字典名称
|
||||||
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
|
DictType string `gorm:"size:128;" json:"dictType"` //字典类型
|
||||||
Status string `gorm:"size:4;" json:"status"` //状态
|
Status string `gorm:"size:4;" json:"status"` //状态
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
type SysFileDir struct {
|
type SysFileDir struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Id int `json:"id" gorm:"type:int(11);primary_key;AUTO_INCREMENT"` //
|
Id int `json:"id" gorm:"type:int(11);primary_key;auto_increment;"` //
|
||||||
Label string `json:"label" gorm:"type:varchar(255);"` // 名称
|
Label string `json:"label" gorm:"type:varchar(255);"` // 名称
|
||||||
PId int `json:"pId" gorm:"type:int(11);"` // 父id
|
PId int `json:"pId" gorm:"type:int(11);"` // 父id
|
||||||
Sort int `json:"sort" gorm:""` //排序
|
Sort int `json:"sort" gorm:""` //排序
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LoginLog struct {
|
type LoginLog struct {
|
||||||
InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键
|
InfoId int `json:"infoId" gorm:"primary_key;auto_increment;"` //主键
|
||||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
Username string `json:"username" gorm:"size:128;"` //用户名
|
||||||
Status string `json:"status" gorm:"size:4;"` //状态
|
Status string `json:"status" gorm:"size:4;"` //状态
|
||||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type MenuLable struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Menus struct {
|
type Menus struct {
|
||||||
MenuId int `json:"menuId" gorm:"column:menu_id;primary_key"`
|
MenuId int `json:"menuId" gorm:"column:menu_id;primary_key;"`
|
||||||
MenuName string `json:"menuName" gorm:"column:menu_name"`
|
MenuName string `json:"menuName" gorm:"column:menu_name"`
|
||||||
Title string `json:"title" gorm:"column:title"`
|
Title string `json:"title" gorm:"column:title"`
|
||||||
Icon string `json:"icon" gorm:"column:icon"`
|
Icon string `json:"icon" gorm:"column:icon"`
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SysFileInfo struct {
|
type SysFileInfo struct {
|
||||||
Id int `json:"id" gorm:"type:int(11);primary_key;AUTO_INCREMENT"` // id
|
Id int `json:"id" gorm:"type:int(11);primary_key;auto_increment;"` // id
|
||||||
Type string `json:"type" gorm:"type:varchar(255);"` // 文件类型
|
Type string `json:"type" gorm:"type:varchar(255);"` // 文件类型
|
||||||
Name string `json:"name" gorm:"type:varchar(255);"` // 文件名称
|
Name string `json:"name" gorm:"type:varchar(255);"` // 文件名称
|
||||||
Size string `json:"size" gorm:"type:int(11);"` // 文件大小
|
Size string `json:"size" gorm:"type:int(11);"` // 文件大小
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
|||||||
new(models.SysConfig),
|
new(models.SysConfig),
|
||||||
new(models.SysSetting),
|
new(models.SysSetting),
|
||||||
new(models.SysFileDir),
|
new(models.SysFileDir),
|
||||||
|
new(models.SysFileInfo),
|
||||||
new(models.SysCategory),
|
new(models.SysCategory),
|
||||||
new(models.SysContent),
|
new(models.SysContent),
|
||||||
)
|
)
|
||||||
|
|||||||
+24
-24
@@ -2,46 +2,46 @@ import request from '@/utils/request'
|
|||||||
|
|
||||||
// 查询{{.ClassName}}列表
|
// 查询{{.ClassName}}列表
|
||||||
export function list{{.ClassName}}(query) {
|
export function list{{.ClassName}}(query) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}',
|
url: '/api/v1/{{.ModuleName}}',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: query
|
params: query
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询{{.ClassName}}详细
|
// 查询{{.ClassName}}详细
|
||||||
export function get{{.ClassName}} ({{.PkJsonField}}) {
|
export function get{{.ClassName}} ({{.PkJsonField}}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
|
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 新增{{.ClassName}}
|
// 新增{{.ClassName}}
|
||||||
export function add{{.ClassName}}(data) {
|
export function add{{.ClassName}}(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}',
|
url: '/api/v1/{{.ModuleName}}',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改{{.ClassName}}
|
// 修改{{.ClassName}}
|
||||||
export function update{{.ClassName}}(data) {
|
export function update{{.ClassName}}(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}/'+data.{{.PkJsonField}},
|
url: '/api/v1/{{.ModuleName}}/'+data.{{.PkJsonField}},
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除{{.ClassName}}
|
// 删除{{.ClassName}}
|
||||||
export function del{{.ClassName}}(data) {
|
export function del{{.ClassName}}(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/api/v1/{{.ModuleName}}',
|
url: '/api/v1/{{.ModuleName}}',
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
orm "go-admin/common/global"
|
orm "go-admin/common/global"
|
||||||
@@ -29,7 +29,8 @@ type {{.ClassName}} struct {
|
|||||||
{{- else if eq .GoField "CreateBy" -}}
|
{{- else if eq .GoField "CreateBy" -}}
|
||||||
{{- else if eq .GoField "UpdateBy" -}}
|
{{- else if eq .GoField "UpdateBy" -}}
|
||||||
{{- else }}
|
{{- 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 }}
|
{{- end }}
|
||||||
DataScope string `json:"dataScope" gorm:"-"`
|
DataScope string `json:"dataScope" gorm:"-"`
|
||||||
Params string `json:"params" gorm:"-"`
|
Params string `json:"params" gorm:"-"`
|
||||||
@@ -50,11 +51,11 @@ func (e *{{.ClassName}}) GetId() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
|
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
|
||||||
e.CreateBy = strconv.Itoa(int(createBy))
|
e.CreateBy = createBy
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) {
|
func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) {
|
||||||
e.UpdateBy = strconv.Itoa(int(updateBy))
|
e.UpdateBy = updateBy
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建{{.ClassName}}
|
// 创建{{.ClassName}}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package dto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type {{.ClassName}}Search struct {
|
type {{.ClassName}}Search struct {
|
||||||
@@ -49,6 +50,10 @@ type {{.ClassName}}Control struct {
|
|||||||
{{- else if eq .GoField "CreatedAt" -}}
|
{{- else if eq .GoField "CreatedAt" -}}
|
||||||
{{- else if eq .GoField "UpdatedAt" -}}
|
{{- else if eq .GoField "UpdatedAt" -}}
|
||||||
{{- else if eq .GoField "DeletedAt" -}}
|
{{- else if eq .GoField "DeletedAt" -}}
|
||||||
|
{{- else if eq .GoField "CreateBy" }}
|
||||||
|
|
||||||
|
{{.GoField}} uint `json:"{{.JsonField}}"` // {{.ColumnComment}}
|
||||||
|
{{- else if eq .GoField "UpdateBy" }}
|
||||||
{{- else if eq .GoField "CreateBy" -}}
|
{{- else if eq .GoField "CreateBy" -}}
|
||||||
|
|
||||||
{{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
{{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
||||||
@@ -56,6 +61,9 @@ type {{.ClassName}}Control struct {
|
|||||||
|
|
||||||
{{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
{{.GoField}} uint `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
|
||||||
{{- else }}
|
{{- else }}
|
||||||
|
|
||||||
|
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}"` // {{.ColumnComment}}
|
||||||
|
{{end -}}
|
||||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{end -}}
|
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"` {{end -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
@@ -74,7 +82,7 @@ func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) {
|
|||||||
{{ range .Columns -}}
|
{{ range .Columns -}}
|
||||||
{{$x := .Pk}}
|
{{$x := .Pk}}
|
||||||
{{- if ($x) }}
|
{{- if ($x) }}
|
||||||
Model: gorm.Model{ID: s.Id},
|
Model: gorm.Model{ID: s.ID},
|
||||||
{{- else if eq .GoField "CreatedAt" -}}
|
{{- else if eq .GoField "CreatedAt" -}}
|
||||||
{{- else if eq .GoField "UpdatedAt" -}}
|
{{- else if eq .GoField "UpdatedAt" -}}
|
||||||
{{- else if eq .GoField "DeletedAt" -}}
|
{{- else if eq .GoField "DeletedAt" -}}
|
||||||
@@ -83,7 +91,8 @@ func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) {
|
|||||||
CreateBy: s.CreateBy,
|
CreateBy: s.CreateBy,
|
||||||
UpdateBy: s.UpdateBy,
|
UpdateBy: s.UpdateBy,
|
||||||
},
|
},
|
||||||
{{- else if eq .GoField "UpdateBy" -}}
|
|
||||||
|
{{- else if eq .GoField "UpdateBy" -}}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{.GoField}}: s.{{.GoField}},
|
{{.GoField}}: s.{{.GoField}},
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
{{- if eq .IsActions 2 -}}
|
{{- if eq .IsActions 2 -}}
|
||||||
|
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
@@ -8,7 +10,6 @@ import (
|
|||||||
orm "go-admin/common/global"
|
orm "go-admin/common/global"
|
||||||
{{ end }}
|
{{ end }}
|
||||||
"go-admin/common/models"
|
"go-admin/common/models"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type {{.ClassName}} struct {
|
type {{.ClassName}} struct {
|
||||||
@@ -40,7 +41,7 @@ func (e *{{.ClassName}}) Generate() models.ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *{{.ClassName}}) GetId() interface{} {
|
func (e *{{.ClassName}}) GetId() interface{} {
|
||||||
return e.ID
|
return e.{{.PkGoField}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
|
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
|
||||||
|
|||||||
@@ -378,7 +378,7 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
// 文件
|
// 文件
|
||||||
{{range .Columns}}
|
{{range .Columns}}
|
||||||
{{- if ne .HtmlType "file" -}}
|
{{- if eq .HtmlType "file" -}}
|
||||||
fileShow{{.GoField}}: function() {
|
fileShow{{.GoField}}: function() {
|
||||||
this.fileOpen = true
|
this.fileOpen = true
|
||||||
this.fileIndex = '{{.JsonField}}'
|
this.fileIndex = '{{.JsonField}}'
|
||||||
|
|||||||
Reference in new issue
Block a user