feat: add Go backend
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
// Package @{.varName | ToLower}
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) @{NowYear} HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version @{.hgVersion}
|
||||
//
|
||||
package @{.varName | ToLower}
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"@{.importInput}"
|
||||
"hotgo/internal/model/input/form"
|
||||
@{ if eq .options.Step.IsTreeTable true }"hotgo/utility/tree"@{end}
|
||||
)
|
||||
|
||||
// ListReq 查询@{.tableComment}列表
|
||||
type ListReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/list" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}列表"`
|
||||
@{.templateGroup}in.@{.varName}ListInp
|
||||
}
|
||||
|
||||
type ListRes struct {
|
||||
form.PageRes
|
||||
List []*@{.templateGroup}in.@{.varName}ListModel `json:"list" dc:"数据列表"`
|
||||
}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// ExportReq 导出@{.tableComment}列表
|
||||
type ExportReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/export" method:"get" tags:"@{.tableComment}" summary:"导出@{.tableComment}列表"`
|
||||
@{.templateGroup}in.@{.varName}ListInp
|
||||
}
|
||||
|
||||
type ExportRes struct{}
|
||||
@{end}
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
// ViewReq 获取@{.tableComment}指定信息
|
||||
type ViewReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/view" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}指定信息"`
|
||||
@{.templateGroup}in.@{.varName}ViewInp
|
||||
}
|
||||
|
||||
type ViewRes struct {
|
||||
*@{.templateGroup}in.@{.varName}ViewModel
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// EditReq 修改/新增@{.tableComment}
|
||||
type EditReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/edit" method:"post" tags:"@{.tableComment}" summary:"修改/新增@{.tableComment}"`
|
||||
@{.templateGroup}in.@{.varName}EditInp
|
||||
}
|
||||
|
||||
type EditRes struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
// DeleteReq 删除@{.tableComment}
|
||||
type DeleteReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/delete" method:"post" tags:"@{.tableComment}" summary:"删除@{.tableComment}"`
|
||||
@{.templateGroup}in.@{.varName}DeleteInp
|
||||
}
|
||||
|
||||
type DeleteRes struct{}
|
||||
@{end}
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
// MaxSortReq 获取@{.tableComment}最大排序
|
||||
type MaxSortReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/maxSort" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}最大排序"`
|
||||
@{.templateGroup}in.@{.varName}MaxSortInp
|
||||
}
|
||||
|
||||
type MaxSortRes struct {
|
||||
*@{.templateGroup}in.@{.varName}MaxSortModel
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
// StatusReq 更新@{.tableComment}状态
|
||||
type StatusReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/status" method:"post" tags:"@{.tableComment}" summary:"更新@{.tableComment}状态"`
|
||||
@{.templateGroup}in.@{.varName}StatusInp
|
||||
}
|
||||
|
||||
type StatusRes struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
// SwitchReq 更新@{.tableComment}开关状态
|
||||
type SwitchReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/switch" method:"post" tags:"@{.tableComment}" summary:"更新@{.tableComment}状态"`
|
||||
@{.templateGroup}in.@{.varName}SwitchInp
|
||||
}
|
||||
|
||||
type SwitchRes struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// TreeOptionReq 获取@{.tableComment}关系树选项
|
||||
type TreeOptionReq struct {
|
||||
g.Meta `path:"/@{.varName | LcFirst}/treeOption" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}关系树选项"`
|
||||
}
|
||||
|
||||
type TreeOptionRes []tree.Node
|
||||
@{end}
|
||||
@@ -0,0 +1,118 @@
|
||||
// Package @{.templateGroup}
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) @{NowYear} HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version @{.hgVersion}
|
||||
//
|
||||
package @{.templateGroup}
|
||||
|
||||
import (
|
||||
"context"
|
||||
"@{.importApi}"
|
||||
"hotgo/internal/model/input/form"
|
||||
"@{.importInput}"
|
||||
"@{.importService}"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
var (
|
||||
@{.varName} = c@{.varName}{}
|
||||
)
|
||||
|
||||
type c@{.varName} struct{}
|
||||
|
||||
// List 查看@{.tableComment}列表
|
||||
func (c *c@{.varName}) List(ctx context.Context, req *@{.varName | ToLower}.ListReq) (res *@{.varName | ToLower}.ListRes, err error) {
|
||||
list, totalCount, err := service.@{.servFunName}().List(ctx, &req.@{.varName}ListInp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if list == nil {
|
||||
list = []*@{.templateGroup}in.@{.varName}ListModel{}
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.ListRes)
|
||||
res.List = list
|
||||
res.PageRes.Pack(req, totalCount)
|
||||
return
|
||||
}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// Export 导出@{.tableComment}列表
|
||||
func (c *c@{.varName}) Export(ctx context.Context, req *@{.varName | ToLower}.ExportReq) (res *@{.varName | ToLower}.ExportRes, err error) {
|
||||
err = service.@{.servFunName}().Export(ctx, &req.@{.varName}ListInp)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// Edit 更新@{.tableComment}
|
||||
func (c *c@{.varName}) Edit(ctx context.Context, req *@{.varName | ToLower}.EditReq) (res *@{.varName | ToLower}.EditRes, err error) {
|
||||
err = service.@{.servFunName}().Edit(ctx, &req.@{.varName}EditInp)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
// MaxSort 获取@{.tableComment}最大排序
|
||||
func (c *c@{.varName}) MaxSort(ctx context.Context, req *@{.varName | ToLower}.MaxSortReq) (res *@{.varName | ToLower}.MaxSortRes, err error) {
|
||||
data, err := service.@{.servFunName}().MaxSort(ctx, &req.@{.varName}MaxSortInp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.MaxSortRes)
|
||||
res.@{.varName}MaxSortModel = data
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
// View 获取指定@{.tableComment}信息
|
||||
func (c *c@{.varName}) View(ctx context.Context, req *@{.varName | ToLower}.ViewReq) (res *@{.varName | ToLower}.ViewRes, err error) {
|
||||
data, err := service.@{.servFunName}().View(ctx, &req.@{.varName}ViewInp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.ViewRes)
|
||||
res.@{.varName}ViewModel = data
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
// Delete 删除@{.tableComment}
|
||||
func (c *c@{.varName}) Delete(ctx context.Context, req *@{.varName | ToLower}.DeleteReq) (res *@{.varName | ToLower}.DeleteRes, err error) {
|
||||
err = service.@{.servFunName}().Delete(ctx, &req.@{.varName}DeleteInp)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
// Status 更新@{.tableComment}状态
|
||||
func (c *c@{.varName}) Status(ctx context.Context, req *@{.varName | ToLower}.StatusReq) (res *@{.varName | ToLower}.StatusRes, err error) {
|
||||
err = service.@{.servFunName}().Status(ctx, &req.@{.varName}StatusInp)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
// Switch 更新@{.tableComment}开关状态
|
||||
func (c *c@{.varName}) Switch(ctx context.Context, req *@{.varName | ToLower}.SwitchReq) (res *@{.varName | ToLower}.SwitchRes, err error) {
|
||||
err = service.@{.servFunName}().Switch(ctx, &req.@{.varName}SwitchInp)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// TreeOption 获取@{.tableComment}关系树选项
|
||||
func (c *c@{.varName}) TreeOption(ctx context.Context, req *@{.varName | ToLower}.TreeOptionReq) (res *@{.varName | ToLower}.TreeOptionRes, err error) {
|
||||
data, err := service.@{.servFunName}().TreeOption(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(data) > 0 {
|
||||
res = (*@{.varName | ToLower}.TreeOptionRes)(&data)
|
||||
} else {
|
||||
temp := make(@{.varName | ToLower}.TreeOptionRes, 0)
|
||||
res = &temp
|
||||
}
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@@ -0,0 +1,167 @@
|
||||
// Package @{.templateGroup}in
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) @{NowYear} HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version @{.hgVersion}
|
||||
//
|
||||
package @{.templateGroup}in
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/utility/validate"
|
||||
@{ if eq .options.Step.HasHookMemberSummary true }"hotgo/internal/library/hgorm/hook"@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }"hotgo/utility/tree"@{end}
|
||||
)
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// @{.varName}UpdateFields 修改@{.tableComment}字段过滤
|
||||
type @{.varName}UpdateFields struct {
|
||||
@{.updateFieldsColumns}
|
||||
}
|
||||
|
||||
// @{.varName}InsertFields 新增@{.tableComment}字段过滤
|
||||
type @{.varName}InsertFields struct {
|
||||
@{.insertFieldsColumns}
|
||||
}
|
||||
|
||||
// @{.varName}EditInp 修改/新增@{.tableComment}
|
||||
type @{.varName}EditInp struct {
|
||||
entity.@{.daoName}
|
||||
}
|
||||
|
||||
func (in *@{.varName}EditInp) Filter(ctx context.Context) (err error) {
|
||||
@{.editInpValidator}
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}EditModel struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
// @{.varName}DeleteInp 删除@{.tableComment}
|
||||
type @{.varName}DeleteInp struct {
|
||||
@{.pk.GoName} interface{} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}DeleteInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}DeleteModel struct{}
|
||||
@{end}
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
// @{.varName}ViewInp 获取指定@{.tableComment}信息
|
||||
type @{.varName}ViewInp struct {
|
||||
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}ViewInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}ViewModel struct {
|
||||
@{.viewModelColumns}
|
||||
}@{end}
|
||||
|
||||
// @{.varName}ListInp 获取@{.tableComment}列表
|
||||
type @{.varName}ListInp struct {
|
||||
form.PageReq
|
||||
@{.listInpColumns}
|
||||
}
|
||||
|
||||
func (in *@{.varName}ListInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}ListModel struct {
|
||||
@{.listModelColumns}
|
||||
}
|
||||
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// @{.varName}ExportModel 导出@{.tableComment}
|
||||
type @{.varName}ExportModel struct {
|
||||
@{.exportModelColumns}
|
||||
}@{end}
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
// @{.varName}MaxSortInp 获取@{.tableComment}最大排序
|
||||
type @{.varName}MaxSortInp struct{}
|
||||
|
||||
func (in *@{.varName}MaxSortInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}MaxSortModel struct {
|
||||
Sort int `json:"sort" description:"排序"`
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
// @{.varName}StatusInp 更新@{.tableComment}状态
|
||||
type @{.varName}StatusInp struct {
|
||||
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
Status int `json:"status" dc:"状态"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}StatusInp) Filter(ctx context.Context) (err error) {
|
||||
if in.@{.pk.GoName} <= 0 {
|
||||
err = gerror.New("@{.pk.Dc}不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSlice(consts.StatusSlice, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}StatusModel struct{}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
// @{.varName}SwitchInp 更新@{.tableComment}开关状态
|
||||
type @{.varName}SwitchInp struct {
|
||||
form.SwitchReq
|
||||
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
|
||||
}
|
||||
|
||||
func (in *@{.varName}SwitchInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type @{.varName}SwitchModel struct{}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// @{.varName}TreeOption 关系树选项
|
||||
type @{.varName}TreeOption struct {
|
||||
@{.treeOptionFields}
|
||||
Children []tree.Node `json:"children" dc:"子节点"`
|
||||
}
|
||||
|
||||
// ID 获取节点ID
|
||||
func (t *@{.varName}TreeOption) ID() int64 {
|
||||
return t.@{.pk.GoName}
|
||||
}
|
||||
|
||||
// PID 获取父级节点ID
|
||||
func (t *@{.varName}TreeOption) PID() int64 {
|
||||
return t.Pid
|
||||
}
|
||||
|
||||
// SetChildren 设置子节点数据
|
||||
func (t *@{.varName}TreeOption) SetChildren(children []tree.Node) {
|
||||
t.Children = children
|
||||
}
|
||||
@{end}
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
// Package @{.templateGroup}
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) @{NowYear} HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version @{.hgVersion}
|
||||
//
|
||||
package @{.templateGroup}
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/hgorm"
|
||||
"hotgo/internal/library/hgorm/handler"
|
||||
"hotgo/internal/library/hgorm/hook"
|
||||
"@{.importInput}"
|
||||
"hotgo/internal/model/input/form"
|
||||
"@{.importService}"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/excel"
|
||||
"hotgo/utility/validate"
|
||||
@{ if eq .options.Step.IsAddon true }isc "hotgo/internal/service"@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }"hotgo/utility/tree"@{end}
|
||||
@{ if eq .options.Step.HasFuncDict true }"hotgo/internal/library/dict"@{end}
|
||||
@{ if and (eq .options.Step.HasFuncDict true) (eq .options.Step.IsAddon false) }"hotgo/internal/model"@{end}
|
||||
@{ if and (eq .options.Step.HasFuncDict true) (eq .options.Step.IsAddon true) }imodel "hotgo/internal/model"@{end}
|
||||
)
|
||||
|
||||
type s@{.servFunName} struct{}
|
||||
|
||||
func New@{.servFunName}() *s@{.servFunName} {
|
||||
return &s@{.servFunName}{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.Register@{.servFunName}(New@{.servFunName}())
|
||||
@{ if eq .options.Step.HasFuncDict true }dict.RegisterFunc("@{.varName | LcFirst}Option", "@{.tableComment}选项", service.@{.servFunName}().Option)@{end}}
|
||||
|
||||
// Model @{.tableComment}ORM模型
|
||||
func (s *s@{.servFunName}) Model(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
return handler.Model(dao.@{.daoName}.Ctx(ctx), option...)
|
||||
}
|
||||
|
||||
// List 获取@{.tableComment}列表
|
||||
func (s *s@{.servFunName}) List(ctx context.Context, in *@{.templateGroup}in.@{.varName}ListInp) (list []*@{.templateGroup}in.@{.varName}ListModel, totalCount int, err error) {
|
||||
mod := s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end})
|
||||
|
||||
// 字段过滤
|
||||
@{.listFields}
|
||||
|
||||
@{ if ne .listJoin "" }
|
||||
// 关联表字段
|
||||
@{.listJoin}
|
||||
@{end}
|
||||
|
||||
@{.listWhere}
|
||||
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// 树形列表判断是否需要分页
|
||||
if in.Pagination {
|
||||
mod = mod.Page(in.Page, in.PerPage)
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.IsTreeTable false }
|
||||
// 分页
|
||||
mod = mod.Page(in.Page, in.PerPage)
|
||||
@{end}
|
||||
|
||||
// 排序
|
||||
mod = mod.@{.listOrder}
|
||||
|
||||
@{ if eq .options.Step.HasHookMemberSummary true }
|
||||
// 操作人摘要信息
|
||||
mod = mod.Hook(hook.MemberSummary)
|
||||
@{end}
|
||||
|
||||
// 查询数据
|
||||
if err = mod.ScanAndCount(&list, &totalCount, false);err != nil {
|
||||
err = gerror.Wrap(err, "获取@{.tableComment}列表失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// Export 导出@{.tableComment}
|
||||
func (s *s@{.servFunName}) Export(ctx context.Context, in *@{.templateGroup}in.@{.varName}ListInp) (err error) {
|
||||
list, totalCount, err := s.List(ctx, in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...}
|
||||
tags, err := convert.GetEntityDescTags(@{.templateGroup}in.@{.varName}ExportModel{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
fileName = "导出@{.tableComment}-" + gctx.CtxId(ctx)
|
||||
sheetName = fmt.Sprintf("索引条件共%v行,共%v页,当前导出是第%v页,本页共%v行", totalCount, form.CalPageCount(totalCount, in.PerPage), in.Page, len(list))
|
||||
exports []@{.templateGroup}in.@{.varName}ExportModel
|
||||
)
|
||||
|
||||
if err = gconv.Scan(list, &exports);err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName)
|
||||
return
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// Edit 修改/新增@{.tableComment}
|
||||
func (s *s@{.servFunName}) Edit(ctx context.Context, in *@{.templateGroup}in.@{.varName}EditInp) (err error) {
|
||||
@{.edit.unique}@{.edit.validation} return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
||||
@{ if eq .options.Step.IsTreeTable true }in.Pid, in.Level, in.Tree, err = hgorm.AutoUpdateTree(ctx, &dao.@{.daoName}, in.@{.pk.GoName}, in.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}@{end}
|
||||
// 修改
|
||||
if in.@{.pk.GoName} > 0 {
|
||||
@{.edit.update}
|
||||
}
|
||||
|
||||
// 新增
|
||||
@{.edit.insert}
|
||||
return
|
||||
})
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
// Delete 删除@{.tableComment}
|
||||
func (s *s@{.servFunName}) Delete(ctx context.Context, in *@{.templateGroup}in.@{.varName}DeleteInp) (err error) {
|
||||
@{ if eq .options.Step.IsTreeTable true }count, err := dao.@{.daoName}.Ctx(ctx).Where(dao.@{.daoName}.Columns().Pid, in.@{.pk.GoName}).Count()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return gerror.New("请先删除该@{.tableComment}下的所有下级!")
|
||||
}@{end}
|
||||
@{ if eq .deletedUpdate "" }
|
||||
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Unscoped().Delete();err != nil {
|
||||
err = gerror.Wrap(err, "删除@{.tableComment}失败,请稍后重试!")
|
||||
return
|
||||
}@{else}
|
||||
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Data(@{.deletedUpdate}).Unscoped().Update();err != nil {
|
||||
err = gerror.Wrap(err, "删除@{.tableComment}失败,请稍后重试!")
|
||||
return
|
||||
}@{end}
|
||||
return
|
||||
}@{end}
|
||||
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
// MaxSort 获取@{.tableComment}最大排序
|
||||
func (s *s@{.servFunName}) MaxSort(ctx context.Context, in *@{.templateGroup}in.@{.varName}MaxSortInp) (res *@{.templateGroup}in.@{.varName}MaxSortModel, err error) {
|
||||
if err = dao.@{.daoName}.Ctx(ctx).Fields(dao.@{.daoName}.Columns().Sort).OrderDesc(dao.@{.daoName}.Columns().Sort).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, "获取@{.tableComment}最大排序,请稍后重试!")
|
||||
return
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
res = new(@{.templateGroup}in.@{.varName}MaxSortModel)
|
||||
}
|
||||
|
||||
res.Sort = form.DefaultMaxSort(res.Sort)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
// View 获取@{.tableComment}指定信息
|
||||
func (s *s@{.servFunName}) View(ctx context.Context, in *@{.templateGroup}in.@{.varName}ViewInp) (res *@{.templateGroup}in.@{.varName}ViewModel, err error) {
|
||||
if err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName})@{ if eq .options.Step.HasHookMemberSummary true }.Hook(hook.MemberSummary)@{end}.Scan(&res);err != nil {
|
||||
err = gerror.Wrap(err, "获取@{.tableComment}信息,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
// Status 更新@{.tableComment}状态
|
||||
func (s *s@{.servFunName}) Status(ctx context.Context, in *@{.templateGroup}in.@{.varName}StatusInp) (err error) {
|
||||
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Data(@{.statusUpdate}).Update();err != nil {
|
||||
err = gerror.Wrap(err, "更新@{.tableComment}状态失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
// Switch 更新@{.tableComment}开关
|
||||
func (s *s@{.servFunName}) Switch(ctx context.Context, in *@{.templateGroup}in.@{.varName}SwitchInp) (err error) {
|
||||
var fields = []string{
|
||||
@{.switchFields} // ...
|
||||
}
|
||||
|
||||
if !validate.InSlice(fields, in.Key) {
|
||||
err = gerror.New("开关键名不在白名单")
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Data(@{.switchUpdate}).Update();err != nil {
|
||||
err = gerror.Wrap(err, "更新@{.tableComment}开关失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// TreeOption 获取@{.tableComment}关系树选项
|
||||
func (s *s@{.servFunName}) TreeOption(ctx context.Context) (nodes []tree.Node, err error) {
|
||||
var models []*@{.templateGroup}in.@{.varName}TreeOption
|
||||
if err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).Fields(@{.templateGroup}in.@{.varName}TreeOption{}).OrderAsc(dao.@{.daoName}.Columns().Pid).@{.listOrder}.Scan(&models); err != nil {
|
||||
err = gerror.Wrap(err, "获取@{.tableComment}关系树选项失败!")
|
||||
return
|
||||
}
|
||||
nodes = make([]tree.Node, len(models))
|
||||
for i, v := range models {
|
||||
nodes[i] = v
|
||||
}
|
||||
return tree.ListToTree(0, nodes)
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasFuncDict true }
|
||||
// Option 获取@{.tableComment}选项
|
||||
func (s *s@{.servFunName}) Option(ctx context.Context) (opts []*@{ if eq .options.Step.IsAddon false }model@{end}@{ if eq .options.Step.IsAddon true }imodel@{end}.Option, err error) {
|
||||
var models []*entity.@{.daoName}
|
||||
if err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).Fields(dao.@{.daoName}.Columns().@{.options.FuncDict.Value.GoName},dao.@{.daoName}.Columns().@{.options.FuncDict.Label.GoName}).
|
||||
@{.listOrder}.Scan(&models); err != nil {
|
||||
err = gerror.Wrap(err, "获取@{.tableComment}选项失败!")
|
||||
return
|
||||
}
|
||||
|
||||
opts = make([]*@{ if eq .options.Step.IsAddon false }model@{end}@{ if eq .options.Step.IsAddon true }imodel@{end}.Option, len(models))
|
||||
for k, v := range models {
|
||||
opts[k] = dict.GenHashOption(v.@{.options.FuncDict.Value.GoName}, gconv.String(v.@{.options.FuncDict.Label.GoName}))
|
||||
}
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Package genrouter
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) @{NowYear} HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version @{.hgVersion}
|
||||
//
|
||||
package genrouter
|
||||
|
||||
import "@{.importController}"
|
||||
|
||||
func init() {
|
||||
LoginRequiredRouter = append(LoginRequiredRouter, @{.templateGroup}.@{.varName}) // @{.tableComment}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
-- hotgo自动生成菜单权限SQL 通常情况下只在首次生成代码时自动执行一次
|
||||
-- 如需再次执行请先手动删除生成的菜单权限和SQL文件:@{.generatePath}
|
||||
-- Version: @{.hgVersion}
|
||||
-- Date: @{.nowTime}
|
||||
-- Link https://github.com/bufanyun/hotgo
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET AUTOCOMMIT = 0;
|
||||
START TRANSACTION;
|
||||
|
||||
--
|
||||
-- 数据库: `@{.dbName}`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- 插入表中的数据 `@{.menuTable}`
|
||||
--
|
||||
|
||||
|
||||
SET @now := now();
|
||||
|
||||
|
||||
-- 菜单目录
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, '@{.options.Menu.Pid}', '@{.tableComment}', '@{.varName | LcFirst}', '/@{.varName | LcFirst}', '@{.options.Menu.Icon}', '1', '@{.pageRedirect}', '', '', '@{.mainComponent}', '1', '', '0', '0', '', '0', '0', '0', '@{.dirLevel}', '@{.dirTree}', '@{.options.Menu.Sort}', '', '1', @now, @now);
|
||||
|
||||
|
||||
SET @dirId = LAST_INSERT_ID();
|
||||
|
||||
|
||||
-- 菜单页面
|
||||
-- 列表
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @dirId, '@{.tableComment}列表', '@{.varName | LcFirst}Index', 'index', '', '2', '', '/@{.apiPrefix}/list', '', '/@{.componentPrefix}/index', '1', '@{.varName | LcFirst}', '0', '0', '', '0', '1', '0', '@{.listLevel}', CONCAT('@{.dirTree}tr_', @dirId,' '), '10', '', '1', @now, @now);
|
||||
|
||||
|
||||
SET @listId = LAST_INSERT_ID();
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
-- 详情
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '@{.tableComment}详情', '@{.varName | LcFirst}View', '', '', '3', '', '/@{.apiPrefix}/view', '', '', '1', '', '0', '0', '', '0', '1', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '10', '', '1', @now, @now);
|
||||
@{end}
|
||||
|
||||
-- 菜单按钮
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
-- 编辑
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '编辑/新增@{.tableComment}', '@{.varName | LcFirst}Edit', '', '', '3', '', '/@{.apiPrefix}/edit', '', '', '1', '', '0', '0', '', '0', '1', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '20', '', '1', @now, @now);
|
||||
@{end}
|
||||
|
||||
SET @editId = LAST_INSERT_ID();
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
-- 获取最大排序
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @editId, '获取@{.tableComment}最大排序', '@{.varName | LcFirst}MaxSort', '', '', '3', '', '/@{.apiPrefix}/maxSort', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.sortLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId, ' tr_', @editId,' '), '30', '', '1', @now, @now);
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
-- 删除
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '删除@{.tableComment}', '@{.varName | LcFirst}Delete', '', '', '3', '', '/@{.apiPrefix}/delete', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '40', '', '1', @now, @now);
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
-- 更新状态
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '修改@{.tableComment}状态', '@{.varName | LcFirst}Status', '', '', '3', '', '/@{.apiPrefix}/status', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '50', '', '1', @now, @now);
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
-- 操作开关
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '操作@{.tableComment}开关', '@{.varName | LcFirst}Switch', '', '', '3', '', '/@{.apiPrefix}/switch', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '60', '', '1', @now, @now);
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
-- 导出
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '导出@{.tableComment}', '@{.varName | LcFirst}Export', '', '', '3', '', '/@{.apiPrefix}/export', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '70', '', '1', @now, @now);
|
||||
@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
-- 关系树选项
|
||||
INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '获取@{.tableComment}关系树选项', '@{.varName | LcFirst}TreeOption', '', '', '3', '', '/@{.apiPrefix}/treeOption', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), '70', '', '1', @now, @now);
|
||||
@{end}
|
||||
COMMIT;
|
||||
@@ -0,0 +1,84 @@
|
||||
-- hotgo自动生成菜单权限SQL 通常情况下只在首次生成代码时自动执行一次
|
||||
-- 如需再次执行请先手动删除生成的菜单权限和SQL文件:@{.generatePath}
|
||||
-- Version: @{.hgVersion}
|
||||
-- Date: @{.nowTime}
|
||||
-- Link https://github.com/bufanyun/hotgo
|
||||
|
||||
--
|
||||
-- 数据库: "@{.dbName}"
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- 插入表中的数据 "@{.menuTable}"
|
||||
--
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
dir_id bigint;
|
||||
list_id bigint;
|
||||
edit_id bigint;
|
||||
BEGIN
|
||||
-- 菜单目录
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES ('@{.options.Menu.Pid}', '@{.tableComment}', '@{.varName | LcFirst}', '/@{.varName | LcFirst}', '@{.options.Menu.Icon}', '1', '@{.pageRedirect}', '', '', '@{.mainComponent}', '1', '', '0', '0', '', '0', '0', '0', '@{.dirLevel}', '@{.dirTree}', '@{.options.Menu.Sort}', '', '1', now(), now())
|
||||
RETURNING id INTO dir_id;
|
||||
|
||||
-- 菜单页面
|
||||
-- 列表
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (dir_id, '@{.tableComment}列表', '@{.varName | LcFirst}Index', 'index', '', '2', '', '/@{.apiPrefix}/list', '', '/@{.componentPrefix}/index', '1', '@{.varName | LcFirst}', '0', '0', '', '0', '1', '0', '@{.listLevel}', '@{.dirTree}tr_' || dir_id || ' ', '10', '', '1', now(), now())
|
||||
RETURNING id INTO list_id;
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
|
||||
-- 详情
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '@{.tableComment}详情', '@{.varName | LcFirst}View', '', '', '3', '', '/@{.apiPrefix}/view', '', '', '1', '', '0', '0', '', '0', '1', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '10', '', '1', now(), now());
|
||||
@{end}
|
||||
|
||||
-- 菜单按钮
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
-- 编辑
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '编辑/新增@{.tableComment}', '@{.varName | LcFirst}Edit', '', '', '3', '', '/@{.apiPrefix}/edit', '', '', '1', '', '0', '0', '', '0', '1', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '20', '', '1', now(), now())
|
||||
RETURNING id INTO edit_id;
|
||||
@{end}
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
|
||||
|
||||
-- 获取最大排序
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (edit_id, '获取@{.tableComment}最大排序', '@{.varName | LcFirst}MaxSort', '', '', '3', '', '/@{.apiPrefix}/maxSort', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.sortLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' tr_' || edit_id || ' ', '30', '', '1', now(), now());
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
|
||||
-- 删除
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '删除@{.tableComment}', '@{.varName | LcFirst}Delete', '', '', '3', '', '/@{.apiPrefix}/delete', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '40', '', '1', now(), now());
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
|
||||
-- 更新状态
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '修改@{.tableComment}状态', '@{.varName | LcFirst}Status', '', '', '3', '', '/@{.apiPrefix}/status', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '50', '', '1', now(), now());
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
|
||||
-- 操作开关
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '操作@{.tableComment}开关', '@{.varName | LcFirst}Switch', '', '', '3', '', '/@{.apiPrefix}/switch', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '60', '', '1', now(), now());
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
|
||||
-- 导出
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '导出@{.tableComment}', '@{.varName | LcFirst}Export', '', '', '3', '', '/@{.apiPrefix}/export', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '70', '', '1', now(), now());
|
||||
@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
|
||||
-- 关系树选项
|
||||
INSERT INTO "@{.menuTable}" ("pid", "title", "name", "path", "icon", "type", "redirect", "permissions", "permission_name", "component", "always_show", "active_menu", "is_root", "is_frame", "frame_src", "keep_alive", "hidden", "affix", "level", "tree", "sort", "remark", "status", "created_at", "updated_at")
|
||||
VALUES (list_id, '获取@{.tableComment}关系树选项', '@{.varName | LcFirst}TreeOption', '', '', '3', '', '/@{.apiPrefix}/treeOption', '', '', '1', '', '0', '0', '', '0', '0', '0', '@{.btnLevel}', '@{.dirTree}tr_' || dir_id || ' tr_' || list_id || ' ', '70', '', '1', now(), now());
|
||||
@{end}
|
||||
END $$;
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { http, jumpExport } from '@/utils/http/axios';
|
||||
|
||||
// 获取@{.tableComment}列表
|
||||
export function List(params) {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/list',
|
||||
method: 'get',
|
||||
params,
|
||||
});
|
||||
}
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
// 删除/批量删除@{.tableComment}
|
||||
export function Delete(params) {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/delete',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// 添加/编辑@{.tableComment}
|
||||
export function Edit(params) {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/edit',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
// 修改@{.tableComment}状态
|
||||
export function Status(params) {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/status',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
// 操作@{.tableComment}开关
|
||||
export function Switch(params) {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/switch',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
|
||||
// 获取@{.tableComment}指定详情
|
||||
export function View(params) {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/view',
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasMaxSort true }
|
||||
// 获取@{.tableComment}最大排序
|
||||
export function MaxSort() {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/maxSort',
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// 导出@{.tableComment}
|
||||
export function Export(params) {
|
||||
jumpExport('/@{.apiPrefix}/export', params);
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// 获取@{.tableComment}关系树选项
|
||||
export function TreeOption() {
|
||||
return http.request({
|
||||
url: '/@{.apiPrefix}/treeOption',
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-modal
|
||||
v-model:show="showModal"
|
||||
:mask-closable="false"
|
||||
:show-icon="false"
|
||||
preset="dialog"
|
||||
transform-origin="center"
|
||||
:title="formValue.@{.pk.TsName} > 0 ? '编辑@{.tableComment} #' + formValue.@{.pk.TsName} : '添加@{.tableComment}'"
|
||||
:style="{
|
||||
width: dialogWidth,
|
||||
}"
|
||||
>
|
||||
<n-scrollbar style="max-height: 87vh" class="pr-5">
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-form
|
||||
ref="formRef"
|
||||
:model="formValue"
|
||||
@{ if eq .options.Step.HasRules true }:rules="rules"@{end}
|
||||
:label-placement="settingStore.isMobile ? 'top' : 'left'"
|
||||
:label-width="100"
|
||||
class="py-4"
|
||||
>
|
||||
<n-grid
|
||||
cols="1 s:1 m:@{.options.PresetStep.FormGridCols} l:@{.options.PresetStep.FormGridCols} xl:@{.options.PresetStep.FormGridCols} 2xl:@{.options.PresetStep.FormGridCols}"
|
||||
responsive="screen"
|
||||
>
|
||||
@{.formItem}
|
||||
</n-grid>
|
||||
</n-form>
|
||||
</n-spin>
|
||||
</n-scrollbar>
|
||||
<template #action>
|
||||
<n-space>
|
||||
<n-button @click="closeForm"> 取消 </n-button>
|
||||
<n-button type="info" :loading="formBtnLoading" :disabled="!isFormValid" @click="confirmForm"> 确定 </n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@{.script.import} import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
|
||||
const emit = defineEmits(['reloadTable']);
|
||||
const message = useMessage();
|
||||
const settingStore = useProjectSettingStore();
|
||||
@{ if eq .options.DictOps.Has true }const dict = useDictStore();@{end}
|
||||
const loading = ref(false);
|
||||
const showModal = ref(false);
|
||||
const formValue = ref<State>(newState(null));
|
||||
const formRef = ref<any>({});
|
||||
const formBtnLoading = ref(false);
|
||||
const dialogWidth = computed(() => {
|
||||
return adaModalWidth(840);
|
||||
});
|
||||
@{.script.setup}
|
||||
// 提交表单
|
||||
function confirmForm(e) {
|
||||
e.preventDefault();
|
||||
formRef.value.validate((errors) => {
|
||||
if (!errors) {
|
||||
formBtnLoading.value = true;
|
||||
Edit(formValue.value)
|
||||
.then((_res) => {
|
||||
message.success('操作成功');
|
||||
closeForm();
|
||||
emit('reloadTable');
|
||||
})
|
||||
.finally(() => {
|
||||
formBtnLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
message.error('请填写完整信息');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭表单
|
||||
function closeForm() {
|
||||
showModal.value = false;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function openModal(state: State) {
|
||||
showModal.value = true;
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// 加载关系树选项
|
||||
loadTreeOption();
|
||||
@{end}
|
||||
// 新增
|
||||
if (!state || state.@{.pk.TsName} < 1) {
|
||||
formValue.value = newState(state);
|
||||
@{ if eq .options.Step.HasMaxSort true }
|
||||
loading.value = true;
|
||||
MaxSort()
|
||||
.then((res) => {
|
||||
formValue.value.sort = res.sort;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});@{end}
|
||||
return;
|
||||
}
|
||||
|
||||
// 编辑
|
||||
loading.value = true;
|
||||
View({ @{.pk.TsName}: state.@{.pk.TsName} })
|
||||
.then((res) => {
|
||||
formValue.value = res;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less"></style>
|
||||
|
||||
@@ -0,0 +1,528 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="n-layout-page-header">
|
||||
<n-card :bordered="false" title="@{.tableComment}">
|
||||
<!-- 这是由系统生成的CURD表格,你可以将此行注释改为表格的描述 -->
|
||||
</n-card>
|
||||
</div>
|
||||
|
||||
@{ if eq .options.Step.IsOptionTreeTable false }<n-card :bordered="false" class="proCard">@{end}
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }
|
||||
<n-grid cols="1 s:1 m:1 l:4 xl:4 2xl:4" responsive="screen" :x-gap="12">
|
||||
<n-gi span="1">
|
||||
<n-card :segmented="{ content: true }" :bordered="false" size="small" class="proCard">
|
||||
<template #header>
|
||||
<n-space>
|
||||
@{ if eq .options.Step.HasAdd true }
|
||||
<n-button type="info" icon-placement="left" @click="addTable" v-if="hasPermission(['/@{.apiPrefix}/edit'])">
|
||||
<template #icon>
|
||||
<div class="flex items-center">
|
||||
<n-icon size="14">
|
||||
<PlusOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
添加
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
<n-button
|
||||
v-if="hasPermission(['/@{.apiPrefix}/edit'])"
|
||||
type="info"
|
||||
icon-placement="left"
|
||||
@click="handleEdit(selectedState)"
|
||||
:disabled="selectedState.@{.pk.TsName} < 1"
|
||||
>
|
||||
<template #icon>
|
||||
<div class="flex items-center">
|
||||
<n-icon size="14">
|
||||
<EditOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
编辑
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasBatchDel true }
|
||||
<n-button
|
||||
v-if="hasPermission(['/@{.apiPrefix}/delete'])"
|
||||
type="error"
|
||||
icon-placement="left"
|
||||
@click="handleDelete(selectedState)"
|
||||
:disabled="selectedState.@{.pk.TsName} < 1"
|
||||
>
|
||||
<template #icon>
|
||||
<div class="flex items-center">
|
||||
<n-icon size="14">
|
||||
<DeleteOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
删除
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
<n-button type="info" icon-placement="left" @click="handleAllExpanded">
|
||||
{{ expandedKeys.length ? '收起' : '展开' }}
|
||||
<template #icon>
|
||||
<div class="flex items-center">
|
||||
<n-icon size="14">
|
||||
<AlignLeftOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
<div class="w-full menu">
|
||||
<n-input v-model:value="pattern" placeholder="输入名称搜索">
|
||||
<template #suffix>
|
||||
<n-icon size="18" class="cursor-pointer">
|
||||
<SearchOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
</n-input>
|
||||
<div class="py-3 menu-list">
|
||||
<template v-if="loading">
|
||||
<div class="flex items-center justify-center py-4">
|
||||
<n-spin size="medium" />
|
||||
</div>
|
||||
</template>
|
||||
<n-tree
|
||||
v-else
|
||||
show-line
|
||||
block-line
|
||||
cascade
|
||||
virtual-scroll
|
||||
:pattern="pattern"
|
||||
:data="treeOption"
|
||||
:expandedKeys="expandedKeys"
|
||||
style="height: 75vh"
|
||||
key-field="@{.pk.TsName}"
|
||||
label-field="@{.options.Tree.TitleField.TsName}"
|
||||
@update:selected-keys="handleSelected"
|
||||
@update:expanded-keys="handleOnExpandedKeys"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</n-card>
|
||||
</n-gi>
|
||||
<n-gi span="3">
|
||||
<n-card :bordered="false" class="proCard">
|
||||
<template #header v-if="selectedState.@{.pk.TsName} > 0">
|
||||
<n-space>
|
||||
<n-icon size="18">
|
||||
<FormOutlined />
|
||||
</n-icon>
|
||||
<span>正在编辑 {{ selectedState.title }}</span>
|
||||
</n-space>
|
||||
</template>
|
||||
<n-result v-show="selectedState.@{.pk.TsName} < 1" status="info" title="提示" description="请先从列表选择一项后,进行编辑">
|
||||
<template #footer>
|
||||
<n-button
|
||||
type="info"
|
||||
icon-placement="left"
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }@click="handleAdd(selectedState)"
|
||||
@{end}@{ if eq .options.Step.IsOptionTreeTable false }@click="addTable"
|
||||
@{end}v-if="hasPermission(['/@{.apiPrefix}/edit'])"
|
||||
>
|
||||
<template #icon>
|
||||
<div class="flex items-center">
|
||||
<n-icon size="14">
|
||||
<PlusOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
添加
|
||||
</n-button>
|
||||
</template>
|
||||
</n-result>
|
||||
@{end}
|
||||
|
||||
@{ if eq .isSearchForm true }
|
||||
<BasicForm
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }v-if="selectedState.@{.pk.TsName} > 0"
|
||||
@{end}ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@keyup.enter="reloadTable"
|
||||
>
|
||||
<template #statusSlot="{ model, field }">
|
||||
<n-input v-model:value="model[field]" />
|
||||
</template>
|
||||
</BasicForm>
|
||||
@{end}
|
||||
|
||||
<BasicTable
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }v-if="selectedState.@{.pk.TsName} > 0"
|
||||
@{end}ref="actionRef"
|
||||
@{ if eq .options.Step.HasCheck true }openChecked
|
||||
@{end}:columns="columns"
|
||||
:request="loadDataTable"
|
||||
:row-key="(row) => row.@{.pk.TsName}"
|
||||
:actionColumn="actionColumn"
|
||||
:scroll-x="scrollX"
|
||||
:resizeHeightOffset="-10000"
|
||||
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable false) }:cascade="false"
|
||||
:expanded-row-keys="expandedKeys"
|
||||
@update:expanded-row-keys="updateExpandedKeys"
|
||||
@{end}@{ if eq .options.Step.HasCheck true }:checked-row-keys="checkedIds"
|
||||
@{end}@{ if eq .options.Step.HasCheck true }@update:checked-row-keys="handleOnCheckedRow"
|
||||
@{end}
|
||||
>
|
||||
<template #tableTitle>
|
||||
|
||||
@{ if eq .options.Step.HasAdd true }
|
||||
<n-button
|
||||
type="primary"
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }@click="handleAdd(selectedState)"
|
||||
@{end}@{ if eq .options.Step.IsOptionTreeTable false }@click="addTable"
|
||||
@{end}class="min-left-space"
|
||||
v-if="hasPermission(['/@{.apiPrefix}/edit'])"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<PlusOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
添加
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasBatchDel true }
|
||||
<n-button
|
||||
type="error"
|
||||
@click="handleBatchDelete"
|
||||
class="min-left-space"
|
||||
v-if="hasPermission(['/@{.apiPrefix}/delete'])"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<DeleteOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
批量删除
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
<n-button
|
||||
type="primary"
|
||||
@click="handleExport"
|
||||
class="min-left-space"
|
||||
v-if="hasPermission(['/@{.apiPrefix}/export'])"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<ExportOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
导出
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable false) }
|
||||
<n-button type="primary" icon-placement="left" @click="handleAllExpanded" class="min-left-space">
|
||||
全部{{ expandedKeys.length ? '收起' : '展开' }}
|
||||
<template #icon>
|
||||
<div class="flex items-center">
|
||||
<n-icon size="14">
|
||||
<AlignLeftOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
</n-button>
|
||||
@{end}
|
||||
|
||||
</template>
|
||||
</BasicTable>
|
||||
</n-card>
|
||||
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasEdit true } <Edit ref="editRef" @reloadTable="reloadTable" />@{end}
|
||||
@{ if eq .options.Step.HasView true } <View ref="viewRef" />@{end}
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@{.import}
|
||||
@{ if eq .options.DictOps.Has true }const dict = useDictStore();@{end}
|
||||
const dialog = useDialog();
|
||||
const message = useMessage();
|
||||
const { hasPermission } = usePermission();
|
||||
const actionRef = ref();
|
||||
const searchFormRef = ref<any>({});
|
||||
const editRef = ref();
|
||||
@{ if eq .options.Step.HasView true }const viewRef = ref();@{end}
|
||||
@{ if eq .options.Step.HasCheck true }const checkedIds = ref([]);@{end}
|
||||
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable false) }const expandedKeys = ref([]);
|
||||
const allTreeKeys = ref([]);@{end}
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }const expandedKeys = ref([]);
|
||||
const pattern = ref('');
|
||||
const selectedState = ref<State>(newState(null));
|
||||
const loading = ref(false);@{end}
|
||||
|
||||
const actionColumn = reactive({
|
||||
width: @{.options.Step.ActionColumnWidth},
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render(record: State) {
|
||||
return h(TableAction as any, {
|
||||
style: 'button',
|
||||
actions: [
|
||||
@{ if eq .options.Step.HasEdit true } {
|
||||
label: '编辑',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: ['/@{.apiPrefix}/edit'],
|
||||
},@{end}
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable false) } {
|
||||
label: '添加',
|
||||
onClick: handleAdd.bind(null, record),
|
||||
auth: ['/@{.apiPrefix}/edit'],
|
||||
},@{end}
|
||||
@{ if eq .options.Step.HasStatus true } {
|
||||
label: '禁用',
|
||||
onClick: handleStatus.bind(null, record, 2),
|
||||
ifShow: () => {
|
||||
return record.status === 1;
|
||||
},
|
||||
auth: ['/@{.apiPrefix}/status'],
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
onClick: handleStatus.bind(null, record, 1),
|
||||
ifShow: () => {
|
||||
return record.status === 2;
|
||||
},
|
||||
auth: ['/@{.apiPrefix}/status'],
|
||||
},@{end}
|
||||
@{ if eq .options.Step.HasDel true } {
|
||||
label: '删除',
|
||||
onClick: handleDelete.bind(null, record),
|
||||
auth: ['/@{.apiPrefix}/delete'],
|
||||
},@{end}
|
||||
],
|
||||
@{ if eq .options.Step.HasView true } dropDownActions: [
|
||||
{
|
||||
label: '查看详情',
|
||||
key: 'view',
|
||||
auth: ['/@{.apiPrefix}/view'],
|
||||
},
|
||||
],
|
||||
select: (key) => {
|
||||
if (key === 'view') {
|
||||
return handleView(record);
|
||||
}
|
||||
},@{end}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const scrollX = computed(() => {
|
||||
return adaTableScrollX(columns, actionColumn.width);
|
||||
});
|
||||
|
||||
const [register, {}] = useForm({
|
||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||
labelWidth: 80,
|
||||
schemas,
|
||||
});
|
||||
|
||||
@{ if eq .options.Step.IsTreeTable false }
|
||||
// 加载表格数据
|
||||
const loadDataTable = async (res) => {
|
||||
return await List({ ...searchFormRef.value?.formModel, ...res });
|
||||
};@{end}
|
||||
|
||||
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable false) }
|
||||
// 加载普通数表数据
|
||||
const loadDataTable = async (res = {}) => {
|
||||
const params = { ...(searchFormRef.value?.formModel ?? {}), ...res, pagination: false };
|
||||
const dataSource = await List(params);
|
||||
allTreeKeys.value = expandedKeys.value = dataSource.list.map((item) => item.@{.pk.TsName});
|
||||
dataSource.list = convertListToTree(dataSource.list, '@{.pk.TsName}');
|
||||
return dataSource;
|
||||
};@{end}
|
||||
|
||||
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable true) }
|
||||
// 加载选项式树表数据
|
||||
const loadDataTable = async (res = {}) => {
|
||||
if (selectedState.value.@{.pk.TsName} < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 刷新树选项
|
||||
loadTreeOption();
|
||||
|
||||
// 获取选中的下级列表
|
||||
const params = {
|
||||
...(searchFormRef.value?.formModel ?? {}),
|
||||
...res,
|
||||
pid: selectedState.value.@{.pk.TsName},
|
||||
};
|
||||
return await List(params);
|
||||
};
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.HasCheck true }
|
||||
// 更新选中的行
|
||||
function handleOnCheckedRow(rowKeys) {
|
||||
checkedIds.value = rowKeys;
|
||||
}@{end}
|
||||
|
||||
// 重新加载表格数据
|
||||
function reloadTable() {
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
@{ if eq .options.Step.HasAdd true }
|
||||
// 添加数据
|
||||
function addTable() {
|
||||
editRef.value.openModal(null);
|
||||
}@{end}
|
||||
|
||||
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.IsTreeTable true) }
|
||||
// 添加树节点下级数据
|
||||
function handleAdd(record: Recordable) {
|
||||
const state = newState(null);
|
||||
state.pid = record.@{.pk.TsName};
|
||||
editRef.value.openModal(state);
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
// 编辑数据
|
||||
function handleEdit(record: Recordable) {
|
||||
editRef.value.openModal(record);
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasView true }
|
||||
// 查看详情
|
||||
function handleView(record: Recordable) {
|
||||
viewRef.value.openModal(record);
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasDel true }
|
||||
// 单个删除
|
||||
function handleDelete(record: Recordable) {
|
||||
dialog.warning({
|
||||
title: '警告',
|
||||
content: '你确定要删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: () => {
|
||||
Delete(record).then((_res) => {
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
});
|
||||
},
|
||||
});
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasBatchDel true }
|
||||
// 批量删除
|
||||
function handleBatchDelete() {
|
||||
if (checkedIds.value.length < 1){
|
||||
message.error('请至少选择一项要删除的数据');
|
||||
return;
|
||||
}
|
||||
|
||||
dialog.warning({
|
||||
title: '警告',
|
||||
content: '你确定要批量删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: () => {
|
||||
Delete({ @{.pk.TsName}: checkedIds.value }).then((_res) => {
|
||||
checkedIds.value = [];
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
});
|
||||
},
|
||||
});
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasExport true }
|
||||
// 导出
|
||||
function handleExport() {
|
||||
message.loading('正在导出列表...', { duration: 1200 });
|
||||
Export(searchFormRef.value?.formModel);
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasStatus true }
|
||||
// 修改状态
|
||||
function handleStatus(record: Recordable, status: number) {
|
||||
Status({ @{.pk.TsName}: record.@{.pk.TsName}, status: status }).then((_res) => {
|
||||
message.success('设为' + dict.getLabel('sys_normal_disable', status) + '成功');
|
||||
setTimeout(() => {
|
||||
reloadTable();
|
||||
});
|
||||
});
|
||||
}@{end}
|
||||
|
||||
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Step.IsOptionTreeTable false) }
|
||||
// 收起/展开全部树节点
|
||||
function handleAllExpanded() {
|
||||
if (expandedKeys.value.length) {
|
||||
expandedKeys.value = [];
|
||||
} else {
|
||||
expandedKeys.value = allTreeKeys.value;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新展开的树节点
|
||||
function updateExpandedKeys(openKeys: never[]) {
|
||||
expandedKeys.value = openKeys;
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }
|
||||
// 选中树节点
|
||||
function handleSelected(keys, option) {
|
||||
if (keys.length) {
|
||||
selectedState.value = newState(option[0]);
|
||||
reloadTable();
|
||||
} else {
|
||||
selectedState.value = newState(null);
|
||||
}
|
||||
}
|
||||
|
||||
// 展开指定节点
|
||||
function handleOnExpandedKeys(keys) {
|
||||
expandedKeys.value = keys;
|
||||
}
|
||||
|
||||
// 展开全部节点
|
||||
function handleAllExpanded() {
|
||||
if (expandedKeys.value.length) {
|
||||
expandedKeys.value = [];
|
||||
} else {
|
||||
expandedKeys.value = getTreeKeys(unref(treeOption), '@{.pk.TsName}');
|
||||
}
|
||||
}
|
||||
|
||||
// 首次加载树选项,默认展开全部
|
||||
function firstLoadTreeOption() {
|
||||
loading.value = true;
|
||||
TreeOption().then((res) => {
|
||||
treeOption.value = res;
|
||||
expandedKeys.value = getTreeKeys(unref(treeOption), '@{.pk.TsName}');
|
||||
loading.value = false;
|
||||
});
|
||||
}@{end}
|
||||
|
||||
@{ if or (eq .dictOptions.Has true) (eq .options.Step.IsOptionTreeTable true) }
|
||||
onMounted(() => {
|
||||
@{ if eq .dictOptions.Has true }loadOptions();@{end}
|
||||
@{ if eq .options.Step.IsOptionTreeTable true }firstLoadTreeOption();@{end}
|
||||
});@{end}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
@@ -0,0 +1,52 @@
|
||||
@{.import}
|
||||
|
||||
@{.const}
|
||||
|
||||
export class State {
|
||||
@{range .stateItems} public @{.Name} = @{if and .DataType (or (eq .DataType "varchar") (eq .DataType "char") (eq .DataType "bpchar") (eq .DataType "text") (eq .DataType "json") (eq .DataType "jsonb") (eq .DataType "date") (eq .DataType "time") (eq .DataType "timetz") (eq .DataType "datetime") (eq .DataType "timestamp") (eq .DataType "timestamptz") (eq .DataType "TIMESTAMP") (eq .DataType "interval") (eq .DataType "uuid") (eq .DataType "bytea") (eq .DataType "inet") (eq .DataType "cidr") (eq .DataType "macaddr") (eq .DataType "macaddr8") (eq .DataType "bit") (eq .DataType "varbit") (eq .DataType "point") (eq .DataType "line") (eq .DataType "lseg") (eq .DataType "box") (eq .DataType "path") (eq .DataType "polygon") (eq .DataType "circle") (eq .DataType "money")) (ne .DefaultValue "null")}'@{.DefaultValue}'@{else}@{.DefaultValue}@{end}; // @{.Dc}
|
||||
@{end}
|
||||
constructor(state?: Partial<State>) {
|
||||
if (state) {
|
||||
Object.assign(this, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function newState(state: State | Record<string, any> | null): State {
|
||||
if (state !== null) {
|
||||
if (state instanceof State) {
|
||||
return cloneDeep(state);
|
||||
}
|
||||
return new State(state);
|
||||
}
|
||||
return new State();
|
||||
}
|
||||
|
||||
// 表单验证规则
|
||||
@{ if eq .options.Step.HasRules true }@{.rules}@{end}
|
||||
|
||||
// 表格搜索表单
|
||||
@{ if eq .options.Step.HasSearchForm true }@{.formSchema}@{end}
|
||||
|
||||
// 表格列
|
||||
@{.columns}
|
||||
|
||||
@{ if eq .dictOptions.Has true }
|
||||
// 加载字典数据选项
|
||||
export function loadOptions() {
|
||||
dict.loadOptions(@{ToTSArray .options.DictOps.Types});
|
||||
}
|
||||
@{end}
|
||||
|
||||
@{ if eq .options.Step.IsTreeTable true }
|
||||
// 关系树选项
|
||||
export const treeOption = ref([]);
|
||||
|
||||
// 加载关系树选项
|
||||
export function loadTreeOption() {
|
||||
TreeOption().then((res) => {
|
||||
treeOption.value = res;
|
||||
});
|
||||
}
|
||||
@{end}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-drawer v-model:show="showModal" :width="dialogWidth">
|
||||
<n-drawer-content title="@{.tableComment}详情" closable>
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-descriptions label-placement="left" class="py-2" :column="1">
|
||||
@{.item}
|
||||
</n-descriptions>
|
||||
</n-spin>
|
||||
</n-drawer-content>
|
||||
</n-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { View } from '@{.importWebApi}';
|
||||
import { State, newState } from './model';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
@{ if eq .hasUploadFile true }import { getFileExt } from '@/utils/urlUtils';
|
||||
@{end}@{ if eq .options.DictOps.Has true }import { useDictStore } from '@/store/modules/dict';@{end}
|
||||
|
||||
const message = useMessage();
|
||||
@{ if eq .options.DictOps.Has true }const dict = useDictStore();@{end}
|
||||
const loading = ref(false);
|
||||
const showModal = ref(false);
|
||||
const formValue = ref(newState(null));
|
||||
const dialogWidth = computed(() => {
|
||||
return adaModalWidth(580);
|
||||
});
|
||||
@{ if eq .hasUploadFile true }const fileAvatarCSS = computed(() => {
|
||||
return {
|
||||
'--n-merged-size': `var(--n-avatar-size-override, 80px)`,
|
||||
'--n-font-size': `18px`,
|
||||
};
|
||||
});
|
||||
|
||||
// 下载
|
||||
function download(url: string) {
|
||||
window.open(url);
|
||||
}
|
||||
@{end}
|
||||
|
||||
// 打开模态框
|
||||
function openModal(state: State) {
|
||||
showModal.value = true;
|
||||
loading.value = true;
|
||||
View({ @{.pk.TsName}: state.@{.pk.TsName} })
|
||||
.then((res) => {
|
||||
formValue.value = res;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
|
||||
Reference in New Issue
Block a user