mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-27 14:40:42 +08:00
发布v2.2.10版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
91
server/resource/generate/default/curd/api.go.template
Normal file
91
server/resource/generate/default/curd/api.go.template
Normal file
@@ -0,0 +1,91 @@
|
||||
// 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}
|
||||
// @AutoGenerate Date @{.nowTime}
|
||||
//
|
||||
package @{.varName | ToLower}
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"@{.importInput}"
|
||||
"hotgo/internal/model/input/form"
|
||||
)
|
||||
|
||||
// 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 eq .options.Step.HasView 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}最大排序"`
|
||||
}
|
||||
|
||||
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}
|
164
server/resource/generate/default/curd/controller.go.template
Normal file
164
server/resource/generate/default/curd/controller.go.template
Normal file
@@ -0,0 +1,164 @@
|
||||
// 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}
|
||||
// @AutoGenerate Date @{.nowTime}
|
||||
//
|
||||
package @{.templateGroup}
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"@{.importApi}"
|
||||
"@{.importInput}"
|
||||
"hotgo/internal/model/input/form"
|
||||
"@{.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) {
|
||||
var in @{.templateGroup}in.@{.varName}ListInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
list, totalCount, err := service.@{.templateGroup | UcFirst}@{.varName}().List(ctx, in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.ListRes)
|
||||
res.List = list
|
||||
res.PageCount = form.CalPageCount(totalCount, req.PerPage)
|
||||
res.Page = req.Page
|
||||
res.PerPage = req.PerPage
|
||||
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) {
|
||||
var in @{.templateGroup}in.@{.varName}ListInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Export(ctx, in)
|
||||
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) {
|
||||
var in @{.templateGroup}in.@{.varName}EditInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Edit(ctx, in)
|
||||
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.@{.templateGroup | UcFirst}@{.varName}().MaxSort(ctx, sysin.@{.varName}MaxSortInp{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = new(@{.varName | ToLower}.MaxSortRes)
|
||||
res.@{.varName}MaxSortModel = data
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasView true }
|
||||
// View 获取指定@{.tableComment}信息
|
||||
func (c *c@{.varName}) View(ctx context.Context, req *@{.varName | ToLower}.ViewReq) (res *@{.varName | ToLower}.ViewRes, err error) {
|
||||
var in @{.templateGroup}in.@{.varName}ViewInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := service.@{.templateGroup | UcFirst}@{.varName}().View(ctx, in)
|
||||
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) {
|
||||
var in @{.templateGroup}in.@{.varName}DeleteInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Delete(ctx, in)
|
||||
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) {
|
||||
var in @{.templateGroup}in.@{.varName}StatusInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Status(ctx, in)
|
||||
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) {
|
||||
var in @{.templateGroup}in.@{.varName}SwitchInp
|
||||
if err = gconv.Scan(req, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = validate.PreFilter(ctx, &in); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = service.@{.templateGroup | UcFirst}@{.varName}().Switch(ctx, in)
|
||||
return
|
||||
}
|
||||
@{end}
|
117
server/resource/generate/default/curd/input.go.template
Normal file
117
server/resource/generate/default/curd/input.go.template
Normal file
@@ -0,0 +1,117 @@
|
||||
// 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}
|
||||
// @AutoGenerate Date @{.nowTime}
|
||||
//
|
||||
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.HasEdit true }
|
||||
// @{.varName}EditInp 修改/新增@{.tableComment}
|
||||
type @{.varName}EditInp struct {
|
||||
entity.@{.daoName}
|
||||
}
|
||||
|
||||
func (in *@{.varName}EditInp) Filter(ctx context.Context) (err error) {
|
||||
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 eq .options.Step.HasView 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 {
|
||||
entity.@{.daoName}
|
||||
}@{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) {
|
||||
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}
|
172
server/resource/generate/default/curd/logic.go.template
Normal file
172
server/resource/generate/default/curd/logic.go.template
Normal file
@@ -0,0 +1,172 @@
|
||||
// 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}
|
||||
// @AutoGenerate Date @{.nowTime}
|
||||
//
|
||||
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/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/hgorm"
|
||||
"hotgo/internal/library/hgorm/handler"
|
||||
"@{.importInput}"
|
||||
"hotgo/internal/model/input/form"
|
||||
"@{.importService}"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/excel"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type s@{.servFunName} struct{}
|
||||
|
||||
func New@{.servFunName}() *s@{.servFunName} {
|
||||
return &s@{.servFunName}{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.Register@{.servFunName}(New@{.servFunName}())
|
||||
}
|
||||
|
||||
// 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)
|
||||
@{.listWhere}
|
||||
@{.listJoin.link}
|
||||
totalCount, err = mod.Clone().Count(1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if totalCount == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@{.listJoin.select}
|
||||
|
||||
err = mod.Fields(fields).Page(in.Page, in.PerPage).@{.listOrder}.Scan(&list)
|
||||
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) + ".xlsx"
|
||||
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) {
|
||||
// 修改
|
||||
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) {
|
||||
_, err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Delete()
|
||||
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 {
|
||||
return
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
res = new(@{.templateGroup}in.@{.varName}MaxSortModel)
|
||||
}
|
||||
|
||||
res.Sort = form.DefaultMaxSort(ctx, res.Sort)
|
||||
return
|
||||
}
|
||||
@{end}
|
||||
@{ if eq .options.Step.HasView true }
|
||||
// View 获取@{.tableComment}指定信息
|
||||
func (s *s@{.servFunName}) View(ctx context.Context, in @{.templateGroup}in.@{.varName}ViewInp) (res *@{.templateGroup}in.@{.varName}ViewModel, err error) {
|
||||
err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Scan(&res)
|
||||
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 in.@{.pk.GoName} <= 0 {
|
||||
err = gerror.New("@{.pk.Dc}不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(@{.statusUpdate}).Update()
|
||||
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.InSliceString(fields, in.Key) {
|
||||
err = gerror.New("开关键名不在白名单")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = s.Model(ctx).Where(dao.@{.daoName}.Columns().@{.pk.GoName}, in.@{.pk.GoName}).Data(@{.switchUpdate}).Update()
|
||||
return
|
||||
}
|
||||
@{end}
|
15
server/resource/generate/default/curd/router.go.template
Normal file
15
server/resource/generate/default/curd/router.go.template
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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}
|
||||
// @AutoGenerate Date @{.nowTime}
|
||||
//
|
||||
package genrouter
|
||||
|
||||
import "@{.importController}"
|
||||
|
||||
func init() {
|
||||
LoginRequiredRouter = append(LoginRequiredRouter, @{.templateGroup}.@{.varName}) // @{.tableComment}
|
||||
}
|
71
server/resource/generate/default/curd/source.sql.template
Normal file
71
server/resource/generate/default/curd/source.sql.template
Normal file
@@ -0,0 +1,71 @@
|
||||
-- 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', '', '', '', '@{.mainComponent}', '1', '', '0', '0', '', '0', '0', '0', '1', '', '@{.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', '', '0', '0', '', '0', '0', '0', '2', '', '10', '', '1', @now, @now);
|
||||
|
||||
|
||||
SET @listId = LAST_INSERT_ID();
|
||||
@{ if eq .options.Step.HasView 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, @dirId, '@{.tableComment}详情', '@{.varName | LcFirst}View', 'view/:id?', '', '2', '', '/@{.apiPrefix}/view', '', '/@{.componentPrefix}/view', '0', '@{.varName | LcFirst}Index', '0', '0', '', '0', '1', '0', '2', '', '20', '', '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', '3', '', '10', '', '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', '3', '', '10', '', '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', '3', '', '10', '', '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', '3', '', '10', '', '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', '3', '', '10', '', '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', '3', '', '10', '', '1', @now, @now);
|
||||
@{end}
|
||||
|
||||
COMMIT;
|
75
server/resource/generate/default/curd/web.api.ts.template
Normal file
75
server/resource/generate/default/curd/web.api.ts.template
Normal file
@@ -0,0 +1,75 @@
|
||||
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 eq .options.Step.HasView 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}
|
99
server/resource/generate/default/curd/web.edit.vue.template
Normal file
99
server/resource/generate/default/curd/web.edit.vue.template
Normal file
@@ -0,0 +1,99 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-modal
|
||||
v-model:show="isShowModal"
|
||||
:show-icon="false"
|
||||
preset="dialog"
|
||||
:title="params?.@{.pk.TsName} > 0 ? '编辑 #' + params?.@{.pk.TsName} : '添加'"
|
||||
:style="{
|
||||
width: dialogWidth,
|
||||
}"
|
||||
>
|
||||
<n-form
|
||||
:model="params"
|
||||
:rules="rules"
|
||||
ref="formRef"
|
||||
label-placement="left"
|
||||
:label-width="80"
|
||||
class="py-4"
|
||||
>
|
||||
@{.formItem}
|
||||
</n-form>
|
||||
<template #action>
|
||||
<n-space>
|
||||
<n-button @click="closeForm">取消</n-button>
|
||||
<n-button type="info" :loading="formBtnLoading" @click="confirmForm">确定</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
</n-spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@{.script.import} import { rules, options, State, newState } from './model';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
|
||||
const emit = defineEmits(['reloadTable', 'updateShowModal']);
|
||||
|
||||
interface Props {
|
||||
showModal: boolean;
|
||||
formParams?: State;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
showModal: false,
|
||||
formParams: () => {
|
||||
return newState(null);
|
||||
},
|
||||
});
|
||||
|
||||
const isShowModal = computed({
|
||||
get: () => {
|
||||
return props.showModal;
|
||||
},
|
||||
set: (value) => {
|
||||
emit('updateShowModal', value);
|
||||
},
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const params = ref<State>(props.formParams);
|
||||
const message = useMessage();
|
||||
const formRef = ref<any>({});
|
||||
const dialogWidth = ref('75%');
|
||||
const formBtnLoading = ref(false);
|
||||
|
||||
function confirmForm(e) {
|
||||
e.preventDefault();
|
||||
formBtnLoading.value = true;
|
||||
formRef.value.validate((errors) => {
|
||||
if (!errors) {
|
||||
Edit(params.value).then((_res) => {
|
||||
message.success('操作成功');
|
||||
setTimeout(() => {
|
||||
isShowModal.value = false;
|
||||
emit('reloadTable');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
message.error('请填写完整信息');
|
||||
}
|
||||
formBtnLoading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
adaModalWidth(dialogWidth);
|
||||
});
|
||||
|
||||
function closeForm() {
|
||||
isShowModal.value = false;
|
||||
}
|
||||
|
||||
@{.script.setup}
|
||||
</script>
|
||||
|
||||
<style lang="less"></style>
|
249
server/resource/generate/default/curd/web.index.vue.template
Normal file
249
server/resource/generate/default/curd/web.index.vue.template
Normal file
@@ -0,0 +1,249 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-card :bordered="false" class="proCard">
|
||||
<div class="n-layout-page-header">
|
||||
<n-card :bordered="false" title="@{.tableComment}">
|
||||
<!-- 这是系统自动生成的CURD表格,你可以将此行注释改为表格的描述 -->
|
||||
</n-card>
|
||||
</div>
|
||||
<BasicForm
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@keyup.enter="reloadTable"
|
||||
ref="searchFormRef"
|
||||
>
|
||||
<template #statusSlot="{ model, field }">
|
||||
<n-input v-model:value="model[field]" />
|
||||
</template>
|
||||
</BasicForm>
|
||||
|
||||
<BasicTable
|
||||
:openChecked="@{.options.Step.HasCheck}"
|
||||
:columns="columns"
|
||||
:request="loadDataTable"
|
||||
:row-key="(row) => row.id"
|
||||
ref="actionRef"
|
||||
:actionColumn="actionColumn"
|
||||
@update:checked-row-keys="onCheckedRow"
|
||||
:scroll-x="1090"
|
||||
:resizeHeightOffset="-10000"
|
||||
size="small"
|
||||
>
|
||||
<template #tableTitle>
|
||||
@{ if eq .options.Step.HasAdd true } <n-button
|
||||
type="primary"
|
||||
@click="addTable"
|
||||
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"
|
||||
:disabled="batchDeleteDisabled"
|
||||
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}/delete'])"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<ExportOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
导出
|
||||
</n-button>@{end}
|
||||
</template>
|
||||
</BasicTable>
|
||||
</n-card>
|
||||
@{ if eq .options.Step.HasEdit true } <Edit
|
||||
@reloadTable="reloadTable"
|
||||
@updateShowModal="updateShowModal"
|
||||
:showModal="showModal"
|
||||
:formParams="formParams"
|
||||
/>@{end}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, reactive, ref } from 'vue';
|
||||
import { useDialog, useMessage } from 'naive-ui';
|
||||
import { BasicTable, TableAction } from '@/components/Table';
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
@{.apiImport}
|
||||
import { State, columns, schemas, options, newState } from './model';
|
||||
@{.iconsImport}
|
||||
@{ if eq .options.Step.HasView true } import { useRouter } from 'vue-router';@{end}
|
||||
import { getOptionLabel } from '@/utils/hotgo';
|
||||
@{ if eq .options.Step.HasEdit true } import Edit from './edit.vue';@{end}
|
||||
const { hasPermission } = usePermission();
|
||||
@{ if eq .options.Step.HasView true } const router = useRouter();@{end}
|
||||
const actionRef = ref();
|
||||
const dialog = useDialog();
|
||||
const message = useMessage();
|
||||
const searchFormRef = ref<any>({});
|
||||
const batchDeleteDisabled = ref(true);
|
||||
const checkedIds = ref([]);
|
||||
const showModal = ref(false);
|
||||
const formParams = ref<State>();
|
||||
|
||||
const actionColumn = reactive({
|
||||
width: 300,
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
// fixed: 'right',
|
||||
render(record) {
|
||||
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 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 [register, {}] = useForm({
|
||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||
labelWidth: 80,
|
||||
schemas,
|
||||
});
|
||||
|
||||
const loadDataTable = async (res) => {
|
||||
return await List({ ...searchFormRef.value?.formModel, ...res });
|
||||
};
|
||||
@{ if eq .options.Step.HasAdd true }
|
||||
function addTable() {
|
||||
showModal.value = true;
|
||||
formParams.value = newState(null);
|
||||
}@{end}
|
||||
@{ if or (eq .options.Step.HasAdd true) (eq .options.Step.HasEdit true) }
|
||||
function updateShowModal(value) {
|
||||
showModal.value = value;
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasCheck true } function onCheckedRow(rowKeys) {
|
||||
batchDeleteDisabled.value = rowKeys.length <= 0;
|
||||
checkedIds.value = rowKeys;
|
||||
}@{end}
|
||||
|
||||
function reloadTable() {
|
||||
actionRef.value.reload();
|
||||
}
|
||||
@{ if eq .options.Step.HasView true }
|
||||
function handleView(record: Recordable) {
|
||||
router.push({ name: '@{.varName | LcFirst}View', params: { id: record.@{.pk.TsName} } });
|
||||
}@{end}
|
||||
@{ if eq .options.Step.HasEdit true }
|
||||
function handleEdit(record: Recordable) {
|
||||
showModal.value = true;
|
||||
formParams.value = newState(record as State);
|
||||
}@{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();
|
||||
});
|
||||
},
|
||||
onNegativeClick: () => {
|
||||
// message.error('取消');
|
||||
},
|
||||
});
|
||||
}@{end}
|
||||
|
||||
@{ if eq .options.Step.HasBatchDel true } function handleBatchDelete() {
|
||||
dialog.warning({
|
||||
title: '警告',
|
||||
content: '你确定要批量删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: () => {
|
||||
Delete({ id: checkedIds.value }).then((_res) => {
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
});
|
||||
},
|
||||
onNegativeClick: () => {
|
||||
// message.error('取消');
|
||||
},
|
||||
});
|
||||
}@{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('设为' + getOptionLabel(options.value.sys_normal_disable, status) + '成功');
|
||||
setTimeout(() => {
|
||||
reloadTable();
|
||||
});
|
||||
});
|
||||
}@{end}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
34
server/resource/generate/default/curd/web.model.ts.template
Normal file
34
server/resource/generate/default/curd/web.model.ts.template
Normal file
@@ -0,0 +1,34 @@
|
||||
import { h, ref } from 'vue';
|
||||
import { NAvatar, NImage, NTag, NSwitch, NRate } from 'naive-ui';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { Dicts } from '@/api/dict/dict';
|
||||
@{ if eq .options.Step.HasSwitch true }import { Switch } from '@/api/@{.varName | LcFirst}';@{end}
|
||||
import { isArray, isNullObject } from '@/utils/is';
|
||||
import { getFileExt } from '@/utils/urlUtils';
|
||||
import { defRangeShortcuts, defShortcuts, formatToDate } from '@/utils/dateUtil';
|
||||
import { validate } from '@/utils/validateUtil';
|
||||
import { getOptionLabel, getOptionTag, Options, errorImg } from '@/utils/hotgo';
|
||||
@{ if eq .options.Step.HasSwitch true }
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
const { hasPermission } = usePermission();
|
||||
const $message = window['$message'];
|
||||
@{end}
|
||||
|
||||
@{.state}
|
||||
|
||||
@{.defaultState}
|
||||
|
||||
export function newState(state: State | null): State {
|
||||
if (state !== null) {
|
||||
return cloneDeep(state);
|
||||
}
|
||||
return cloneDeep(defaultState);
|
||||
}
|
||||
|
||||
@{.dictOptions.const}
|
||||
@{.rules}
|
||||
@{.formSchema}
|
||||
@{.columns}
|
||||
@{.dictOptions.load}
|
||||
|
48
server/resource/generate/default/curd/web.view.vue.template
Normal file
48
server/resource/generate/default/curd/web.view.vue.template
Normal file
@@ -0,0 +1,48 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="n-layout-page-header">
|
||||
<n-card :bordered="false" title="@{.tableComment}详情"> <!-- CURD详情页--> </n-card>
|
||||
</div>
|
||||
<n-card :bordered="false" class="proCard mt-4" size="small" :segmented="{ content: true }">
|
||||
<n-descriptions label-placement="left" class="py-2" column="4">
|
||||
@{.item}
|
||||
</n-descriptions>
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { View } from '@{.importWebApi}';
|
||||
import { newState, options } from './model';
|
||||
import { getOptionLabel, getOptionTag } from '@/utils/hotgo';
|
||||
import { getFileExt } from '@/utils/urlUtils';
|
||||
|
||||
const message = useMessage();
|
||||
const router = useRouter();
|
||||
const id = Number(router.currentRoute.value.params.id);
|
||||
const formValue = ref(newState(null));
|
||||
const fileAvatarCSS = computed(() => {
|
||||
return {
|
||||
'--n-merged-size': `var(--n-avatar-size-override, 80px)`,
|
||||
'--n-font-size': `18px`,
|
||||
};
|
||||
});
|
||||
|
||||
//下载
|
||||
function download(url: string) {
|
||||
window.open(url);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (id < 1) {
|
||||
message.error('@{.pk.Dc}不正确,请检查!');
|
||||
return;
|
||||
}
|
||||
formValue.value = await View({ @{.pk.TsName}: id });
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
Reference in New Issue
Block a user