diff --git a/app/admin/apis/tools/gen.go b/app/admin/apis/tools/gen.go
index 838c43e..50a4576 100644
--- a/app/admin/apis/tools/gen.go
+++ b/app/admin/apis/tools/gen.go
@@ -9,7 +9,6 @@ import (
"go-admin/app/admin/models"
"go-admin/app/admin/models/tools"
- "go-admin/common/global"
tools2 "go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/config"
@@ -20,17 +19,17 @@ func Preview(c *gin.Context) {
id, err := tools2.StringToInt(c.Param("tableId"))
tools2.HasError(err, "", -1)
table.TableId = id
- t1, err := template.ParseFiles("template/model.go.template")
+ t1, err := template.ParseFiles("template/v3/model.go.template")
tools2.HasError(err, "", -1)
- t2, err := template.ParseFiles("template/api.go.template")
+ t2, err := template.ParseFiles("template/v3/no_actions/api.go.template")
tools2.HasError(err, "", -1)
- t3, err := template.ParseFiles("template/js.go.template")
+ t3, err := template.ParseFiles("template/v3/js.go.template")
tools2.HasError(err, "", -1)
- t4, err := template.ParseFiles("template/vue.go.template")
+ t4, err := template.ParseFiles("template/v3/vue.go.template")
tools2.HasError(err, "", -1)
- t5, err := template.ParseFiles("template/router.go.template")
+ t5, err := template.ParseFiles("template/v3/no_actions/router_check_role.go.template")
tools2.HasError(err, "", -1)
- t6, err := template.ParseFiles("template/v2/dto.go.template")
+ t6, err := template.ParseFiles("template/v3/no_actions/dto.go.template")
tools2.HasError(err, "", -1)
tab, _ := table.Get()
var b1 bytes.Buffer
@@ -59,98 +58,6 @@ func Preview(c *gin.Context) {
c.JSON(http.StatusOK, res.ReturnOK())
}
-func GenCode(c *gin.Context) {
- table := tools.SysTables{}
- id, err := tools2.StringToInt(c.Param("tableId"))
- tools2.HasError(err, "", -1)
- table.TableId = id
- tab, _ := table.Get()
-
- routerfile := "template/routercheckrole.go.template"
-
- oldTest := "// {{认证路由自动补充在此处请勿删除}}"
- newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
-
- if tab.IsAuth == 2 {
- oldTest = "// {{无需认证路由自动补充在此处请勿删除}}"
- newText = "// {{无需认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1)"
- 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)
- 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("./apis/" + tab.ModuleName + "/")
- _ = tools2.PathCreate("./models/")
- _ = tools2.PathCreate("./router/")
- _ = tools2.PathCreate("./dto/")
- _ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/")
- _ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName)
-
- 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, "./models/"+tab.PackageName+".go")
- tools2.FileCreate(b2, "./apis/"+tab.ModuleName+"/"+tab.PackageName+".go")
- tools2.FileCreate(b3, "./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, "./dto/"+tab.PackageName+".go")
-
- helper := tools2.ReplaceHelper{
- Root: "./router/router.go",
- OldText: oldTest,
- NewText: newText,
- }
- if helper.OldText == helper.NewText {
- global.Logger.Println("error !! the NewText isEqual the OldText")
- return
- }
- if err := helper.DoWrok(); err != nil {
- global.Logger.Print("error:", err.Error())
-
- } else {
- global.Logger.Print("done!")
- }
-
- app.OK(c, "", "Code generated successfully!")
-}
-
-func GenCodeV2(c *gin.Context) {
- table := tools.SysTables{}
- id, err := tools2.StringToInt(c.Param("tableId"))
- tools2.HasError(err, "", -1)
- table.TableId = id
- tab, _ := table.Get()
-
- if tab.IsActions == 1 {
- ActionsGen(tab)
- } else {
- NOActionsGen(tab)
- }
-
- app.OK(c, "", "Code generated successfully!")
-}
-
func GenCodeV3(c *gin.Context) {
table := tools.SysTables{}
id, err := tools2.StringToInt(c.Param("tableId"))
@@ -265,101 +172,6 @@ func ActionsGenV3(tab tools.SysTables) {
tools2.FileCreate(b6, "./app/"+tab.PackageName+"/service/dto/"+tab.BusinessName+".go")
}
-func NOActionsGen(tab tools.SysTables) {
- routerfile := "template/routercheckrole.go.template"
-
- if tab.IsAuth == 2 {
- 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)
- 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 + "/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.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+"/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")
-
-}
-
-func ActionsGen(tab tools.SysTables) {
- routerfile := "template/v2/routercheckrole.go.template"
-
- if tab.IsAuth == 2 {
- 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) {
table := tools.SysTables{}
diff --git a/common/database/mysql-drive.go b/common/database/mysql_drive.go
similarity index 100%
rename from common/database/mysql-drive.go
rename to common/database/mysql_drive.go
diff --git a/common/database/pgsql-driver.go b/common/database/pgsql_driver.go
similarity index 100%
rename from common/database/pgsql-driver.go
rename to common/database/pgsql_driver.go
diff --git a/common/database/sqlite3-driver.go b/common/database/sqlite3_driver.go
similarity index 100%
rename from common/database/sqlite3-driver.go
rename to common/database/sqlite3_driver.go
diff --git a/common/global/logger.go b/common/global/logger.go
deleted file mode 100644
index dfbfa4a..0000000
--- a/common/global/logger.go
+++ /dev/null
@@ -1 +0,0 @@
-package global
diff --git a/template/api.go.template b/template/api.go.template
deleted file mode 100644
index c264074..0000000
--- a/template/api.go.template
+++ /dev/null
@@ -1,84 +0,0 @@
-package {{.ModuleName}}
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/app/admin/models"
- "go-admin/app/admin/service/dto"
- "go-admin/tools"
- "go-admin/tools/app"
- "go-admin/tools/app/msg"
-)
-
-func Get{{.ClassName}}List(c *gin.Context) {
- var data models.{{.ClassName}}
- var err error
- var pageSize = 10
- var pageIndex = 1
-
- if size := c.Request.FormValue("pageSize"); size != "" {
- pageSize, err = tools.StringToInt(size)
- }
- if index := c.Request.FormValue("pageIndex"); index != "" {
- pageIndex, err = tools.StringToInt(index)
- }
-
- var v dto.{{.ClassName}}Search
- err = c.Bind(&v)
- tools.HasError(err, "数据解析失败", 422)
-
- data.DataScope = tools.GetUserIdStr(c)
- result, count, err := data.GetPage(pageSize, pageIndex, v)
- tools.HasError(err, "", -1)
-
- app.PageOK(c, result, count, pageIndex, pageSize, "")
-}
-
-func Get{{.ClassName}}(c *gin.Context) {
- var data models.{{.ClassName}}
- data.{{.PkGoField}}, _ = tools.StringToInt(c.Param("{{.PkJsonField}}"))
- result, err := data.Get()
- tools.HasError(err, "抱歉未找到相关信息", -1)
-
- app.OK(c, result, "")
-}
-
-// @Summary 添加{{.TableComment}}
-// @Description 获取JSON
-// @Tags {{.TableComment}}
-// @Accept application/json
-// @Product application/json
-// @Param data body models.{{.ClassName}} true "data"
-// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
-// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
-// @Router /api/v1/{{.ModuleName}} [post]
-func Insert{{.ClassName}}(c *gin.Context) {
- var data models.{{.ClassName}}
- err := c.ShouldBindJSON(&data)
- data.CreateBy = tools.GetUserIdStr(c)
- tools.HasError(err, "", 500)
- result, err := data.Create()
- tools.HasError(err, "", -1)
- app.OK(c, result, "")
-}
-
-func Update{{.ClassName}}(c *gin.Context) {
- var data models.{{.ClassName}}
- err := c.ShouldBindJSON(&data)
- tools.HasError(err, "数据解析失败", -1)
- data.UpdateBy = tools.GetUserIdStr(c)
- result, err := data.Update(data.{{.PkGoField}})
- tools.HasError(err, "", -1)
-
- app.OK(c, result, "")
-}
-
-func Delete{{.ClassName}}(c *gin.Context) {
- var data models.{{.ClassName}}
- data.UpdateBy = tools.GetUserIdStr(c)
-
- IDS := tools.GetDeleteIds(c)
- _, err := data.BatchDelete(IDS)
- tools.HasError(err, msg.DeletedFail, 500)
- app.OK(c, nil, msg.DeletedSuccess)
-}
\ No newline at end of file
diff --git a/template/dto.go.template b/template/dto.go.template
deleted file mode 100644
index a59cf2d..0000000
--- a/template/dto.go.template
+++ /dev/null
@@ -1,12 +0,0 @@
-package dto
-
-type {{.ClassName}}Search struct {
- {{ $tablename := .TBName -}}
- {{ range .Columns -}}
- {{$z := .IsQuery}}
- {{- if ($z) -}}
- {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}"` // {{.ColumnComment}}
-
- {{end -}}
- {{- end }}
-}
diff --git a/template/js.go.template b/template/js.go.template
deleted file mode 100644
index db3d4a2..0000000
--- a/template/js.go.template
+++ /dev/null
@@ -1,47 +0,0 @@
-import request from '@/utils/request'
-
-// 查询{{.ClassName}}列表
-export function list{{.ClassName}}(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'
- })
-}
-
-
-// 新增{{.ClassName}}
-export function add{{.ClassName}}(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
- })
-}
-
-// 删除{{.ClassName}}
-export function del{{.ClassName}}(data) {
- return request({
- url: '/api/v1/{{.ModuleName}}',
- method: 'delete',
- data: data
- })
-}
-
diff --git a/template/model.go.template b/template/model.go.template
deleted file mode 100644
index 3e47a8b..0000000
--- a/template/model.go.template
+++ /dev/null
@@ -1,149 +0,0 @@
-package models
-
-import (
- "gorm.io/gorm"
-
- "go-admin/common/dto"
- orm "go-admin/common/global"
- "go-admin/common/models"
- "go-admin/tools"
-
- {{ range .Columns }}
- {{- if eq .GoField "CreatedAt" -}}
- {{- else if eq .GoField "UpdatedAt" -}}
- {{- else if eq .GoField "DeletedAt" -}}
- {{- else if eq .GoType "time.Time" -}}"time"{{- end}}
- {{- end }}
-)
-
-type {{.ClassName}} struct {
- gorm.Model
- models.ControlBy
- {{ range .Columns -}}
- {{$x := .Pk}}
- {{- if ($x) }}
-
- {{- else if eq .GoField "CreatedAt" -}}
- {{- else if eq .GoField "UpdatedAt" -}}
- {{- else if eq .GoField "DeletedAt" -}}
- {{- 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 -}}
- {{- end }}
- DataScope string `json:"dataScope" gorm:"-"`
- Params string `json:"params" gorm:"-"`
-}
-
-func ({{.ClassName}}) TableName() string {
- return "{{.TBName}}"
-}
-
-
-func (e *{{.ClassName}}) Generate() models.ActiveRecord {
- o := *e
- return &o
-}
-
-func (e *{{.ClassName}}) GetId() interface{} {
- return e.{{.PkGoField}}
-}
-
-func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
- e.CreateBy = createBy
-}
-
-func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) {
- e.UpdateBy = updateBy
-}
-
-// 创建{{.ClassName}}
-func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
- var doc {{.ClassName}}
- result := orm.Eloquent.Table(e.TableName()).Create(&e)
- if result.Error != nil {
- err := result.Error
- return doc, err
- }
- doc = *e
- return doc, nil
-}
-
-
-// 获取{{.ClassName}}
-func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
- var doc {{.ClassName}}
- table := orm.Eloquent.Table(e.TableName())
- {{ range .Columns }}
- {{$x := .Pk}}
- {{- if ($x) }}
- if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
- table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
- }
- {{- else if .IsQuery }}
- if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} {
- table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}})
- }
- {{ end -}}
- {{- end }}
-
- if err := table.First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
-}
-
-// 获取{{.ClassName}}带分页
-func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int, v interface{}) ([]{{.ClassName}}, int, error) {
- var doc []{{.ClassName}}
-
- table := orm.Eloquent.Table(e.TableName()).Scopes(dto.MakeCondition(v))
-
- // 数据权限控制(如果不需要数据权限请将此处去掉)
- dataPermission := new(DataPermission)
- dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
- table,err := dataPermission.GetDataScope(e.TableName(), table)
- if err != nil {
- return nil, 0, err
- }
- var count int64
-
- if err := table.Scopes(dto.Paginate(pageSize, pageIndex)).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
- return nil, 0, err
- }
- return doc, int(count), nil
-}
-
-// 更新{{.ClassName}}
-func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
- if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
- return
- }
-
- //参数1:是要修改的数据
- //参数2:是修改的数据
- if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
- return
- }
- return
-}
-
-// 删除{{.ClassName}}
-func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
- if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
- success = false
- return
- }
- success = true
- return
-}
-
-//批量删除
-func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) {
- if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
- return
- }
- Result = true
- return
-}
diff --git a/template/router.go.template b/template/router.go.template
deleted file mode 100644
index 30f8c73..0000000
--- a/template/router.go.template
+++ /dev/null
@@ -1,33 +0,0 @@
-package router
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/middleware"
- "go-admin/apis/{{.ModuleName}}"
- jwt "go-admin/pkg/jwtauth"
-)
-
-// 需认证的路由代码
-func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
- r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
- {
- r.GET("/:{{.PkJsonField}}", {{.ModuleName}}.Get{{.ClassName}})
- r.GET("", {{.ModuleName}}.Get{{.ClassName}}List)
- r.POST("", {{.ModuleName}}.Insert{{.ClassName}})
- r.PUT("", {{.ModuleName}}.Update{{.ClassName}})
- r.DELETE("", {{.ModuleName}}.Delete{{.ClassName}})
- }
-}
-
-// 无需认证的路由代码
-func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
- r := v1.Group("/{{.ModuleName}}")
- {
- r.GET("", {{.ModuleName}}.Get{{.ClassName}}List)
- r.GET("/:{{.PkJsonField}}", {{.ModuleName}}.Get{{.ClassName}})
- r.POST("", {{.ModuleName}}.Insert{{.ClassName}})
- r.PUT("", {{.ModuleName}}.Update{{.ClassName}})
- r.DELETE("", {{.ModuleName}}.Delete{{.ClassName}})
- }
-}
diff --git a/template/routercheckrole.go.template b/template/routercheckrole.go.template
deleted file mode 100644
index e28b2af..0000000
--- a/template/routercheckrole.go.template
+++ /dev/null
@@ -1,25 +0,0 @@
-package router
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/app/admin/apis/{{.ModuleName}}"
- "go-admin/app/admin/middleware"
- jwt "go-admin/pkg/jwtauth"
-)
-
-func init() {
- routerCheckRole = append(routerCheckRole, register{{.ClassName}}Router)
-}
-
-// 需认证的路由代码
-func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
- r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
- {
- r.GET("/:{{.PkJsonField}}", {{.ModuleName}}.Get{{.ClassName}})
- r.POST("", {{.ModuleName}}.Insert{{.ClassName}})
- r.PUT("/:{{.PkJsonField}}", {{.ModuleName}}.Update{{.ClassName}})
- r.DELETE("", {{.ModuleName}}.Delete{{.ClassName}})
- r.GET("",{{.ModuleName}}.Get{{.ClassName}}List)
- }
-}
diff --git a/template/routernocheckrole.go.template b/template/routernocheckrole.go.template
deleted file mode 100644
index 076606e..0000000
--- a/template/routernocheckrole.go.template
+++ /dev/null
@@ -1,23 +0,0 @@
-package router
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/app/admin/apis/{{.ModuleName}}"
-)
-
-func init() {
- routerNoCheckRole = append(routerNoCheckRole, register{{.ClassName}}Router)
-}
-
-// 无需认证的路由代码
-func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
- r := v1.Group("/{{.ModuleName}}")
- {
- r.GET("/:{{.PkJsonField}}", {{.ModuleName}}.Get{{.ClassName}})
- r.POST("", {{.ModuleName}}.Insert{{.ClassName}})
- r.PUT("/:{{.PkJsonField}}", {{.ModuleName}}.Update{{.ClassName}})
- r.DELETE("", {{.ModuleName}}.Delete{{.ClassName}})
- r.GET("",{{.ModuleName}}.Get{{.ClassName}}List)
- }
-}
diff --git a/template/v2/dto.go.template b/template/v2/dto.go.template
deleted file mode 100644
index 989e5cd..0000000
--- a/template/v2/dto.go.template
+++ /dev/null
@@ -1,113 +0,0 @@
-package dto
-
-import (
- "github.com/gin-gonic/gin"
- "gorm.io/gorm"
-
- "go-admin/app/admin/models"
- "go-admin/common/dto"
- "go-admin/common/log"
- common "go-admin/common/models"
-)
-
-type {{.ClassName}}Search struct {
- dto.Pagination `search:"-"`
- {{ $tablename := .TBName -}}
- {{ range .Columns -}}
- {{$z := .IsQuery}}
- {{- if ($z) -}}
- {{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}" comment:"{{.ColumnComment}}"`
-
- {{ end -}}
- {{- end }}
-}
-
-func (m *{{.ClassName}}Search) GetNeedSearch() interface{} {
- return *m
-}
-
-func (m *{{.ClassName}}Search) Bind(ctx *gin.Context) error {
- err := ctx.ShouldBind(m)
- if err != nil {
- log.Errorf("MsgID[%s] Bind error: %#v", err)
- }
- return err
-}
-
-func (m *{{.ClassName}}Search) Generate() dto.Index {
- o := *m
- return &o
-}
-
-type {{.ClassName}}Control struct {
- {{ range .Columns -}}
- {{$x := .Pk}}
- {{- if ($x) }}
- {{.GoField}} uint `uri:"{{.JsonField}}" comment:"{{.ColumnComment}}"` // {{.ColumnComment}}
- {{- else if eq .GoField "CreatedAt" -}}
- {{- else if eq .GoField "UpdatedAt" -}}
- {{- else if eq .GoField "DeletedAt" -}}
- {{- else if eq .GoField "CreateBy" -}}
- {{- else if eq .GoField "UpdateBy" -}}
-
- {{- else }}
-
- {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" comment:"{{.ColumnComment}}"`
- {{end -}}
- {{- end }}
-}
-
-func (s *{{.ClassName}}Control) Bind(ctx *gin.Context) error {
- err := ctx.ShouldBindUri(s)
- if err != nil {
- log.Errorf("MsgID[%s] Bind error: %#v", err)
- return err
- }
- err = ctx.ShouldBind(s)
- if err != nil {
- log.Errorf("MsgID[%s] Bind error: %#v", err)
- }
- return err
-}
-
-func (s *{{.ClassName}}Control) Generate() dto.Control {
- cp := *s
- return &cp
-}
-
-func (s *{{.ClassName}}Control) GenerateM() (common.ActiveRecord, error) {
- return &models.{{.ClassName}}{
- {{ range .Columns -}}
- {{$x := .Pk}}
- {{- if ($x) }}
- Model: gorm.Model{ID: s.ID},
- {{- else if eq .GoField "CreatedAt" -}}
- {{- else if eq .GoField "UpdatedAt" -}}
- {{- else if eq .GoField "DeletedAt" -}}
- {{- else if eq .GoField "CreateBy" -}}
-
-
- {{- else if eq .GoField "UpdateBy" -}}
- {{- else }}
- {{.GoField}}: s.{{.GoField}},
- {{- end }}
- {{- end }}
- }, nil
-}
-
-func (s *{{.ClassName}}Control) GetId() interface{} {
- return s.{{.PkGoField}}
-}
-
-type {{.ClassName}}ById struct {
- dto.ObjectById
-}
-
-func (s *{{.ClassName}}ById) Generate() dto.Control {
- cp := *s
- return &cp
-}
-
-func (s *{{.ClassName}}ById) GenerateM() (common.ActiveRecord, error) {
- return &models.{{.ClassName}}{}, nil
-}
diff --git a/template/v2/model.go.template b/template/v2/model.go.template
deleted file mode 100644
index ecbebbe..0000000
--- a/template/v2/model.go.template
+++ /dev/null
@@ -1,43 +0,0 @@
-package models
-
-import (
- "gorm.io/gorm"
-
- {{- if eq .IsActions 2 -}}
-
- "go-admin/common/dto"
- "go-admin/tools"
- orm "go-admin/common/global"
- {{ end }}
- "go-admin/common/models"
-)
-
-type {{.ClassName}} struct {
- gorm.Model
- models.ControlBy
- {{ range .Columns -}}
- {{$x := .Pk}}
- {{- if ($x) }}
-
- {{- else if eq .GoField "CreatedAt" -}}
- {{- else if eq .GoField "UpdatedAt" -}}
- {{- else if eq .GoField "DeletedAt" -}}
- {{- 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 -}}
- {{- end }}
-}
-
-func ({{.ClassName}}) TableName() string {
- return "{{.TBName}}"
-}
-
-func (e *{{.ClassName}}) Generate() models.ActiveRecord {
- o := *e
- return &o
-}
-
-func (e *{{.ClassName}}) GetId() interface{} {
- return e.{{.PkGoField}}
-}
diff --git a/template/v2/routercheckrole.go.template b/template/v2/routercheckrole.go.template
deleted file mode 100644
index 88451bd..0000000
--- a/template/v2/routercheckrole.go.template
+++ /dev/null
@@ -1,31 +0,0 @@
-package router
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/app/admin/middleware"
- "go-admin/app/admin/models"
- "go-admin/app/admin/service/dto"
- "go-admin/common/actions"
- jwt "go-admin/pkg/jwtauth"
-)
-
-func init() {
- routerCheckRole = append(routerCheckRole, register{{.ClassName}}Router)
-}
-
-// 需认证的路由代码
-func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
- r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
- {
- model := &models.{{.ClassName}}{}
- r.GET("", actions.PermissionAction(), actions.IndexAction(model, new(dto.{{.ClassName}}Search), func() interface{} {
- list := make([]models.{{.ClassName}}, 0)
- return &list
- }))
- r.GET("/:id", actions.PermissionAction(), actions.ViewAction(new(dto.{{.ClassName}}ById), nil))
- r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
- r.PUT("/:id", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control)))
- r.DELETE("", actions.PermissionAction(), actions.DeleteAction(new(dto.{{.ClassName}}ById)))
- }
-}
diff --git a/template/v2/routernocheckrole.go.template b/template/v2/routernocheckrole.go.template
deleted file mode 100644
index c647266..0000000
--- a/template/v2/routernocheckrole.go.template
+++ /dev/null
@@ -1,30 +0,0 @@
-package router
-
-import (
- "github.com/gin-gonic/gin"
-
- "go-admin/app/admin/middleware"
- "go-admin/app/admin/models"
- "go-admin/app/admin/service/dto"
- "go-admin/common/actions"
-)
-
-func init() {
- routerNoCheckRole = append(routerNoCheckRole, register{{.ClassName}}Router)
-}
-
-// 无需认证的路由代码
-func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
- r := v1.Group("/{{.ModuleName}}")
- {
- model := &models.{{.ClassName}}{}
- r.GET("", actions.IndexAction(model, new(dto.{{.ClassName}}Search), func() interface{} {
- list := make([]models.{{.ClassName}}, 0)
- return &list
- }))
- r.GET("/:id", actions.ViewAction(new(dto.{{.ClassName}}ById), nil))
- r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
- r.PUT("/:id", actions.UpdateAction(new(dto.{{.ClassName}}Control)))
- r.DELETE("", actions.DeleteAction(new(dto.{{.ClassName}}ById)))
- }
-}
diff --git a/template/vue.go.template b/template/vue.go.template
deleted file mode 100644
index 0aa3a2b..0000000
--- a/template/vue.go.template
+++ /dev/null
@@ -1,472 +0,0 @@
-{{$tableComment:=.TableComment}}
-
-
-
-
-
- {{range .Columns}}
- {{- $x := .IsQuery -}}
- {{- if ($x) -}}
-
- {{- if ne .FkTableName "" -}}
-
-
-
- {{- else -}}
- {{if eq .DictType "" -}}
-
- {{- else -}}
-
-
-
- {{- end}}
- {{- end}}
-
- {{end}}
- {{- end }}
-
- 搜索
- 重置
-
-
-
-
-
- 新增
-
-
-
- 修改
-
-
-
- 删除
-
-
-
-
-
-
- {{- range .Columns -}}
- {{- $x := .IsList -}}
- {{- if (eq $x "1") }}
- {{- if ne .FkTableName "" -}}
-
-
- {{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
-
-
-
- {{- else -}}
- {{- if ne .DictType "" -}}
-
-
- {{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
-
-
-
- {{- end -}}
- {{- if eq .DictType "" -}}
-
-
- {{- end -}}
- {{- end -}}
- {{- end }}
- {{- end }}
-
-
- 修改
-
- 删除
-
-
-
-
-
-
-
-
-
-
- {{ range .Columns }}
- {{- $x := .IsInsert -}}
- {{- if (eq $x "1") -}}
- {{- if (.Pk) }}
- {{- else if eq .GoField "CreatedAt" -}}
- {{- else if eq .GoField "UpdatedAt" -}}
- {{- else if eq .GoField "DeletedAt" -}}
- {{- else if eq .GoField "UpdateBy" -}}
- {{- else if eq .GoField "CreateBy" -}}
- {{- else }}
-
- {{ if eq "input" .HtmlType -}}
-
- {{- else if eq "select" .HtmlType -}}
- {{- if ne .FkTableName "" -}}
-
-
-
- {{- else -}}
-
-
-
- {{- end -}}
- {{- else if eq "radio" .HtmlType -}}
-
- {{"{{"}} dict.dictLabel {{"}}"}}
-
- {{- else if eq "file" .HtmlType -}}
-
- 选择文件
- {{- else if eq "datetime" .HtmlType -}}
-
-
- {{- else if eq "textarea" .HtmlType -}}
-
-
- {{- end }}
-
- {{- end }}
- {{- end }}
- {{- end }}
-
-
-
-
-
-
-
-
-
-