chore: 并入 iotlcm-app 历史到 app/(原提交 f40bda9)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:00 +08:00
1107 changed files with 147143 additions and 0 deletions
@@ -0,0 +1,101 @@
// Package @{.varName | ToLower}
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) @{NowYear} LiXiujie
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
// @AutoGenerate Version @{.xiuVersion}
//
package v1 //@{.varName | ToLower}
import (
"github.com/gogf/gf/v2/frame/g"
"@{.importInput}"
"xiuadmin/internal/model/response"
@{ if eq .options.Step.IsTreeTable true }"xiuadmin/utility/tree"@{end}
)
// ListReq 查询@{.tableComment}列表
type @{.varName}ListReq struct {
g.Meta `path:"/@{.varName | LcFirst}/list" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}列表" x-check-permission:"cpm:gen:@{.varName| LcFirst}:list"`
@{.templateGroup}in.@{.varName}ListParam
}
type @{.varName}ListRes struct {
response.PageResult
Items []*@{.templateGroup}in.@{.varName}ListModel `json:"items" dc:"数据列表"`
}
@{ if eq .options.Step.HasExport true }
// ExportReq 导出@{.tableComment}列表
type @{.varName}ExportReq struct {
g.Meta `path:"/@{.varName | LcFirst}/export" method:"post" tags:"@{.tableComment}" summary:"导出@{.tableComment}列表" x-check-permission:"cpm:gen:@{.varName| LcFirst}:export"`
@{.templateGroup}in.@{.varName}ListParam
}
type @{.varName}ExportRes struct{}
@{end}
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// ViewReq 获取@{.tableComment}指定信息
type @{.varName}ViewReq struct {
g.Meta `path:"/@{.varName | LcFirst}/view" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}指定信息" x-check-permission:"cpm:gen:@{.varName| LcFirst}:view"`
@{.templateGroup}in.@{.varName}ViewParam
}
type @{.varName}ViewRes struct {
*@{.templateGroup}in.@{.varName}ViewModel
}
@{end}
@{ if eq .options.Step.HasEdit true }
// EditReq 修改/新增@{.tableComment}
type @{.varName}EditReq struct {
g.Meta `path:"/@{.varName | LcFirst}/edit" method:"post" tags:"@{.tableComment}" summary:"修改/新增@{.tableComment}" x-check-permission:"cpm:gen:@{.varName| LcFirst}:edit"`
@{.templateGroup}in.@{.varName}EditParam
}
type @{.varName}EditRes struct{}
@{end}
@{ if eq .options.Step.HasDel true }
// DeleteReq 删除@{.tableComment}
type @{.varName}DeleteReq struct {
g.Meta `path:"/@{.varName | LcFirst}/delete" method:"post" tags:"@{.tableComment}" summary:"删除@{.tableComment}" x-check-permission:"cpm:gen:@{.varName| LcFirst}:delete"`
@{.templateGroup}in.@{.varName}DeleteParam
}
type @{.varName}DeleteRes struct{}
@{end}
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
// MaxSortReq 获取@{.tableComment}最大排序
type @{.varName}MaxSortReq struct {
g.Meta `path:"/@{.varName | LcFirst}/maxSort" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}最大排序" x-check-permission:"cpm:gen:@{.varName| LcFirst}:maxSort"`
@{.templateGroup}in.@{.varName}MaxSortParam
}
type @{.varName}MaxSortRes struct {
*@{.templateGroup}in.@{.varName}MaxSortModel
}
@{end}
@{ if eq .options.Step.HasStatus true }
// StatusReq 更新@{.tableComment}状态
type @{.varName}StatusReq struct {
g.Meta `path:"/@{.varName | LcFirst}/status" method:"post" tags:"@{.tableComment}" summary:"更新@{.tableComment}状态" x-check-permission:"cpm:gen:@{.varName| LcFirst}:status"`
@{.templateGroup}in.@{.varName}StatusParam
}
type @{.varName}StatusRes struct{}
@{end}
@{ if eq .options.Step.HasSwitch true }
// SwitchReq 更新@{.tableComment}开关状态
type @{.varName}SwitchReq struct {
g.Meta `path:"/@{.varName | LcFirst}/switch" method:"post" tags:"@{.tableComment}" summary:"更新@{.tableComment}状态" x-check-permission:"cpm:gen:@{.varName| LcFirst}:switch"`
@{.templateGroup}in.@{.varName}SwitchParam
}
type @{.varName}SwitchRes struct{}
@{end}
@{ if eq .options.Step.IsTreeTable true }
// TreeOptionReq 获取@{.tableComment}关系树选项
type @{.varName}TreeOptionReq struct {
g.Meta `path:"/@{.varName | LcFirst}/treeOption" method:"get" tags:"@{.tableComment}" summary:"获取@{.tableComment}关系树选项" x-check-permission:"cpm:gen:@{.varName| LcFirst}:treeOption"`
}
type @{.varName}TreeOptionRes []tree.Node
@{end}
@@ -0,0 +1,119 @@
// Package @{.templateGroup}
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) @{NowYear} LiXiujie
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
// @AutoGenerate Version @{.xiuVersion}
//
package @{.templateGroup}
import (
"context"
v1 "@{.importApi}"
"xiuadmin/internal/model/input/form"
"@{.importInput}"
"@{.importService}"
)
var (
@{.varName} = c@{.varName}{}
)
type c@{.varName} struct{}
// List 查看@{.tableComment}列表
func (c *c@{.varName}) @{.varName}List(ctx context.Context, req *v1.@{.varName}ListReq) (res *v1.@{.varName}ListRes, err error) {
list, totalCount, err := service.@{.servFunName}().List(ctx, &req.@{.varName}ListParam)
if err != nil {
return
}
if list == nil {
list = []*@{.templateGroup}in.@{.varName}ListModel{}
}
res = new(v1.@{.varName}ListRes)
res.Items = list
res.PageResult.Page = req.Page
res.PageResult.PageSize = req.PageSize
res.PageResult.Total = totalCount
return
}
@{ if eq .options.Step.HasExport true }
// Export 导出@{.tableComment}列表
func (c *c@{.varName}) @{.varName}Export(ctx context.Context, req *v1.@{.varName}ExportReq) (res *v1.@{.varName}ExportRes, err error) {
err = service.@{.servFunName}().Export(ctx, &req.@{.varName}ListParam)
return
}
@{end}
@{ if eq .options.Step.HasEdit true }
// Edit 更新@{.tableComment}
func (c *c@{.varName}) @{.varName}Edit(ctx context.Context, req *v1.@{.varName}EditReq) (res *v1.@{.varName}EditRes, err error) {
err = service.@{.servFunName}().Edit(ctx, &req.@{.varName}EditParam)
return
}
@{end}
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
// MaxSort 获取@{.tableComment}最大排序
func (c *c@{.varName}) @{.varName}MaxSort(ctx context.Context, req *v1.@{.varName}MaxSortReq) (res *v1.@{.varName}MaxSortRes, err error) {
data, err := service.@{.servFunName}().MaxSort(ctx, &req.@{.varName}MaxSortParam)
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}) @{.varName}View(ctx context.Context, req *v1.@{.varName}ViewReq) (res *v1.@{.varName}ViewRes, err error) {
data, err := service.@{.servFunName}().View(ctx, &req.@{.varName}ViewParam)
if err != nil {
return
}
res = new(v1.@{.varName}ViewRes)
res.@{.varName}ViewModel = data
return
}
@{end}
@{ if eq .options.Step.HasDel true }
// Delete 删除@{.tableComment}
func (c *c@{.varName}) @{.varName}Delete(ctx context.Context, req *v1.@{.varName}DeleteReq) (res *v1.@{.varName}DeleteRes, err error) {
err = service.@{.servFunName}().Delete(ctx, &req.@{.varName}DeleteParam)
return
}
@{end}
@{ if eq .options.Step.HasStatus true }
// Status 更新@{.tableComment}状态
func (c *c@{.varName}) @{.varName}Status(ctx context.Context, req *v1.@{.varName}StatusReq) (res *v1.@{.varName}StatusRes, err error) {
err = service.@{.servFunName}().Status(ctx, &req.@{.varName}StatusParam)
return
}
@{end}
@{ if eq .options.Step.HasSwitch true }
// Switch 更新@{.tableComment}开关状态
func (c *c@{.varName}) @{.varName}Switch(ctx context.Context, req *v1.@{.varName}SwitchReq) (res *v1.@{.varName}SwitchRes, err error) {
err = service.@{.servFunName}().Switch(ctx, &req.@{.varName}SwitchParam)
return
}
@{end}
@{ if eq .options.Step.IsTreeTable true }
// TreeOption 获取@{.tableComment}关系树选项
func (c *c@{.varName}) @{.varName}TreeOption(ctx context.Context, req *v1.@{.varName}TreeOptionReq) (res *v1.@{.varName}TreeOptionRes, err error) {
data, err := service.@{.servFunName}().TreeOption(ctx)
if err != nil {
return nil, err
}
if len(data) > 0 {
res = (*v1.@{.varName}TreeOptionRes)(&data)
} else {
temp := make(v1.@{.varName}TreeOptionRes, 0)
res = &temp
}
return
}
@{end}
@@ -0,0 +1,168 @@
// Package @{.templateGroup}in
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) @{NowYear} LiXiujie
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
// @AutoGenerate Version @{.xiuVersion}
//
package @{.templateGroup}in
import (
"context"
"errors"
"slices"
"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"
"xiuadmin/internal/consts"
"xiuadmin/internal/model/entity"
"xiuadmin/internal/model/request"
"xiuadmin/utility/validate"
@{ if eq .options.Step.HasHookMemberSummary true }"xiuadmin/internal/library/xgorm/hook"@{end}
@{ if eq .options.Step.IsTreeTable true }"xiuadmin/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}EditParam 修改/新增@{.tableComment}
type @{.varName}EditParam struct {
//entity.@{.daoName}
@{.editParamFieldsColumns}
}
func (in *@{.varName}EditParam) Filter(ctx context.Context) (err error) {
@{.editParamValidator}
return
}
type @{.varName}EditModel struct{}
@{end}
@{ if eq .options.Step.HasDel true }
// @{.varName}DeleteParam 删除@{.tableComment}
type @{.varName}DeleteParam struct {
@{.pk.GoName} interface{} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
}
func (in *@{.varName}DeleteParam) 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}ViewParam 获取指定@{.tableComment}信息
type @{.varName}ViewParam struct {
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
}
func (in *@{.varName}ViewParam) Filter(ctx context.Context) (err error) {
return
}
type @{.varName}ViewModel struct {
@{.viewModelColumns}
}@{end}
// @{.varName}ListParam 获取@{.tableComment}列表
type @{.varName}ListParam struct {
request.PageInfo
@{.listInpColumns}
}
func (in *@{.varName}ListParam) 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}MaxSortParam 获取@{.tableComment}最大排序
type @{.varName}MaxSortParam struct{}
func (in *@{.varName}MaxSortParam) Filter(ctx context.Context) (err error) {
return
}
type @{.varName}MaxSortModel struct {
Sort int `json:"sort" description:"排序"`
}
@{end}
@{ if eq .options.Step.HasStatus true }
// @{.varName}StatusParam 更新@{.tableComment}状态
type @{.varName}StatusParam struct {
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
Status int `json:"status" dc:"状态"`
}
func (in *@{.varName}StatusParam) 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 (!slices.Contains(consts.StatusSlice, in.Status)) {
err = gerror.New("状态不正确")
return
}
return
}
type @{.varName}StatusModel struct{}
@{end}
@{ if eq .options.Step.HasSwitch true }
// @{.varName}SwitchParam 更新@{.tableComment}开关状态
type @{.varName}SwitchParam struct {
request.SwitchReq
@{.pk.GoName} @{.pk.GoType} `json:"@{.pk.TsName}" v:"required#@{.pk.Dc}不能为空" dc:"@{.pk.Dc}"`
}
func (in *@{.varName}SwitchParam) 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.@{.options.Tree.PidField.GoName}
}
// SetChildren 设置子节点数据
func (t *@{.varName}TreeOption) SetChildren(children []tree.Node) {
t.Children = children
}
@{end}
@@ -0,0 +1,298 @@
// Package @{.templateGroup}
// @Link https://github.com/xiujiecn/xiu-admin
// @Copyright Copyright (c) @{NowYear} LiXiujie
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
// @AutoGenerate Version @{.xiuVersion}
//
package @{.templateGroup}
import (
"context"
"fmt"
"slices"
"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"
"xiuadmin/internal/dao"
"xiuadmin/internal/consts"
"xiuadmin/internal/library/contexts"
"xiuadmin/internal/library/xgorm"
"xiuadmin/internal/library/xgorm/handler"
"xiuadmin/internal/library/xgorm/hook"
"xiuadmin/internal/model/do"
"@{.importInput}"
"@{.importService}"
"xiuadmin/utility/convert"
"xiuadmin/utility/excel"
"xiuadmin/utility/validate"
@{ if eq .options.Step.IsAddon true }isc "xiuadmin/internal/service"@{end}
@{ if eq .options.Step.IsTreeTable true }"xiuadmin/utility/tree"@{end}
@{ if eq .options.Step.HasFuncDict true }"xiuadmin/internal/library/dict"@{end}
@{ if eq .options.Step.HasFuncDict true }"xiuadmin/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 {
if len(option) == 0 {
option = append(option, &handler.Option{
FilterTenant: true,
FilterAuth: true,
})
}
return handler.Model(dao.@{.daoName}.Ctx(ctx), option...)
}
// List 获取@{.tableComment}列表
func (s *s@{.servFunName}) List(ctx context.Context, in *@{.templateGroup}in.@{.varName}ListParam) (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.Page > 0 && in.PageSize > 0 {
mod = mod.Page(in.Page, in.PageSize)
}
@{end}
@{ if eq .options.Step.IsTreeTable false }
// 分页
mod = mod.Page(in.Page, in.PageSize)
@{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}ListParam) (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, (totalCount+in.PageSize-1)/in.PageSize, 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}EditParam) (err error) {
@{.edit.unique} return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Tree.HasTreePath true) }in.@{.options.Tree.PidField.GoName}, in.@{.options.Tree.LevelField.GoName}, in.@{.options.Tree.TreeField.GoName}, err = xgorm.AutoUpdateTree(ctx, &dao.@{.daoName}, in.@{.pk.GoName}, in.@{.options.Tree.PidField.GoName}, &xgorm.TreeFiledOption{
IdField: dao.@{.daoName}.Columns().@{.pk.GoName},
PidField: dao.@{.daoName}.Columns().@{.options.Tree.PidField.GoName},
LevelField: dao.@{.daoName}.Columns().@{.options.Tree.LevelField.GoName},
TreeField: dao.@{.daoName}.Columns().@{.options.Tree.TreeField.GoName},
})
if err != nil {
return err
}@{end}
@{ if and (eq .options.Step.IsTreeTable true) (eq .options.Tree.HasTreePath false) }if in.@{.pk.GoName} > 0 && in.@{.pk.GoName} == in.@{.options.Tree.PidField.GoName} {
return gerror.New("上级不能是自己!")
}
if in.@{.options.Tree.PidField.GoName} > 0 {
count, err := dao.@{.daoName}.Ctx(ctx).WherePri(in.@{.options.Tree.PidField.GoName}).Count()
if err != nil {
return err
}
if count == 0 {
return gerror.New("未查询到树表上级信息,请检查!")
}
nextPid := in.@{.options.Tree.PidField.GoName}
visited := map[interface{}]bool{}
for nextPid > 0 {
if nextPid == in.@{.pk.GoName} {
return gerror.New("上级不能设为自己当前的子级!")
}
if visited[nextPid] {
return gerror.New("树表上级关系存在循环,请检查!")
}
visited[nextPid] = true
var parent *@{.templateGroup}in.@{.varName}TreeOption
if err = dao.@{.daoName}.Ctx(ctx).Fields(dao.@{.daoName}.Columns().@{.options.Tree.PidField.GoName}).WherePri(nextPid).Scan(&parent); err != nil {
return err
}
if parent == nil {
return gerror.New("未查询到树表上级信息,请检查!")
}
nextPid = parent.@{.options.Tree.PidField.GoName}
}
}@{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}DeleteParam) (err error) {
@{ if eq .options.Step.IsTreeTable true }count, err := dao.@{.daoName}.Ctx(ctx).Where(dao.@{.daoName}.Columns().@{.options.Tree.PidField.GoName}, in.@{.pk.GoName}).Count()
if err != nil {
err = gerror.Wrap(err, "查询@{.tableComment}下级失败,请稍后重试!")
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}MaxSortParam) (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}ViewParam) (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}StatusParam) (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}SwitchParam) (err error) {
var fields = []string{
@{.switchFields} // ...
}
if (!slices.Contains(fields, in.Key)) {
err = gerror.New("开关键名不在白名单")
return
}
@{.switchUpdate}
if _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Data(data).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().@{.options.Tree.PidField.GoName}).@{.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), nil
}
@{end}
@{ if eq .options.Step.HasFuncDict true }
// Option 获取@{.tableComment}选项
func (s *s@{.servFunName}) Option(ctx context.Context) (opts []*model.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([]*model.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/xiujiecn/xiu-admin
// @Copyright Copyright (c) @{NowYear} LiXiujie
// @Author Lxj <li@example.com>
// @License https://github.com/xiujiecn/xiu-admin/blob/master/LICENSE
// @AutoGenerate Version @{.xiuVersion}
//
package genrouter
import "@{.importController}"
func init() {
LoginRequiredRouter = append(LoginRequiredRouter, @{.templateGroup}.@{.varName}) // @{.tableComment}
}
@@ -0,0 +1,82 @@
-- XJAdmin自动生成菜单权限SQL 通常情况下只在首次生成代码时自动执行一次
-- 如需再次执行请先手动删除生成的菜单权限和SQL文件:@{.generatePath}
-- Version: @{.xiuVersion}
-- Date: @{.nowTime}
-- Link https://github.com/xiujiecn/xiu-admin
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
--
-- 数据库: `@{.dbName}`
--
-- --------------------------------------------------------
--
-- 插入表中的数据 `@{.menuTable}`
--
SET @now := now();
-- 菜单目录
INSERT INTO `@{.menuTable}` ( `menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES ( NULL, '@{.tableComment}', '@{.options.Menu.Pid}', @{.dirLevel}, '@{.dirTree}', '@{.options.Menu.Sort}', '@{.varName | LcFirst}', '@{.mainComponent}', '', 1, 0, 'M', '0', '0', '', '@{.options.Menu.Icon}', 103, 1, @now, NULL, NULL, '');
SET @dirId = LAST_INSERT_ID();
-- 菜单页面
-- 列表
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '@{.tableComment}列表', @dirId, '@{.listLevel}', CONCAT('@{.dirTree}tr_', @dirId,' '),'10', 'index', 'gen/@{.componentPrefix}/index', '', 1, 0, 'C', '0', '0', 'gen:@{.apiPrefix}:list', '@{.options.Menu.Icon}', 103, 1, @now, 1, @now, '');
SET @listId = LAST_INSERT_ID();
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
-- 详情
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '@{.tableComment}详情', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:view', '', 103, 1, @now, NULL, NULL, '');
@{end}
-- 菜单按钮
@{ if eq .options.Step.HasEdit true }
-- 编辑
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '编辑/新增@{.tableComment}', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:edit', '', 103, 1, @now, NULL, NULL, '');
@{end}
SET @editId = LAST_INSERT_ID();
@{ if and (eq .options.Step.HasEdit true) (eq .options.Step.HasMaxSort true) }
-- 获取最大排序
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '获取@{.tableComment}最大排序', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:maxSort', '', 103, 1, @now, NULL, NULL, '');
@{end}
@{ if eq .options.Step.HasDel true }
-- 删除
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '删除@{.tableComment}', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:delete', '', 103, 1, @now, NULL, NULL, '');
@{end}
@{ if eq .options.Step.HasStatus true }
-- 更新状态
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '修改@{.tableComment}状态', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:status', '', 103, 1, @now, NULL, NULL, '');
@{end}
@{ if eq .options.Step.HasSwitch true }
-- 操作开关
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '操作@{.tableComment}开关', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:switch', '', 103, 1, @now, NULL, NULL, '');
@{end}
@{ if eq .options.Step.HasExport true }
-- 导出
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '导出@{.tableComment}', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:export', '', 103, 1, @now, NULL, NULL, '');
@{end}
@{ if eq .options.Step.IsTreeTable true }
-- 关系树选项
INSERT INTO `@{.menuTable}` (`menu_id`, `menu_name`, `parent_id`, `level`, `tree`, `order_num`, `path`, `component`, `query_param`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `created_dept`, `created_by`, `created_at`, `updated_by`, `updated_at`, `remark`) VALUES (NULL, '获取@{.tableComment}关系树选项', @listId, '@{.btnLevel}', CONCAT('@{.dirTree}tr_', @dirId, ' tr_', @listId,' '), 10, '', '', '', 1, 0, 'F', '0', '0', 'gen:@{.apiPrefix}:treeOption', '', 103, 1, @now, NULL, NULL, '');
@{end}
-- 默认绑定到超级管理员角色
INSERT IGNORE INTO `@{.roleMenuTable}` (`role_id`, `menu_id`)
SELECT 1, `menu_id`
FROM `@{.menuTable}`
WHERE `menu_id` IN (@dirId, @listId)
OR `parent_id` = @listId;
COMMIT;
@@ -0,0 +1,58 @@
import { requestClient } from '#/api/request';
// 获取@{.tableComment}列表
export function List(params:any) {
return requestClient.get<any>('gen/@{.apiPrefix}/list', { params });
}
@{ if eq .options.Step.HasDel true }
// 删除/批量删除@{.tableComment}
export function Delete(params:any) {
return requestClient.post<any>('gen/@{.apiPrefix}/delete', { ...params });
}
@{end}
@{ if eq .options.Step.HasEdit true }
// 添加/编辑@{.tableComment}
export function Edit(params:any) {
return requestClient.post<any>('gen/@{.apiPrefix}/edit', { ...params });
}
@{end}
@{ if eq .options.Step.HasStatus true }
// 修改@{.tableComment}状态
export function Status(params:any) {
return requestClient.post<any>('gen/@{.apiPrefix}/status', { ...params });
}
@{end}
@{ if eq .options.Step.HasSwitch true }
// 操作@{.tableComment}开关
export function Switch(params:any) {
return requestClient.post<any>('gen/@{.apiPrefix}/switch', { ...params });
}
@{end}
@{ if or (eq .options.Step.HasView true) (eq .options.Step.HasEdit true) }
// 获取@{.tableComment}指定详情
export function View(params:any) {
return requestClient.get<any>('gen/@{.apiPrefix}/view', { params });
}
@{end}
@{ if eq .options.Step.HasMaxSort true }
// 获取@{.tableComment}最大排序
export function MaxSort(params:any) {
return requestClient.get<any>('gen/@{.apiPrefix}/maxSort', { params });
}
@{end}
@{ if eq .options.Step.HasExport true }
// 导出@{.tableComment}
export function Export(params:any) {
return requestClient.post<Blob>('/gen/@{.apiPrefix}/export', { ...params } , {
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
responseType: 'blob',
});
}
@{end}
@{ if eq .options.Step.IsTreeTable true }
// 获取@{.tableComment}关系树选项
export function TreeOption() {
return requestClient.get<any>('gen/@{.apiPrefix}/treeOption');
}
@{end}
@@ -0,0 +1,135 @@
<template>
<BasicDrawer :close-on-click-modal="false" :title="title" class="w-[600px]">
<BasicForm>
</BasicForm>
</BasicDrawer>
</template>
<script setup lang="ts">
import { computed, nextTick, ref } from 'vue';
import { useVbenDrawer, useVbenModal, VbenButton } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { addFullName, cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { Alert } from 'ant-design-vue';
import { Edit, View } from '@{.importWebApi}';
import { editSchema@{ if eq .options.Step.IsTreeTable true }, treeOption, loadTreeOption@{end} } from './model';
const emit = defineEmits<{ reload: [] }>();
interface ModalProps {
id?: number | string;
update: boolean;
view: boolean;
}
const isUpdate = ref(false);
const isView = ref(false);
const title = computed(() => {
if (isView.value) {
return $t('pages.common.view');
}
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
formItemClass: 'col-span-@{.script.formGridSpan}',
},
layout: 'vertical',
schema: editSchema,
showDefaultActions: false,
wrapperClass: 'grid-cols-@{.script.formGridSpan} gap-x-4',
});
@{ if eq .isEditModal true }
const [BasicDrawer, drawerApi] = useVbenModal
@{else}
const [BasicDrawer, drawerApi] = useVbenDrawer
@{end}
({
onCancel: handleCancel,
onConfirm: handleConfirm,
async onOpenChange(isOpen) {
if (!isOpen) {
return null;
}
drawerApi.setState({ confirmLoading: true, loading: true })
const { id, update, view, } = drawerApi.getData() as ModalProps;
isUpdate.value = update;
isView.value = view;
@{ if eq .options.Step.IsTreeTable true }
await loadTreeOption();
formApi.updateSchema([
{
componentProps: {
fieldNames: { label: '@{.options.Tree.TitleField.TsName}', value: '@{.pk.TsName}' },
showSearch: true,
treeData: treeOption.value,
treeDefaultExpandAll: true,
treeLine: { showLeafIcon: false },
treeNodeFilterProp: '@{.options.Tree.TitleField.TsName}',
},
fieldName: '@{.options.Tree.PidField.TsName}',
},
]);
@{end}
if (isUpdate.value || isView.value) {
const record = await View({ @{.pk.TsName}: id });
await formApi.setValues(record);
}
drawerApi.setState({ confirmLoading: false, loading: false })
if (view) {
drawerApi.setState({ showConfirmButton: false });
formApi.setState({
commonConfig: {
componentProps: {
readonly: true,
"only-read": true,
}
}
});
} else {
drawerApi.setState({ showConfirmButton: true });
formApi.setState({
commonConfig: {
componentProps: {
readonly: false,
"only-read": false,
}
}
});
}
},
});
async function handleConfirm() {
try {
drawerApi.setState({ confirmLoading: true, loading: true })
const { valid } = await formApi.validate();
if (!valid) {
return;
}
const data = cloneDeep(await formApi.getValues());
await (Edit(data));
emit('reload');
await handleCancel();
} catch (error) {
console.error(error);
} finally {
drawerApi.setState({ confirmLoading: false, loading: false })
}
}
async function handleCancel() {
drawerApi.close();
await formApi.resetForm();
}
</script>
@@ -0,0 +1,235 @@
<script lang="ts" setup>
@{.import}
const formOptions: VbenFormProps = {
// 默认展开
collapsed: false,
fieldMappingTime: [['date', ['start', 'end']]],
schema: querySchema,
// 控制表单是否显示折叠按钮
showCollapseButton: true,
// 是否在字段值改变时提交表单
submitOnChange: true,
// 按下回车时是否提交表单
submitOnEnter: false,
};
const gridOptions: VxeTableGridOptions<RowType> = {
checkboxConfig: {
highlight: true,
labelField: '@{.pk.TsName}',
},
rowConfig: {
keyField: '@{.pk.TsName}',
},
columns: columns,
exportConfig: {},
height: 'auto',
keepSource: true,
showOverflow: false,
@{ if eq .options.Step.IsTreeTable true }
pagerConfig: {
enabled: false,
},
@{else}
pagerConfig: {},
@{end}
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await List({
page: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
toolbarConfig: {
custom: true,
export: false,
refresh: true,
resizable: true,
search: true,
zoom: true,
},
@{ if eq .options.Step.IsTreeTable true }
treeConfig: {
parentField: '@{.options.Tree.PidField.TsName}',
rowField: '@{.pk.TsName}',
transform: true,
expandAll: true,
},
@{end}
};
const gridEvents: DeepPartial<VxeGridListeners> = {
checkboxChange: handleCheckboxChange,
checkboxAll: handleCheckboxChange,
};
const CheckboxChecked = ref(false);
function handleCheckboxChange() {
CheckboxChecked.value = gridApi.grid.getCheckboxRecords().length > 0;
}
@{ if eq .options.Step.IsTreeTable true }
function expandAll() {
gridApi.grid?.setAllTreeExpand(true);
}
function collapseAll() {
gridApi.grid?.setAllTreeExpand(false);
}
@{end}
const [Grid, gridApi] = useVbenVxeGrid({
@{ if eq .isSearchForm true }
formOptions,
@{end}
gridOptions,
gridEvents,
});
const [ViewDrawer, drawerApi] = useVbenDrawer({
connectedComponent: viewDrawer,
});
function handlePreview(record: RowType) {
drawerApi.setData({ record });
drawerApi.open();
}
@{ if eq .isEditModal true }
const [EditDrawer, editDrawerApi] = useVbenModal({
connectedComponent: editDrawer,
});
@{else}
const [EditDrawer, editDrawerApi] = useVbenDrawer({
connectedComponent: editDrawer,
});
@{end}
function handleAdd() {
editDrawerApi.setData({ update: false, view: false });
editDrawerApi.open();
}
function handleEdit(row: RowType) {
editDrawerApi.setData({ id: row.@{.pk.TsName}, update: true, view: false });
editDrawerApi.open();
}
@{ if eq .options.Step.HasDel true }
async function handleDelete(row: RowType) {
await Delete({ @{.pk.TsName}: [row.@{.pk.TsName}] });
message.success("删除成功");
await handleRefresh();
}
@{end}
async function handleRefresh() {
await gridApi.query();
}
@{ if eq .options.Step.HasBatchDel true }
function handleMultiDelete() {
const rows = gridApi.grid.getCheckboxRecords();
const ids: RowType['@{.pk.TsName}'][] = [];
for (const row of rows) {
ids.push(row.@{.pk.TsName});
}
if (ids.length === 0){
message.error('请至少选择一项要删除的数据');
return;
}
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await Delete({ @{.pk.TsName}: ids });
message.success("删除成功");
await handleRefresh();
},
});
}
@{end}
@{ if eq .options.Step.HasExport true }
async function handleExport() {
const formValues = gridApi.formApi.form.values;
await commonDownloadExcel(Export, '@{.tableComment}',{
...formValues,
page: 1,
pageSize: 2000,
});
message.success("导出成功");
}
@{end}
@{ if eq .options.Step.HasStatus true }
async function handleStatusChange(row: RowType) {
await Status({ @{.pk.TsName}: row.@{.pk.TsName}, status: row.status });
await message.success("操作成功")
await handleRefresh();
}
@{end}
</script>
<template>
<Page auto-content-height>
<Grid table-title="@{.tableComment}">
<template #toolbar-tools>
@{ if eq .options.Step.HasAdd true }
<Button class="mr-2 flex items-center " type="primary" :icon="h(MdiPlus)" @click="handleAdd" v-access:code="'cpm:gen:@{.varName | LcFirst}:edit'">新增</Button>
@{end}
@{ if eq .options.Step.HasBatchDel true }
<Button class="mr-2 flex items-center" type="primary" :disabled="!CheckboxChecked" :icon="h(MdiDelete)" @click="handleMultiDelete" v-access:code="'cpm:gen:@{.varName | LcFirst}:delete'">删除</Button>
@{end}
@{ if eq .options.Step.HasExport true }
<Button class="mr-2 flex items-center" type="primary" :icon="h(MdiExport)" @click="handleExport" v-access:code="'cpm:gen:@{.varName | LcFirst}:export'">导出</Button>
@{end}
@{ if eq .options.Step.IsTreeTable true }
<Button class="mr-2 flex items-center" @click="expandAll">展开</Button>
<Button class="mr-2 flex items-center" @click="collapseAll">折叠</Button>
@{end}
</template>
@{ if eq .options.Step.HasStatus true }
<template #status="{ row }">
<Switch
v-model:checked="row.status" :checkedValue="'0'" :unCheckedValue="'1'"
@change="handleStatusChange(row)"
:disabled="!hasAccessByCodes(['cpm:gen:@{.varName | LcFirst}:status'])"
/>
</template>
@{end}
<template #action="{ row }">
<div class="flex items-center">
@{ if eq .options.Step.HasView true }
<Button class="mr-2 border-none p-0" :block="false" type="link" @click="handlePreview(row)" v-access:code="'cpm:gen:@{.varName | LcFirst}:view'">查看</Button>
@{end}
@{ if eq .options.Step.HasEdit true }
<Button class="mr-2 border-none p-0" :block="false" type="link" @click="handleEdit(row)" v-access:code="'cpm:gen:@{.varName | LcFirst}:edit'">修改</Button>
@{end}
@{ if eq .options.Step.HasDel true }
<AccessControl :codes="['cpm:gen:@{.varName | LcFirst}:delete']" type="code">
<Popconfirm title="确定删除吗?" :get-popup-container="getVxePopupContainer" placement="left" @confirm="handleDelete(row)" >
<Button class="mr-2 border-none p-0" :block="false" type="link" danger >
删除
</Button>
</Popconfirm>
</AccessControl>
@{end}
</div>
</template>
</Grid>
@{ if eq .options.Step.HasEdit true } <EditDrawer @reload="handleRefresh" /> @{end}
@{ if eq .options.Step.HasView true } <ViewDrawer /> @{end}
</Page>
</template>
@@ -0,0 +1,57 @@
@{.import}
@{.const}
export class State {@{range .stateItems}
public @{.Name} = @{.DefaultValue}; // @{.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}
// 表格列接口
@{.columnsInterface}
// 查看字段列表
@{.viewSchema}
// 编辑字段列表
@{.editSchema}
@{ if eq .dictOptions.Has true }
@{end}
@{ if eq .options.Step.IsTreeTable true }
// 关系树选项
export const treeOption = ref([]);
// 加载关系树选项
export async function loadTreeOption() {
const res = await TreeOption();
treeOption.value = res;
return res;
}
@{end}
@@ -0,0 +1,41 @@
<script setup lang="ts">
import type { SysClient } from '#/api/system/client';
import { computed, nextTick, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { addFullName, cloneDeep } from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { Description, useDescription } from '#/components/description';
import { viewSchema, type RowType } from './model';
import { View } from '@{.importWebApi}';
const [BasicDrawer, drawerApi] = useVbenDrawer({
onOpenChange: handleOpenChange,
});
const [registerDescription, { setDescProps }] = useDescription({
column: 1,
schema: viewSchema,
});
async function handleOpenChange(open: boolean) {
if (!open) {
return null;
}
const { record } = drawerApi.getData() as { record: RowType };
const record2 = await View({ @{.pk.TsName}: record.@{.pk.TsName} });
setDescProps({ data: record2 }, true);
}
</script>
<template>
<BasicDrawer :footer="false" class="w-[600px]" title="查看">
<Description @register="registerDescription">
</Description>
</BasicDrawer>
</template>
@@ -0,0 +1,12 @@
-- 执行日志元数据:仅新增两列,不回填、不重建表。
-- 部署前确认库、备份、同名字段和DDL维护窗口。
-- 旧写入端兼容legacy/0;应用新版本依赖此结构,先迁移再部署。
-- 此脚本尚未在开发、预演或生产数据库执行。
ALTER TABLE batch_main
ADD COLUMN source_channel VARCHAR(24) NOT NULL DEFAULT 'legacy'
COMMENT '发起渠道:console/mini_program/api/system/legacy',
ADD COLUMN execution_mode TINYINT UNSIGNED NOT NULL DEFAULT 0
COMMENT '操作规模:0未知1单卡2批量';
-- 不自动创建索引:按目标表已有索引和查询EXPLAIN确认。
-- 不自动回填:历史来源必须有可验证证据,不能按数量推断单卡。