mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-10 11:13:44 +08:00
发布v2.15.1版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -6,59 +6,135 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
const (
|
||||
IndexApiImport = " import {%v } from '@/api/%s';" // 这里将导入的包路径写死了,后面可以优化成根据配置动态读取
|
||||
IndexApiAddonsImport = " import {%v } from '@/api/addons/%s/%s';"
|
||||
IndexIconsImport = " import {%v } from '@vicons/antd';"
|
||||
)
|
||||
|
||||
func (l *gCurd) webIndexTplData(ctx context.Context, in *CurdPreviewInput) (g.Map, error) {
|
||||
var (
|
||||
data = make(g.Map)
|
||||
apiImport = []string{" List"}
|
||||
iconsImport []string
|
||||
data = make(g.Map)
|
||||
importBuffer = bytes.NewBuffer(nil)
|
||||
importVueMethod = []string{"h", "reactive", "ref", "computed"}
|
||||
importApiMethod = []string{"List"}
|
||||
importModelMethod = []string{"columns", "schemas"}
|
||||
importUtilsMethod = []string{"adaTableScrollX"}
|
||||
importIcons []string
|
||||
actionWidth int64 = 72
|
||||
)
|
||||
|
||||
// 添加
|
||||
if in.options.Step.HasAdd {
|
||||
iconsImport = append(iconsImport, " PlusOutlined")
|
||||
importIcons = append(importIcons, "PlusOutlined")
|
||||
}
|
||||
|
||||
// 编辑
|
||||
// if in.options.Step.HasEdit {
|
||||
// }
|
||||
if in.options.Step.HasEdit {
|
||||
in.options.Step.ActionColumnWidth += actionWidth
|
||||
if in.options.Step.IsTreeTable && !in.options.Step.IsOptionTreeTable {
|
||||
in.options.Step.ActionColumnWidth += actionWidth
|
||||
}
|
||||
if in.options.Step.IsOptionTreeTable {
|
||||
importIcons = append(importIcons, "EditOutlined")
|
||||
}
|
||||
}
|
||||
|
||||
// 导出
|
||||
if in.options.Step.HasExport {
|
||||
iconsImport = append(iconsImport, " ExportOutlined")
|
||||
apiImport = append(apiImport, " Export")
|
||||
importIcons = append(importIcons, "ExportOutlined")
|
||||
importApiMethod = append(importApiMethod, "Export")
|
||||
}
|
||||
|
||||
// 删除
|
||||
if in.options.Step.HasDel || in.options.Step.HasBatchDel {
|
||||
iconsImport = append(iconsImport, " DeleteOutlined")
|
||||
apiImport = append(apiImport, " Delete")
|
||||
if in.options.Step.HasDel {
|
||||
importApiMethod = append(importApiMethod, "Delete")
|
||||
in.options.Step.ActionColumnWidth += actionWidth
|
||||
}
|
||||
|
||||
// 导出
|
||||
// 批量删除
|
||||
if in.options.Step.HasBatchDel {
|
||||
importIcons = append(importIcons, "DeleteOutlined")
|
||||
importApiMethod = append(importApiMethod, "Delete")
|
||||
}
|
||||
|
||||
// 修改状态
|
||||
if in.options.Step.HasStatus {
|
||||
apiImport = append(apiImport, " Status")
|
||||
importApiMethod = append(importApiMethod, "Status")
|
||||
importUtilsMethod = append(importUtilsMethod, "getOptionLabel")
|
||||
importModelMethod = append(importModelMethod, "options")
|
||||
in.options.Step.ActionColumnWidth += actionWidth
|
||||
}
|
||||
|
||||
if in.Config.Application.Crud.Templates[in.In.GenTemplate].IsAddon {
|
||||
data["apiImport"] = fmt.Sprintf(IndexApiAddonsImport, gstr.Implode(",", apiImport), in.In.AddonName, gstr.LcFirst(in.In.VarName))
|
||||
} else {
|
||||
data["apiImport"] = fmt.Sprintf(IndexApiImport, gstr.Implode(",", apiImport), gstr.LcFirst(in.In.VarName))
|
||||
// 更多
|
||||
// 查看详情
|
||||
if in.options.Step.HasView {
|
||||
in.options.Step.ActionColumnWidth += actionWidth
|
||||
}
|
||||
if len(iconsImport) > 0 {
|
||||
data["iconsImport"] = fmt.Sprintf(IndexIconsImport, gstr.Implode(",", iconsImport))
|
||||
|
||||
// 展开树
|
||||
if in.options.Step.IsTreeTable {
|
||||
importIcons = append(importIcons, "AlignLeftOutlined")
|
||||
}
|
||||
|
||||
// 存在字典数据选项
|
||||
if in.options.DictOps.Has {
|
||||
importVueMethod = append(importVueMethod, "onMounted")
|
||||
importModelMethod = append(importModelMethod, "loadOptions")
|
||||
}
|
||||
|
||||
// 普通树表
|
||||
if in.options.Step.IsTreeTable && !in.options.Step.IsOptionTreeTable {
|
||||
importUtilsMethod = append(importUtilsMethod, "convertListToTree")
|
||||
}
|
||||
|
||||
// 选项式树表
|
||||
if in.options.Step.IsOptionTreeTable {
|
||||
importVueMethod = append(importVueMethod, []string{"onMounted", "unref"}...)
|
||||
importIcons = append(importIcons, []string{"FormOutlined", "SearchOutlined"}...)
|
||||
importApiMethod = append(importApiMethod, "TreeOption")
|
||||
importUtilsMethod = append(importUtilsMethod, "getTreeKeys")
|
||||
importModelMethod = append(importModelMethod, []string{"loadTreeOption", "treeOption", "State"}...)
|
||||
}
|
||||
|
||||
// 操作按钮宽度最小值
|
||||
if in.options.Step.ActionColumnWidth > 0 && in.options.Step.ActionColumnWidth < actionWidth*2 {
|
||||
in.options.Step.ActionColumnWidth = 100
|
||||
}
|
||||
|
||||
// 导入基础包
|
||||
importBuffer.WriteString(" import " + ImportWebMethod(importVueMethod) + " from 'vue';\n")
|
||||
importBuffer.WriteString(" import { useDialog, useMessage } from 'naive-ui';\n")
|
||||
importBuffer.WriteString(" import { BasicTable, TableAction } from '@/components/Table';\n")
|
||||
importBuffer.WriteString(" import { BasicForm, useForm } from '@/components/Form/index';\n")
|
||||
importBuffer.WriteString(" import { usePermission } from '@/hooks/web/usePermission';\n")
|
||||
|
||||
// 导入api
|
||||
importBuffer.WriteString(" import " + ImportWebMethod(importApiMethod) + " from '" + in.options.ImportWebApi + "';\n")
|
||||
|
||||
// 导入icons
|
||||
if len(importIcons) > 0 {
|
||||
importBuffer.WriteString(" import " + ImportWebMethod(importIcons) + " from '@vicons/antd';\n")
|
||||
}
|
||||
|
||||
// 导入model
|
||||
if in.options.Step.IsTreeTable {
|
||||
importModelMethod = append(importModelMethod, "newState")
|
||||
}
|
||||
importBuffer.WriteString(" import " + ImportWebMethod(importModelMethod) + " from './model';\n")
|
||||
|
||||
// 导入utils
|
||||
if len(importUtilsMethod) > 0 {
|
||||
importBuffer.WriteString(" import " + ImportWebMethod(importUtilsMethod) + " from '@/utils/hotgo';\n")
|
||||
}
|
||||
|
||||
// 导入edit组件
|
||||
if in.options.Step.HasEdit {
|
||||
importBuffer.WriteString(" import Edit from './edit.vue';\n")
|
||||
}
|
||||
|
||||
// 导入view组件
|
||||
if in.options.Step.HasView {
|
||||
importBuffer.WriteString(" import View from './view.vue';\n")
|
||||
}
|
||||
|
||||
// 没有需要查询的字段则隐藏搜索表单
|
||||
@@ -83,5 +159,6 @@ func (l *gCurd) webIndexTplData(ctx context.Context, in *CurdPreviewInput) (g.Ma
|
||||
}
|
||||
}
|
||||
data["isSearchForm"] = isSearchForm
|
||||
data["import"] = importBuffer.String()
|
||||
return data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user