feat:update file struct
This commit is contained in:
1 parent
c9b073908e
commit
99acf0086f
17 files changed
+6
-1257
No files matched your search
+6
-194
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"go-admin/app/admin/models/tools"
|
"go-admin/app/admin/models/tools"
|
||||||
"go-admin/common/global"
|
|
||||||
tools2 "go-admin/tools"
|
tools2 "go-admin/tools"
|
||||||
"go-admin/tools/app"
|
"go-admin/tools/app"
|
||||||
"go-admin/tools/config"
|
"go-admin/tools/config"
|
||||||
@@ -20,17 +19,17 @@ func Preview(c *gin.Context) {
|
|||||||
id, err := tools2.StringToInt(c.Param("tableId"))
|
id, err := tools2.StringToInt(c.Param("tableId"))
|
||||||
tools2.HasError(err, "", -1)
|
tools2.HasError(err, "", -1)
|
||||||
table.TableId = id
|
table.TableId = id
|
||||||
t1, err := template.ParseFiles("template/model.go.template")
|
t1, err := template.ParseFiles("template/v3/model.go.template")
|
||||||
tools2.HasError(err, "", -1)
|
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)
|
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)
|
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)
|
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)
|
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)
|
tools2.HasError(err, "", -1)
|
||||||
tab, _ := table.Get()
|
tab, _ := table.Get()
|
||||||
var b1 bytes.Buffer
|
var b1 bytes.Buffer
|
||||||
@@ -59,98 +58,6 @@ func Preview(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
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) {
|
func GenCodeV3(c *gin.Context) {
|
||||||
table := tools.SysTables{}
|
table := tools.SysTables{}
|
||||||
id, err := tools2.StringToInt(c.Param("tableId"))
|
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")
|
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) {
|
func GenMenuAndApi(c *gin.Context) {
|
||||||
|
|
||||||
table := tools.SysTables{}
|
table := tools.SysTables{}
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1 +0,0 @@
|
|||||||
package global
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -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 }}
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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}})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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}}
|
|
||||||
}
|
|
||||||
@@ -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)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,472 +0,0 @@
|
|||||||
{{$tableComment:=.TableComment}}
|
|
||||||
<template>
|
|
||||||
<BasicLayout>
|
|
||||||
<template #wrapper>
|
|
||||||
<el-card class="box-card">
|
|
||||||
<el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- $x := .IsQuery -}}
|
|
||||||
{{- if ($x) -}}
|
|
||||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
<el-select v-model="form.{{.JsonField}}"
|
|
||||||
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
|
||||||
<el-option
|
|
||||||
v-for="dict in {{.JsonField}}Options"
|
|
||||||
:key="dict.key"
|
|
||||||
:label="dict.value"
|
|
||||||
:value="dict.key"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
{{- else -}}
|
|
||||||
{{if eq .DictType "" -}}
|
|
||||||
<el-input v-model="queryParams.{{.JsonField}}" placeholder="请输入{{.ColumnComment}}" clearable
|
|
||||||
size="small" @keyup.enter.native="handleQuery"/>
|
|
||||||
{{- else -}}
|
|
||||||
<el-select v-model="queryParams.{{.JsonField}}"
|
|
||||||
placeholder="{{$tableComment}}{{.ColumnComment}}" clearable size="small">
|
|
||||||
<el-option
|
|
||||||
v-for="dict in {{.JsonField}}Options"
|
|
||||||
:key="dict.dictValue"
|
|
||||||
:label="dict.dictLabel"
|
|
||||||
:value="dict.dictValue"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
{{- end}}
|
|
||||||
{{- end}}
|
|
||||||
</el-form-item>
|
|
||||||
{{end}}
|
|
||||||
{{- end }}
|
|
||||||
<el-form-item>
|
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:add']"
|
|
||||||
type="primary"
|
|
||||||
icon="el-icon-plus"
|
|
||||||
size="mini"
|
|
||||||
@click="handleAdd"
|
|
||||||
>新增
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:edit']"
|
|
||||||
type="success"
|
|
||||||
icon="el-icon-edit"
|
|
||||||
size="mini"
|
|
||||||
:disabled="single"
|
|
||||||
@click="handleUpdate"
|
|
||||||
>修改
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:remove']"
|
|
||||||
type="danger"
|
|
||||||
icon="el-icon-delete"
|
|
||||||
size="mini"
|
|
||||||
:disabled="multiple"
|
|
||||||
@click="handleDelete"
|
|
||||||
>删除
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="{{.ModuleName}}List" @selection-change="handleSelectionChange">
|
|
||||||
<el-table-column type="selection" width="55" align="center"/>
|
|
||||||
{{- range .Columns -}}
|
|
||||||
{{- $x := .IsList -}}
|
|
||||||
{{- if (eq $x "1") }}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}" :formatter="{{.JsonField}}Format" width="100">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
{{- else -}}
|
|
||||||
{{- if ne .DictType "" -}}
|
|
||||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
|
||||||
:formatter="{{.JsonField}}Format" width="100">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
{{ "{{" }} {{.JsonField}}Format(scope.row) {{"}}"}}
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
{{- end -}}
|
|
||||||
{{- if eq .DictType "" -}}
|
|
||||||
<el-table-column label="{{.ColumnComment}}" align="center" prop="{{.JsonField}}"
|
|
||||||
:show-overflow-tooltip="true"/>
|
|
||||||
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:edit']"
|
|
||||||
size="mini"
|
|
||||||
type="text"
|
|
||||||
icon="el-icon-edit"
|
|
||||||
@click="handleUpdate(scope.row)"
|
|
||||||
>修改
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['{{.PackageName}}:{{.ModuleName}}:remove']"
|
|
||||||
size="mini"
|
|
||||||
type="text"
|
|
||||||
icon="el-icon-delete"
|
|
||||||
@click="handleDelete(scope.row)"
|
|
||||||
>删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<pagination
|
|
||||||
v-show="total>0"
|
|
||||||
:total="total"
|
|
||||||
:page.sync="queryParams.pageIndex"
|
|
||||||
:limit.sync="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- 添加或修改对话框 -->
|
|
||||||
<el-dialog :title="title" :visible.sync="open" width="500px">
|
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
||||||
{{ 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 }}
|
|
||||||
<el-form-item label="{{.ColumnComment}}" prop="{{.JsonField}}">
|
|
||||||
{{ if eq "input" .HtmlType -}}
|
|
||||||
<el-input v-model="form.{{.JsonField}}" placeholder="{{.ColumnComment}}"
|
|
||||||
{{if eq .IsEdit "false" -}}:disabled="isEdit" {{- end}}/>
|
|
||||||
{{- else if eq "select" .HtmlType -}}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
<el-select v-model="form.{{.JsonField}}"
|
|
||||||
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
|
||||||
<el-option
|
|
||||||
v-for="dict in {{.JsonField}}Options"
|
|
||||||
:key="dict.key"
|
|
||||||
:label="dict.value"
|
|
||||||
:value="dict.key"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
{{- else -}}
|
|
||||||
<el-select v-model="form.{{.JsonField}}"
|
|
||||||
placeholder="请选择" {{if eq .IsEdit "false" -}} :disabled="isEdit" {{- end }}>
|
|
||||||
<el-option
|
|
||||||
v-for="dict in {{.JsonField}}Options"
|
|
||||||
:key="dict.dictValue"
|
|
||||||
:label="dict.dictLabel"
|
|
||||||
:value="dict.dictValue"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
{{- end -}}
|
|
||||||
{{- else if eq "radio" .HtmlType -}}
|
|
||||||
<el-radio-group v-model="form.{{.JsonField}}">
|
|
||||||
<el-radio
|
|
||||||
v-for="dict in {{.JsonField}}Options"
|
|
||||||
:key="dict.dictValue"
|
|
||||||
:label="dict.dictValue"
|
|
||||||
>{{"{{"}} dict.dictLabel {{"}}"}}</el-radio>
|
|
||||||
</el-radio-group>
|
|
||||||
{{- else if eq "file" .HtmlType -}}
|
|
||||||
<el-input
|
|
||||||
v-model="form.{{.JsonField}}"
|
|
||||||
placeholder="图片"
|
|
||||||
/>
|
|
||||||
<el-button type="primary" @click="fileShow{{.GoField}}">选择文件</el-button>
|
|
||||||
{{- else if eq "datetime" .HtmlType -}}
|
|
||||||
<el-date-picker
|
|
||||||
v-model="form.{{.JsonField}}"
|
|
||||||
type="datetime"
|
|
||||||
placeholder="选择日期">
|
|
||||||
</el-date-picker>
|
|
||||||
{{- else if eq "textarea" .HtmlType -}}
|
|
||||||
<el-input
|
|
||||||
v-model="form.{{.JsonField}}"
|
|
||||||
type="textarea"
|
|
||||||
:rows="2"
|
|
||||||
placeholder="请输入内容">
|
|
||||||
</el-input>
|
|
||||||
{{- end }}
|
|
||||||
</el-form-item>
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
{{- end }}
|
|
||||||
</el-form>
|
|
||||||
<div slot="footer" class="dialog-footer">
|
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
||||||
<el-button @click="cancel">取 消</el-button>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
<FileChoose ref="fileChoose" :dialog-form-visible="fileOpen" @confirm="getImgList" @close="fileClose" />
|
|
||||||
</el-card>
|
|
||||||
</template>
|
|
||||||
</BasicLayout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}}} from '@/api/{{ .BusinessName}}'
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
import {list{{.FkTableNameClass}} } from '@/api/{{ .FkTableNamePackage}}'
|
|
||||||
|
|
||||||
{{ end -}}
|
|
||||||
{{- end -}}
|
|
||||||
|
|
||||||
import FileChoose from '@/components/FileChoose'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: '{{.ClassName}}',
|
|
||||||
components: {
|
|
||||||
FileChoose
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
// 遮罩层
|
|
||||||
loading: true,
|
|
||||||
// 选中数组
|
|
||||||
ids: [],
|
|
||||||
// 非单个禁用
|
|
||||||
single: true,
|
|
||||||
// 非多个禁用
|
|
||||||
multiple: true,
|
|
||||||
// 总条数
|
|
||||||
total: 0,
|
|
||||||
// 弹出层标题
|
|
||||||
title: '',
|
|
||||||
// 是否显示弹出层
|
|
||||||
open: false,
|
|
||||||
isEdit: false,
|
|
||||||
fileOpen: false,
|
|
||||||
fileIndex: undefined,
|
|
||||||
// 类型数据字典
|
|
||||||
typeOptions: [],
|
|
||||||
{{.ModuleName}}List: [],
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if ne .DictType "" -}}
|
|
||||||
{{.JsonField}}Options: [],
|
|
||||||
{{- end -}}
|
|
||||||
{{- end }}
|
|
||||||
// 关系表类型
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
{{.JsonField}}Options :[],
|
|
||||||
{{ end -}}
|
|
||||||
{{- end }}
|
|
||||||
// 查询参数
|
|
||||||
queryParams: {
|
|
||||||
pageIndex: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
{{ range .Columns }}
|
|
||||||
{{- if (.IsQuery) -}}
|
|
||||||
{{.JsonField}}:undefined,
|
|
||||||
{{ end -}}
|
|
||||||
{{- end }}
|
|
||||||
},
|
|
||||||
// 表单参数
|
|
||||||
form: {
|
|
||||||
},
|
|
||||||
// 表单校验
|
|
||||||
rules: {
|
|
||||||
{{- range .Columns -}}
|
|
||||||
{{- $x := .IsQuery -}}
|
|
||||||
{{- if ($x) -}}
|
|
||||||
{{.JsonField}}:
|
|
||||||
[
|
|
||||||
{required: true, message: '{{.ColumnComment}}不能为空', trigger: 'blur'}
|
|
||||||
],
|
|
||||||
{{ end }}
|
|
||||||
{{- end -}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.getList()
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if ne .DictType "" -}}
|
|
||||||
|
|
||||||
this.getDicts('{{.DictType}}').then(response => {
|
|
||||||
this.{{.JsonField}}Options = response.data
|
|
||||||
})
|
|
||||||
|
|
||||||
{{ end -}}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
this.get{{.FkTableNameClass}}Items()
|
|
||||||
|
|
||||||
{{ end -}}
|
|
||||||
{{- end -}}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
/** 查询参数列表 */
|
|
||||||
getList() {
|
|
||||||
this.loading = true
|
|
||||||
list{{.ClassName}}(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
|
|
||||||
this.{{.ModuleName}}List = response.data.list
|
|
||||||
this.total = response.data.count
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
// 取消按钮
|
|
||||||
cancel() {
|
|
||||||
this.open = false
|
|
||||||
this.reset()
|
|
||||||
},
|
|
||||||
// 表单重置
|
|
||||||
reset() {
|
|
||||||
this.form = {
|
|
||||||
{{ range .Columns}}
|
|
||||||
{{- $x := .IsInsert -}}
|
|
||||||
{{- if ($x) -}}
|
|
||||||
{{- 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 }}
|
|
||||||
{{.JsonField}}: undefined,
|
|
||||||
{{- end }}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end }}
|
|
||||||
}
|
|
||||||
this.resetForm('form')
|
|
||||||
},
|
|
||||||
getImgList: function() {
|
|
||||||
this.form[this.fileIndex] = this.$refs['fileChoose'].resultList[0].fullUrl
|
|
||||||
},
|
|
||||||
fileClose: function() {
|
|
||||||
this.fileOpen = false
|
|
||||||
},
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if ne .DictType "" -}}
|
|
||||||
{{.JsonField}}Format(row) {
|
|
||||||
return this.selectDictLabel(this.{{.JsonField}}Options, row.{{.JsonField}})
|
|
||||||
},
|
|
||||||
{{ end -}}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
{{.JsonField}}Format(row) {
|
|
||||||
return this.selectItemsLabel(this.{{.JsonField}}Options, row.{{.JsonField}})
|
|
||||||
},
|
|
||||||
{{ end -}}
|
|
||||||
{{- end -}}
|
|
||||||
// 关系
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if ne .FkTableName "" -}}
|
|
||||||
get{{.FkTableNameClass}}Items() {
|
|
||||||
this.getItems(list{{.FkTableNameClass}}, undefined).then(res => {
|
|
||||||
this.{{.JsonField}}Options = this.setItems(res, '{{.FkLabelId}}', '{{.FkLabelName}}')
|
|
||||||
})
|
|
||||||
},
|
|
||||||
{{ end -}}
|
|
||||||
{{- end -}}
|
|
||||||
// 文件
|
|
||||||
{{range .Columns}}
|
|
||||||
{{- if eq .HtmlType "file" -}}
|
|
||||||
fileShow{{.GoField}}: function() {
|
|
||||||
this.fileOpen = true
|
|
||||||
this.fileIndex = '{{.JsonField}}'
|
|
||||||
},
|
|
||||||
{{ end -}}
|
|
||||||
{{- end -}}
|
|
||||||
/** 搜索按钮操作 */
|
|
||||||
handleQuery() {
|
|
||||||
this.queryParams.pageIndex = 1
|
|
||||||
this.getList()
|
|
||||||
},
|
|
||||||
/** 重置按钮操作 */
|
|
||||||
resetQuery() {
|
|
||||||
this.dateRange = []
|
|
||||||
this.resetForm('queryForm')
|
|
||||||
this.handleQuery()
|
|
||||||
},
|
|
||||||
/** 新增按钮操作 */
|
|
||||||
handleAdd() {
|
|
||||||
this.reset()
|
|
||||||
this.open = true
|
|
||||||
this.title = '添加{{.TableComment}}'
|
|
||||||
this.isEdit = false
|
|
||||||
},
|
|
||||||
// 多选框选中数据
|
|
||||||
handleSelectionChange(selection) {
|
|
||||||
this.ids = selection.map(item => item.{{.PkJsonField}})
|
|
||||||
this.single = selection.length !== 1
|
|
||||||
this.multiple = !selection.length
|
|
||||||
},
|
|
||||||
/** 修改按钮操作 */
|
|
||||||
handleUpdate(row) {
|
|
||||||
this.reset()
|
|
||||||
const {{.PkJsonField}} =
|
|
||||||
row.{{.PkJsonField}} || this.ids
|
|
||||||
get{{.ClassName}}({{.PkJsonField}}).then(response => {
|
|
||||||
this.form = response.data
|
|
||||||
this.open = true
|
|
||||||
this.title = '修改{{.TableComment}}'
|
|
||||||
this.isEdit = true
|
|
||||||
})
|
|
||||||
},
|
|
||||||
/** 提交按钮 */
|
|
||||||
submitForm: function () {
|
|
||||||
this.$refs['form'].validate(valid => {
|
|
||||||
if (valid) {
|
|
||||||
if (this.form.{{.PkJsonField}} !== undefined) {
|
|
||||||
update{{.ClassName}}(this.form).then(response => {
|
|
||||||
if (response.code === 200) {
|
|
||||||
this.msgSuccess('修改成功')
|
|
||||||
this.open = false
|
|
||||||
this.getList()
|
|
||||||
} else {
|
|
||||||
this.msgError(response.msg)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
add{{.ClassName}}(this.form).then(response => {
|
|
||||||
if (response.code === 200) {
|
|
||||||
this.msgSuccess('新增成功')
|
|
||||||
this.open = false
|
|
||||||
this.getList()
|
|
||||||
} else {
|
|
||||||
this.msgError(response.msg)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
/** 删除按钮操作 */
|
|
||||||
handleDelete(row) {
|
|
||||||
var Ids = (row.{{.PkJsonField}} && [row.{{.PkJsonField}}]) || this.ids
|
|
||||||
if (this.ids.length === 0) {
|
|
||||||
Ids = [Ids]
|
|
||||||
}
|
|
||||||
this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', '警告', {
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning'
|
|
||||||
}).then(function () {
|
|
||||||
return del{{.ClassName}}( { 'ids': Ids })
|
|
||||||
}).then(() => {
|
|
||||||
this.getList()
|
|
||||||
this.msgSuccess('删除成功')
|
|
||||||
}).catch(function () {
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
Reference in new issue
Block a user