Merge pull request #61 from bufanyun/v2.0

发布v2.15.1版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/…
This commit is contained in:
maxbad
2024-04-23 10:28:55 +08:00
committed by GitHub
445 changed files with 17457 additions and 6708 deletions

View File

@@ -1,6 +1,6 @@
// Package config
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package config

View File

@@ -1,6 +1,6 @@
// Package index
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package index

View File

@@ -1,6 +1,6 @@
// Package index
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package index

View File

@@ -1,6 +1,6 @@
// Package index
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package index

View File

@@ -1,6 +1,6 @@
// Package index
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package index

View File

@@ -0,0 +1,9 @@
// Package consts
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package consts
// 常量枚举.
// 插件中的常量枚举可以统一在这目录下

View File

@@ -1,6 +1,6 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys

View File

@@ -1,6 +1,6 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys

View File

@@ -1,6 +1,6 @@
// Package api
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package api

View File

@@ -1,6 +1,6 @@
// Package home
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package home

View File

@@ -1,6 +1,6 @@
// Package websocket
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package websocket

View File

@@ -1,6 +1,6 @@
// Package crons
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package crons

View File

@@ -1,6 +1,6 @@
// Package global
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package global

View File

@@ -1,6 +1,6 @@
// Package global
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package global

View File

@@ -1,6 +1,6 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys

View File

@@ -1,6 +1,6 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys

View File

@@ -1,6 +1,6 @@
// Package @{.name}
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package @{.name}

View File

@@ -1,6 +1,6 @@
// Package model
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package model

View File

@@ -1,6 +1,6 @@
// Package sysin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sysin

View File

@@ -1,6 +1,6 @@
// Package sysin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
//

View File

@@ -1,6 +1,6 @@
// Package queues
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package queues

View File

@@ -1,6 +1,6 @@
// Package router
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package router

View File

@@ -1,6 +1,6 @@
// Package router
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package router

View File

@@ -1,6 +1,6 @@
// Package genrouter
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package genrouter

View File

@@ -1,6 +1,6 @@
// Package router
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package router

View File

@@ -1,6 +1,6 @@
// Package router
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package router

View File

@@ -11,6 +11,7 @@ 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}列表
@@ -90,3 +91,11 @@ type SwitchReq struct {
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}

View File

@@ -11,7 +11,7 @@ import (
"context"
"@{.importApi}"
"hotgo/internal/model/input/form"
"hotgo/internal/model/input/@{.templateGroup}in"
"@{.importInput}"
"@{.importService}"
"hotgo/utility/validate"
)
@@ -98,4 +98,12 @@ func (c *c@{.varName}) Switch(ctx context.Context, req *@{.varName | ToLower}.Sw
err = service.@{.servFunName}().Switch(ctx, &req.@{.varName}SwitchInp)
return
}
@{end}
@{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)
res = (*@{.varName | ToLower}.TreeOptionRes)(&data)
return
}
@{end}

View File

