refactor🎨: 生成逻辑调整
This commit is contained in:
1 parent
d82129d364
commit
eb8062d19b
4 files changed
+25
-16
No files matched your search
File renamed without changes.
+19
-12
@@ -168,6 +168,7 @@ func (e Gen) GenApiToFile(c *gin.Context) {
|
|||||||
func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
|
func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
|
||||||
e.Context = c
|
e.Context = c
|
||||||
log := e.GetLogger()
|
log := e.GetLogger()
|
||||||
|
tab.MLTBName = strings.Replace(tab.TBName, "_", "-", -1)
|
||||||
|
|
||||||
basePath := "template/v4/"
|
basePath := "template/v4/"
|
||||||
routerFile := basePath + "no_actions/router_check_role.go.template"
|
routerFile := basePath + "no_actions/router_check_role.go.template"
|
||||||
@@ -223,8 +224,13 @@ func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
|
|||||||
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
|
_ = pkg.PathCreate("./app/" + tab.PackageName + "/models/")
|
||||||
_ = pkg.PathCreate("./app/" + tab.PackageName + "/router/")
|
_ = pkg.PathCreate("./app/" + tab.PackageName + "/router/")
|
||||||
_ = pkg.PathCreate("./app/" + tab.PackageName + "/service/dto/")
|
_ = pkg.PathCreate("./app/" + tab.PackageName + "/service/dto/")
|
||||||
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/api/")
|
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/api/" + tab.PackageName+ "/")
|
||||||
_ = pkg.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.ModuleFrontName)
|
err = pkg.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName + "/" + tab.MLTBName+ "/")
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
e.Error(500, err, fmt.Sprintf("views目录创建失败!错误详情:%s", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var b1 bytes.Buffer
|
var b1 bytes.Buffer
|
||||||
err = t1.Execute(&b1, tab)
|
err = t1.Execute(&b1, tab)
|
||||||
@@ -240,13 +246,13 @@ func (e Gen) NOActionsGen(c *gin.Context, tab tools.SysTables) {
|
|||||||
err = t6.Execute(&b6, tab)
|
err = t6.Execute(&b6, tab)
|
||||||
var b7 bytes.Buffer
|
var b7 bytes.Buffer
|
||||||
err = t7.Execute(&b7, tab)
|
err = t7.Execute(&b7, tab)
|
||||||
pkg.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.ModuleName+".go")
|
pkg.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.TBName+".go")
|
||||||
pkg.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.ModuleName+".go")
|
pkg.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.TBName+".go")
|
||||||
pkg.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.ModuleName+".go")
|
pkg.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.TBName+".go")
|
||||||
pkg.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.ModuleFrontName+".js")
|
pkg.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+"/"+tab.MLTBName+".js")
|
||||||
pkg.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.ModuleFrontName+"/index.vue")
|
pkg.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/"+tab.MLTBName+"/index.vue")
|
||||||
pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.ModuleName+".go")
|
pkg.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.TBName+".go")
|
||||||
pkg.FileCreate(b7, "./app/"+tab.PackageName+"/service/"+tab.ModuleName+".go")
|
pkg.FileCreate(b7, "./app/"+tab.PackageName+"/service/"+tab.TBName+".go")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,11 +379,12 @@ func (e Gen) GenMenuAndApi(c *gin.Context) {
|
|||||||
|
|
||||||
table.TableId = id
|
table.TableId = id
|
||||||
tab, _ := table.Get(e.Orm)
|
tab, _ := table.Get(e.Orm)
|
||||||
|
tab.MLTBName = strings.Replace(tab.TBName, "_", "-", -1)
|
||||||
|
|
||||||
Mmenu := dto.SysMenuControl{}
|
Mmenu := dto.SysMenuControl{}
|
||||||
Mmenu.Title = tab.TableComment
|
Mmenu.Title = tab.TableComment
|
||||||
Mmenu.Icon = "pass"
|
Mmenu.Icon = "pass"
|
||||||
Mmenu.Path = "/" + strings.Replace(tab.TBName, "_", "-", -1)
|
Mmenu.Path = "/" +tab.MLTBName
|
||||||
Mmenu.MenuType = "M"
|
Mmenu.MenuType = "M"
|
||||||
Mmenu.Action = "无"
|
Mmenu.Action = "无"
|
||||||
Mmenu.ParentId = 0
|
Mmenu.ParentId = 0
|
||||||
@@ -393,13 +400,13 @@ func (e Gen) GenMenuAndApi(c *gin.Context) {
|
|||||||
Cmenu.MenuName = tab.ClassName + "Manage"
|
Cmenu.MenuName = tab.ClassName + "Manage"
|
||||||
Cmenu.Title = tab.TableComment
|
Cmenu.Title = tab.TableComment
|
||||||
Cmenu.Icon = "pass"
|
Cmenu.Icon = "pass"
|
||||||
Cmenu.Path = tab.TBName
|
Cmenu.Path = "/" + tab.PackageName + "/" + tab.MLTBName
|
||||||
Cmenu.MenuType = "C"
|
Cmenu.MenuType = "C"
|
||||||
Cmenu.Action = "无"
|
Cmenu.Action = "无"
|
||||||
Cmenu.Permission = tab.PackageName + ":" + tab.ModuleFrontName + ":list"
|
Cmenu.Permission = tab.PackageName + ":" + tab.ModuleFrontName + ":list"
|
||||||
Cmenu.ParentId = Mmenu.MenuId
|
Cmenu.ParentId = Mmenu.MenuId
|
||||||
Cmenu.NoCache = false
|
Cmenu.NoCache = false
|
||||||
Cmenu.Component = "/" + tab.ModuleFrontName + "/index"
|
Cmenu.Component = "/" + tab.PackageName + "/" + tab.MLTBName + "/index"
|
||||||
Cmenu.Sort = 0
|
Cmenu.Sort = 0
|
||||||
Cmenu.Visible = "0"
|
Cmenu.Visible = "0"
|
||||||
Cmenu.IsFrame = "0"
|
Cmenu.IsFrame = "0"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
type SysTables struct {
|
type SysTables struct {
|
||||||
TableId int `gorm:"primaryKey;autoIncrement" json:"tableId"` //表编码
|
TableId int `gorm:"primaryKey;autoIncrement" json:"tableId"` //表编码
|
||||||
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
|
TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称
|
||||||
|
MLTBName string `gorm:"-" json:"-"` //表名称
|
||||||
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
|
TableComment string `gorm:"size:255;" json:"tableComment"` //表备注
|
||||||
ClassName string `gorm:"size:255;" json:"className"` //类名
|
ClassName string `gorm:"size:255;" json:"className"` //类名
|
||||||
TplCategory string `gorm:"size:255;" json:"tplCategory"` //
|
TplCategory string `gorm:"size:255;" json:"tplCategory"` //
|
||||||
@@ -188,16 +189,17 @@ func (e *SysTables) Update(tx *gorm.DB) (update SysTables, err error) {
|
|||||||
t, ok := tableMap[e.Columns[i].FkTableName]
|
t, ok := tableMap[e.Columns[i].FkTableName]
|
||||||
if ok {
|
if ok {
|
||||||
e.Columns[i].FkTableNameClass = t.ClassName
|
e.Columns[i].FkTableNameClass = t.ClassName
|
||||||
e.Columns[i].FkTableNamePackage = t.ModuleName
|
t.MLTBName = strings.Replace(t.TBName, "_", "-", -1)
|
||||||
|
e.Columns[i].FkTableNamePackage = t.MLTBName
|
||||||
} else {
|
} else {
|
||||||
tableNameList := strings.Split(e.Columns[i].FkTableName, "_")
|
tableNameList := strings.Split(e.Columns[i].FkTableName, "_")
|
||||||
e.Columns[i].FkTableNameClass = ""
|
e.Columns[i].FkTableNameClass = ""
|
||||||
e.Columns[i].FkTableNamePackage = ""
|
//e.Columns[i].FkTableNamePackage = ""
|
||||||
for a := 0; a < len(tableNameList); a++ {
|
for a := 0; a < len(tableNameList); a++ {
|
||||||
strStart := string([]byte(tableNameList[a])[:1])
|
strStart := string([]byte(tableNameList[a])[:1])
|
||||||
strEnd := string([]byte(tableNameList[a])[1:])
|
strEnd := string([]byte(tableNameList[a])[1:])
|
||||||
e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd
|
e.Columns[i].FkTableNameClass += strings.ToUpper(strStart) + strEnd
|
||||||
e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
|
//e.Columns[i].FkTableNamePackage += strings.ToLower(strStart) + strings.ToLower(strEnd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package global
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Version go-admin version info
|
// Version go-admin version info
|
||||||
Version = "2.0.0-beta.7"
|
Version = "2.0.0-beta.8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in new issue
Block a user