mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-12-08 17:26:08 +08:00
发布v2.13.1版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -8,9 +8,11 @@ package views
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/library/dict"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/utility/convert"
|
||||
)
|
||||
@@ -64,36 +66,66 @@ func (l *gCurd) generateWebModelDictOptions(ctx context.Context, in *CurdPreview
|
||||
}
|
||||
|
||||
var (
|
||||
options = make(g.Map)
|
||||
dictTypeIds []int64
|
||||
dictTypeList []*DictType
|
||||
options = make(g.Map)
|
||||
dictTypeIds []int64
|
||||
dictTypeList []*DictType
|
||||
builtinDictTypeIds []int64
|
||||
builtinDictTypeList []*DictType
|
||||
)
|
||||
|
||||
for _, field := range in.masterFields {
|
||||
if field.DictType > 0 {
|
||||
dictTypeIds = append(dictTypeIds, field.DictType)
|
||||
}
|
||||
|
||||
if field.DictType < 0 {
|
||||
builtinDictTypeIds = append(builtinDictTypeIds, field.DictType)
|
||||
}
|
||||
}
|
||||
|
||||
dictTypeIds = convert.UniqueSlice(dictTypeIds)
|
||||
if len(dictTypeIds) == 0 {
|
||||
builtinDictTypeIds = convert.UniqueSlice(builtinDictTypeIds)
|
||||
|
||||
if len(dictTypeIds) == 0 && len(builtinDictTypeIds) == 0 {
|
||||
options["has"] = false
|
||||
return options, nil
|
||||
}
|
||||
|
||||
err := g.Model("sys_dict_type").Ctx(ctx).
|
||||
Fields("id", "type").
|
||||
WhereIn("id", dictTypeIds).
|
||||
Scan(&dictTypeList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(dictTypeIds) > 0 {
|
||||
err := g.Model("sys_dict_type").Ctx(ctx).
|
||||
Fields("id", "type").
|
||||
WhereIn("id", dictTypeIds).
|
||||
Scan(&dictTypeList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if len(dictTypeList) == 0 {
|
||||
if len(builtinDictTypeIds) > 0 {
|
||||
for _, id := range builtinDictTypeIds {
|
||||
opts, err := dict.GetOptionsById(ctx, id)
|
||||
if err != nil && !errors.Is(err, dict.NotExistKeyError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(opts) > 0 {
|
||||
row := new(DictType)
|
||||
row.Id = id
|
||||
row.Type = opts[0].Type
|
||||
builtinDictTypeList = append(builtinDictTypeList, row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(dictTypeList) == 0 && len(builtinDictTypeList) == 0 {
|
||||
options["has"] = false
|
||||
return options, nil
|
||||
}
|
||||
|
||||
if len(builtinDictTypeList) > 0 {
|
||||
dictTypeList = append(dictTypeList, builtinDictTypeList...)
|
||||
}
|
||||
|
||||
options["has"] = true
|
||||
|
||||
var (
|
||||
@@ -109,7 +141,7 @@ func (l *gCurd) generateWebModelDictOptions(ctx context.Context, in *CurdPreview
|
||||
for _, v := range dictTypeList {
|
||||
// 字段映射字典
|
||||
for _, field := range in.masterFields {
|
||||
if field.DictType > 0 && v.Id == field.DictType {
|
||||
if field.DictType != 0 && v.Id == field.DictType {
|
||||
in.options.dictMap[field.TsName] = v.Type
|
||||
switchLoadOptions = fmt.Sprintf("%s case '%s':\n item.componentProps.options = options.value.%s;\n break;\n", switchLoadOptions, field.TsName, v.Type)
|
||||
}
|
||||
@@ -129,7 +161,6 @@ func (l *gCurd) generateWebModelDictOptions(ctx context.Context, in *CurdPreview
|
||||
options["interface"] = interfaceOptionsBuffer.String()
|
||||
options["const"] = constOptionsBuffer.String()
|
||||
options["load"] = loadOptionsBuffer.String()
|
||||
|
||||
return options, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user