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

+4 -3
View File
@@ -30,17 +30,18 @@ data: data
// 修改{{.ClassName}}
export function update{{.ClassName}}(data) {
return request({
url: '/api/v1/{{.ModuleName}}',
url: '/api/v1/{{.ModuleName}}/'+data.{{.PkJsonField}},
method: 'put',
data: data
})
}
// 删除{{.ClassName}}
export function del{{.ClassName}}({{.PkJsonField}}) {
export function del{{.ClassName}}({{.PkJsonField}},data) {
return request({
url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}},
method: 'delete'
method: 'delete',
data: data
})
}
+7 -2
View File
@@ -1,8 +1,13 @@
package models
import (
orm "go-admin/global"
"go-admin/tools"
"strconv"
"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" -}}
@@ -5,18 +5,17 @@ import (
"go-admin/app/admin/models"
"go-admin/common/dto"
models2 "go-admin/common/models"
"net/http"
)
type {{.ClassName}}Search struct {
Pagination `search:"-"`
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}}"` // {{.ColumnComment}}
{{end -}}
{{ end -}}
{{- end }}
}
@@ -75,29 +74,16 @@ func (s *{{.ClassName}}Control) GenerateM() (models2.ActiveRecord, error) {
{{- else }}
{{.GoField}}: s.{{.GoField}},
{{- end }}
{{- end }}
}, nil
}
func (s *{{.ClassName}}Control) GetId() interface{} {
return s.{{.PkColumn}}
return s.{{.PkGoField}}
}
type {{.ClassName}}ById struct {
Id int `uri:"id" validate:"required"`
Ids []int `json:"ids"`
}
func (s *{{.ClassName}}ById) Bind(ctx *gin.Context) error {
if ctx.Request.Method == http.MethodDelete {
err := ctx.Bind(s)
if err != nil {
return err
}
if len(s.Ids) > 0 {
return nil
}
}
return ctx.BindUri(s)
dto.ObjectById
}
func (s *{{.ClassName}}ById) Generate() dto.Control {
@@ -107,11 +93,4 @@ func (s *{{.ClassName}}ById) Generate() dto.Control {
func (s *{{.ClassName}}ById) GenerateM() (models2.ActiveRecord, error) {
return &models.{{.ClassName}}{}, nil
}
func (s *{{.ClassName}}ById) GetId() interface{} {
if len(s.Ids) > 0 {
return s.Ids
}
return s.Id
}
}
@@ -1,14 +1,17 @@
package models
import (
"strconv"
{{- if eq .IsActions true -}}
{{- else }}
"go-admin/common/dto"
orm "go-admin/common/global"
"go-admin/common/models"
"go-admin/tools"
"strconv"
orm "go-admin/common/global"
{{ end }}
"go-admin/common/models"
)
type SysJob struct {
type {{.ClassName}} struct {
{{ range .Columns -}}
{{$x := .Pk}}
{{- if ($x) }}
@@ -34,7 +37,7 @@ func (e *{{.ClassName}}) Generate() models.ActiveRecord {
}
func (e *{{.ClassName}}) GetId() interface{} {
return e.{{.PkColumn}}
return e.{{.PkGoField}}
}
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
@@ -3,7 +3,6 @@ package router
import (
"github.com/gin-gonic/gin"
"go-admin/apis/{{.ModuleName}}"
"go-admin/app/admin/middleware"
"go-admin/app/admin/models"
"go-admin/app/admin/service/dto"
@@ -26,7 +25,7 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW
}))
r.GET("/:id", actions.PermissionAction(), actions.ViewAction(new(dto.{{.ClassName}}ById)))
r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
r.PUT("", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control)))
r.PUT("/:id", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control)))
r.DELETE("/:id", actions.PermissionAction(), actions.DeleteAction(new(dto.{{.ClassName}}ById)))
}
}
@@ -3,7 +3,10 @@ package router
import (
"github.com/gin-gonic/gin"
"go-admin/apis/{{.ModuleName}}"
"go-admin/app/admin/middleware"
"go-admin/app/admin/models"
"go-admin/app/admin/service/dto"
"go-admin/common/actions"
)
// 无需认证的路由代码
@@ -17,7 +20,7 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
}))
r.GET("/:id", actions.ViewAction(new(dto.{{.ClassName}}ById)))
r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
r.PUT("", actions.UpdateAction(new(dto.{{.ClassName}}Control)))
r.PUT("/:id", actions.UpdateAction(new(dto.{{.ClassName}}Control)))
r.DELETE("/:id", actions.DeleteAction(new(dto.{{.ClassName}}ById)))
}
}
+6 -2
View File
@@ -215,7 +215,7 @@
</template>
<script>
import {add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}}} from '@/api/{{ .PackageName}}'
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}}'
@@ -428,7 +428,11 @@
cancelButtonText: '取消',
type: 'warning'
}).then(function () {
return del{{.ClassName}}(Ids)
if (Ids.length > 1) {
return del{{.ClassName}}(Ids.shift(), { 'ids': Ids })
} else {
return del{{.ClassName}}(Ids, { 'ids': [] })
}
}).then(() => {
this.getList()
this.msgSuccess('删除成功')