feat : update actions gen

This commit is contained in:
zhangwenjian committed 2020-09-10 02:14:48 +08:00
1 parent aaba20d42a
commit fa07a57d22
14 files changed
+160 -112

No files matched your search

+81 -29
View File
@@ -30,7 +30,7 @@ func Preview(c *gin.Context) {
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/router.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/dto.go.template")
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
tab, _ := table.Get()
var b1 bytes.Buffer
@@ -68,7 +68,6 @@ func GenCode(c *gin.Context) {
routerfile := "template/routercheckrole.go.template"
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
@@ -88,7 +87,7 @@ func GenCode(c *gin.Context) {
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/dto.go.template")
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./apis/" + tab.ModuleName + "/")
@@ -136,7 +135,6 @@ func GenCode(c *gin.Context) {
app.OK(c, "", "Code generated successfully!")
}
func GenCodeV2(c *gin.Context) {
table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId"))
@@ -144,14 +142,23 @@ func GenCodeV2(c *gin.Context) {
table.TableId = id
tab, _ := table.Get()
routerfile := "template/v1.2/routercheckrole.go.template"
if !tab.IsAuth {
routerfile = "template/v1.2/routernocheckrole.go.template"
if tab.IsActions {
ActionsGen(tab)
} else {
NOActionsGen(tab)
}
t1, err := template.ParseFiles("template/v1.2/model.go.template")
app.OK(c, "", "Code generated successfully!")
}
func NOActionsGen(tab tools.SysTables) {
routerfile := "template/routercheckrole.go.template"
if !tab.IsAuth {
routerfile = "template/routernocheckrole.go.template"
}
t1, err := template.ParseFiles("template/model.go.template")
tools2.HasError(err, "", -1)
t2, err := template.ParseFiles("template/api.go.template")
tools2.HasError(err, "", -1)
@@ -161,15 +168,15 @@ func GenCodeV2(c *gin.Context) {
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/v1.2/dto.go.template")
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./app/admin/apis/" + tab.ModuleName + "/")
_ = tools2.PathCreate("./app/admin/models/")
_ = tools2.PathCreate("./app/admin/router/")
_ = tools2.PathCreate("./app/admin/dto/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName + "/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName)
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
@@ -183,15 +190,60 @@ func GenCodeV2(c *gin.Context) {
err = t5.Execute(&b5, tab)
var b6 bytes.Buffer
err = t6.Execute(&b6, tab)
tools2.FileCreate(b1, "./app/admin/models/"+tab.PackageName+".go")
tools2.FileCreate(b2, "./app/admin/apis/"+tab.ModuleName+"/"+tab.PackageName+".go")
tools2.FileCreate(b3, "./app/admin/router/"+tab.PackageName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue")
tools2.FileCreate(b6, "./app/admin/service/dto/"+tab.PackageName+".go")
tools2.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
tools2.FileCreate(b2, "./app/"+tab.PackageName+"/apis/"+tab.ModuleName+"/"+tab.BusinessName+".go")
tools2.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
}
app.OK(c, "", "Code generated successfully!")
func ActionsGen(tab tools.SysTables) {
routerfile := "template/v2/routercheckrole.go.template"
if !tab.IsAuth {
routerfile = "template/v2/routernocheckrole.go.template"
}
t1, err := template.ParseFiles("template/v2/model.go.template")
tools2.HasError(err, "", -1)
//t2, err := template.ParseFiles("template/v2/router.go.template")
//tools2.HasError(err, "", -1)
t3, err := template.ParseFiles(routerfile)
tools2.HasError(err, "", -1)
t4, err := template.ParseFiles("template/js.go.template")
tools2.HasError(err, "", -1)
t5, err := template.ParseFiles("template/vue.go.template")
tools2.HasError(err, "", -1)
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
_ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.BusinessName)
var b1 bytes.Buffer
err = t1.Execute(&b1, tab)
//var b2 bytes.Buffer
//err = t2.Execute(&b2, tab)
var b3 bytes.Buffer
err = t3.Execute(&b3, tab)
var b4 bytes.Buffer
err = t4.Execute(&b4, tab)
var b5 bytes.Buffer
err = t5.Execute(&b5, tab)
var b6 bytes.Buffer
err = t6.Execute(&b6, tab)
tools2.FileCreate(b1, "./app/"+tab.PackageName+"/models/"+tab.BusinessName+".go")
//tools2.FileCreate(b2, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b3, "./app/"+tab.PackageName+"/router/"+tab.BusinessName+".go")
tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.BusinessName+".js")
tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.BusinessName+"/index.vue")
tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
}
func GenMenuAndApi(c *gin.Context) {
@@ -228,10 +280,10 @@ func GenMenuAndApi(c *gin.Context) {
Cmenu.Path = tab.TBName
Cmenu.MenuType = "C"
Cmenu.Action = "无"
Cmenu.Permission = tab.PackageName + ":" + tab.ModuleName + ":list"
Cmenu.Permission = tab.ModuleName + ":" + tab.BusinessName + ":list"
Cmenu.ParentId = Mmenu.MenuId
Cmenu.NoCache = false
Cmenu.Component = "/" + tab.ModuleName + "/index"
Cmenu.Component = "/" + tab.BusinessName + "/index"
Cmenu.Sort = 0
Cmenu.Visible = "0"
Cmenu.IsFrame = "0"
@@ -248,7 +300,7 @@ func GenMenuAndApi(c *gin.Context) {
MList.Path = tab.TBName
MList.MenuType = "F"
MList.Action = "无"
MList.Permission = tab.PackageName + ":" + tab.ModuleName + ":query"
MList.Permission = tab.ModuleName + ":" + tab.BusinessName + ":query"
MList.ParentId = Cmenu.MenuId
MList.NoCache = false
MList.Sort = 0
@@ -267,7 +319,7 @@ func GenMenuAndApi(c *gin.Context) {
MCreate.Path = tab.TBName
MCreate.MenuType = "F"
MCreate.Action = "无"
MCreate.Permission = tab.PackageName + ":" + tab.ModuleName + ":add"
MCreate.Permission = tab.ModuleName + ":" + tab.BusinessName + ":add"
MCreate.ParentId = Cmenu.MenuId
MCreate.NoCache = false
MCreate.Sort = 0
@@ -286,7 +338,7 @@ func GenMenuAndApi(c *gin.Context) {
MUpdate.Path = tab.TBName
MUpdate.MenuType = "F"
MUpdate.Action = "无"
MUpdate.Permission = tab.PackageName + ":" + tab.ModuleName + ":edit"
MUpdate.Permission = tab.ModuleName + ":" + tab.BusinessName + ":edit"
MUpdate.ParentId = Cmenu.MenuId
MUpdate.NoCache = false
MUpdate.Sort = 0
@@ -305,7 +357,7 @@ func GenMenuAndApi(c *gin.Context) {
MDelete.Path = tab.TBName
MDelete.MenuType = "F"
MDelete.Action = "无"
MDelete.Permission = tab.PackageName + ":" + tab.ModuleName + ":remove"
MDelete.Permission = tab.ModuleName + ":" + tab.BusinessName + ":remove"
MDelete.ParentId = Cmenu.MenuId
MDelete.NoCache = false
MDelete.Sort = 0
+1 -2
View File
@@ -5,7 +5,6 @@ import (
"go-admin/app/admin/middleware"
"go-admin/app/admin/middleware/handler"
"go-admin/common/global"
jwt "go-admin/pkg/jwtauth"
_ "go-admin/pkg/jwtauth"
"go-admin/tools"
config2 "go-admin/tools/config"
@@ -19,7 +18,7 @@ func InitRouter(r *gin.Engine) *gin.Engine {
middleware.InitMiddleware(r)
// the jwt middleware
var err error
authMiddleware, err = middleware.AuthInit()
authMiddleware, err := middleware.AuthInit()
tools.HasError(err, "JWT Init Error", 500)
// 注册系统路由
+1 -1
View File
@@ -65,7 +65,7 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
v1.GET("/monitor/server", monitor.ServerInfo)
v1.GET("/getCaptcha", system.GenerateCaptchaHandler)
v1.GET("/gen/preview/:tableId", Preview)
v1.GET("/gen/toproject/:tableId", GenCode)
v1.GET("/gen/toproject/:tableId", GenCodeV2)
v1.GET("/gen/todb/:tableId", GenMenuAndApi)
v1.GET("/gen/tabletree", GetSysTablesTree)
v1.GET("/menuTreeselect", system.GetMenuTreeelect)
+1
View File
@@ -2,6 +2,7 @@ package dto
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/common/dto"
models2 "go-admin/common/models"