@@ -18,6 +18,8 @@ import (
"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}字段过滤
@@ -65,7 +67,7 @@ func (in *@{.varName}ViewInp) Filter(ctx context.Context) (err error) {
}
type @{.varName}ViewModel struct {
entity.@{.daoName}
@{.viewModelColumns}
}@{end}
// @{.varName}ListInp 获取@{.tableComment}列表
@@ -138,4 +140,28 @@ func (in *@{.varName}SwitchInp) Filter(ctx context.Context) (err error) {
}
type @{.varName}SwitchModel struct{}
@{end}
@{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}

View File

@@ -17,15 +17,21 @@ import (
"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 eq .options.Step.HasFuncDict true }"hotgo/internal/model"@{end}
)
type s@{.servFunName} struct{}
@@ -36,7 +42,7 @@ func New@{.servFunName}() *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 {
@@ -46,26 +52,45 @@ func (s *s@{.servFunName}) Model(ctx context.Context, option ...*handler.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}
@{.listJoin.link}
totalCount, err = mod.Clone().Count()
if err != nil {
err = gerror.Wrap(err, "获取@{.tableComment}数据行失败,请稍后重试!")
return
@{ if eq .options.Step.IsTreeTable true }
// 树形列表判断是否需要分页
if in.Pagination {
mod = mod.Page(in.Page, in.PerPage)
}
@{end}
if totalCount == 0 {
return
}
@{ if eq .options.Step.IsTreeTable false }
// 分页
mod = mod.Page(in.Page, in.PerPage)
@{end}
@{.listJoin.select}
// 排序
mod = mod.@{.listOrder}
if err = mod.Fields(@{.listJoin.fields}).Page(in.Page, in.PerPage).@{.listOrder}.Scan(&list);err != nil {
@{ 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) {
@@ -81,7 +106,7 @@ func (s *s@{.servFunName}) Export(ctx context.Context, in *@{.templateGroup}in.@
}
var (
fileName = "导出@{.tableComment}-" + gctx.CtxId(ctx) + ".xlsx"
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
)
@@ -93,28 +118,45 @@ func (s *s@{.servFunName}) Export(ctx context.Context, in *@{.templateGroup}in.@
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} // 修改
if in.@{.pk.GoName} > 0 {
@{.edit.update}
}
@{.edit.unique} 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
// 新增
@{.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 _, err = s.Model(ctx@{ if eq .options.Step.HasNotFilterAuth true } ,&handler.Option{FilterAuth: false}@{end}).WherePri(in.@{.pk.GoName}).Delete();err != nil {
err = gerror.Wrap(err, "删除@{.tableComment}失败,请稍后重试!")
return
}
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) {
@@ -131,15 +173,17 @@ func (s *s@{.servFunName}) MaxSort(ctx context.Context, in *@{.templateGroup}in.
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}).Scan(&res);err != nil {
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) {
@@ -150,12 +194,12 @@ func (s *s@{.servFunName}) Status(ctx context.Context, in *@{.templateGroup}in.@
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}
// ...
@{.switchFields} // ...
}
if !validate.InSlice(fields, in.Key) {
@@ -169,4 +213,38 @@ func (s *s@{.servFunName}) Switch(ctx context.Context, in *@{.templateGroup}in.@
}
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 []*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}

View File

@@ -1,5 +1,5 @@
-- hotgo自动生成菜单权限SQL 通常情况下只在首次生成代码时自动执行一次
-- 如需再次执行请先手动删除生成的菜单权限和SQL文件@{.generatePath}
-- 如需再次执行请先手动删除生成的菜单权限和SQL文件@{.generatePath}
-- Version: @{.hgVersion}
-- Date: @{.nowTime}
-- Link https://github.com/bufanyun/hotgo
@@ -23,7 +23,7 @@ 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', '@{.dirLevel}', '@{.dirTree}', '@{.options.Menu.Sort}', '', '1', @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();
@@ -31,7 +31,7 @@ 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', '@{.listLevel}', CONCAT('@{.dirTree}tr_', @dirId,' '), '10', '', '1', @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, @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();
@@ -67,5 +67,8 @@ INSERT INTO `@{.menuTable}` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type
-- 导出
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;

View File

@@ -72,4 +72,13 @@ export function MaxSort() {
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}

View File

@@ -1,55 +1,90 @@
<template>
<div>
<n-spin :show="loading" description="请稍候...">
<n-modal
v-model:show="showModal"
:mask-closable="false"
:show-icon="false"
preset="dialog"
transform-origin="center"
:title="formValue.@{.pk.TsName} > 0 ? '编辑 #' + formValue.@{.pk.TsName} : '添加'"
:style="{
width: dialogWidth,
}"
>
<n-scrollbar style="max-height: 87vh" class="pr-5">
<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
:model="formValue"
:rules="rules"
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"
>
@{.formItem}
<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-scrollbar>
<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>
</n-spin>
</n-scrollbar>
<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>
</div>
</template>
<script lang="ts" setup>
@{.script.import} import { rules, options, State, newState } from './model';
import { useProjectSettingStore } from '@/store/modules/projectSetting';
@{.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();
const dialogWidth = ref('75%');
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);
});
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;
});
}
function confirmForm(e) {
e.preventDefault();
@@ -59,7 +94,7 @@
Edit(formValue.value).then((_res) => {
message.success('操作成功');
setTimeout(() => {
showModal.value = false;
closeForm();
emit('reloadTable');
});
});
@@ -76,11 +111,10 @@
loading.value = false;
}
@{.script.setup}
defineExpose({
openModal,
});
</script>
<style lang="less"></style>

View File

@@ -5,110 +5,206 @@
<!-- 这是由系统生成的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 class="mt-4" 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">
<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="handleEdit(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
@register="register"
@submit="reloadTable"
@reset="reloadTable"
@keyup.enter="reloadTable"
ref="searchFormRef"
>
<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}
</BasicForm>
@{end}
<BasicTable
:openChecked="@{.options.Step.HasCheck}"
:columns="columns"
:request="loadDataTable"
:row-key="(row) => row.id"
ref="actionRef"
:actionColumn="actionColumn"
:checked-row-keys="checkedIds"
@update:checked-row-keys="onCheckedRow"
:scroll-x="1090"
:resizeHeightOffset="-10000"
size="small"
>
<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"
@click="addTable"
class="min-left-space"
v-if="hasPermission(['/@{.apiPrefix}/edit'])"
>
@{ 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"
:disabled="batchDeleteDisabled"
class="min-left-space"
v-if="hasPermission(['/@{.apiPrefix}/delete'])"
>
</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'])"
>
</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}
</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.HasEdit true } <Edit @reloadTable="reloadTable" ref="editRef" />@{end}
@{ 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 { 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 { columns, schemas, options } from './model';
@{.iconsImport}
import { getOptionLabel } from '@/utils/hotgo';
@{ if eq .options.Step.HasEdit true } import Edit from './edit.vue';@{end}
@{ if eq .options.Step.HasView true } import View from './view.vue';@{end}
@{.import}
const dialog = useDialog();
const message = useMessage();
const { hasPermission } = usePermission();
const actionRef = ref();
const searchFormRef = ref<any>({});
const viewRef = ref();
const editRef = ref();
const batchDeleteDisabled = ref(true);
const checkedIds = 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: 300,
width: @{.options.Step.ActionColumnWidth},
title: '操作',
key: 'action',
// fixed: 'right',
fixed: 'right',
render(record) {
return h(TableAction as any, {
style: 'button',
@@ -118,6 +214,11 @@
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),
@@ -156,38 +257,92 @@
},
});
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 eq .options.Step.HasCheck true } function onCheckedRow(rowKeys) {
batchDeleteDisabled.value = rowKeys.length <= 0;
@{ 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();
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) {
@{ if eq .options.Step.HasDel true }
// 单个删除
function handleDelete(record: Recordable) {
dialog.warning({
title: '警告',
content: '你确定要删除',
@@ -202,15 +357,21 @@
});
}@{end}
@{ if eq .options.Step.HasBatchDel true } function handleBatchDelete() {
@{ if eq .options.Step.HasBatchDel true }
// 批量删除
function handleBatchDelete() {
if (checkedIds.value.length < 1){
message.error('请至少选择一项要删除的数据');
return;
}
dialog.warning({
title: '警告',
content: '你确定要批量删除',
positiveText: '确定',
negativeText: '取消',
onPositiveClick: () => {
Delete({ id: checkedIds.value }).then((_res) => {
batchDeleteDisabled.value = true;
Delete({ @{.pk.TsName}: checkedIds.value }).then((_res) => {
checkedIds.value = [];
message.success('删除成功');
reloadTable();
@@ -219,12 +380,16 @@
});
}@{end}
@{ if eq .options.Step.HasExport true } function handleExport() {
@{ 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) {
@{ 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(() => {
@@ -232,6 +397,59 @@
});
});
}@{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 eq .dictOptions.Has true }
onMounted(() => {
loadOptions();@{ if eq .options.Step.IsOptionTreeTable true }
firstLoadTreeOption();@{end}
});@{end}
</script>
<style lang="less" scoped></style>
<style lang="less" scoped></style>

View File

@@ -1,20 +1,14 @@
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 '@{.importWebApi}';@{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, Option, 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}
@{.import}
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) {
@@ -26,10 +20,47 @@ export function newState(state: State | Record<string, any> | null): State {
return new State();
}
@{.dictOptions.interface}
@{.dictOptions.const}
@{.rules}
@{.formSchema}
@{.columns}
@{.dictOptions.load}
// 表单验证规则
@{ if eq .options.Step.HasRules true }@{.rules}@{end}
// 表格搜索表单
@{ if eq .options.Step.HasSearchForm true }@{.formSchema}@{end}
// 表格列
@{.columns}
@{ if eq .dictOptions.Has true }
// 字典数据选项
export const options = ref({
@{range .options.DictOps.Types} @{.}: [] as Option[],
@{end}});
// 加载字典数据选项
export function loadOptions() {
Dicts({
types: @{ToTSArray .options.DictOps.Types},
}).then((res) => {
options.value = res;
for (const item of schemas.value) {
switch (item.field) {@{range .options.DictOps.Schemas}
case '@{.Field}':
item.componentProps.options = options.value.@{.Type};
break;@{end}
}
}
});
}
@{end}
@{ if eq .options.Step.IsTreeTable true }
// 关系树选项
export const treeOption = ref([]);
// 加载关系树选项
export function loadTreeOption() {
TreeOption().then((res) => {
treeOption.value = res;
});
}
@{end}

View File

@@ -1,18 +1,14 @@
<template>
<div>
<n-spin :show="loading" description="请稍候...">
<n-drawer v-model:show="showModal" :width="dialogWidth">
<n-drawer-content>
<template #header> 生成演示详情 </template>
<template #footer>
<n-button @click="showModal = false"> 关闭 </n-button>
</template>
<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}
@{.item}
</n-descriptions>
</n-drawer-content>
</n-drawer>
</n-spin>
</n-spin>
</n-drawer-content>
</n-drawer>
</div>
</template>
@@ -25,10 +21,12 @@
import { getFileExt } from '@/utils/urlUtils';
const message = useMessage();
const dialogWidth = ref('75%');
const loading = ref(false);
const showModal = ref(false);
const formValue = ref(newState(null));
const dialogWidth = computed(() => {
return adaModalWidth(580);
});
const fileAvatarCSS = computed(() => {
return {
'--n-merged-size': `var(--n-avatar-size-override, 80px)`,
@@ -42,10 +40,9 @@
}
function openModal(state: State) {
adaModalWidth(dialogWidth, 580);
showModal.value = true;
loading.value = true;
View({ id: state.id })
View({ @{.pk.TsName}: state.@{.pk.TsName} })
.then((res) => {
formValue.value = res;
})
@@ -60,3 +57,4 @@
</script>
<style lang="less" scoped></style>