修复模版生成model.ts默认值不带引号

This commit is contained in:
lzl 2025-08-18 14:35:59 +08:00
parent 9f1c1ce031
commit ae540c6bfe
2 changed files with 23 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import (
"hotgo/internal/library/dict"
"hotgo/internal/model/input/sysin"
"hotgo/utility/convert"
"strings"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
@ -24,6 +25,7 @@ type StateItem struct {
Name string
DefaultValue interface{}
Dc string
DataType string // 新增字段:存储字段类型信息
}
func (l *gCurd) webModelTplData(ctx context.Context, in *CurdPreviewInput) (data g.Map, err error) {
@ -112,13 +114,20 @@ func (l *gCurd) generateWebModelImport(ctx context.Context, in *CurdPreviewInput
func (l *gCurd) generateWebModelStateItems(ctx context.Context, in *CurdPreviewInput) (items []*StateItem) {
for _, field := range in.masterFields {
dataType := field.DataType
if dataType == "" && field.SqlType != "" {
if parts := strings.SplitN(field.SqlType, "(", 2); len(parts) > 0 {
dataType = parts[0]
}
}
var value = field.DefaultValue
if value == nil {
value = "null"
}
if value == "" {
value = `''`
}
//注释为空判断 避免模版生成的model.ts重复加引号
//if value == "" {
// value = `''`
//}
// 选项组件默认值调整
if gconv.Int(value) == 0 && IsSelectFormMode(field.FormMode) {
@ -145,6 +154,7 @@ func (l *gCurd) generateWebModelStateItems(ctx context.Context, in *CurdPreviewI
items = append(items, &StateItem{
Name: field.TsName + "Summa?: null | MemberSumma",
DefaultValue: "null",
DataType: dataType,
Dc: field.Dc + "摘要信息",
})
}

View File

@ -2,9 +2,16 @@
@{.const}
export class State {@{range .stateItems}
public @{.Name} = @{.DefaultValue}; // @{.Dc}@{end}
export class State {
@{range .stateItems}
public @{.Name} = @{if and .DataType (or
(eq .DataType "varchar")
(eq .DataType "char")
(eq .DataType "text")
(eq .DataType "json")
(eq .DataType "date")
(eq .DataType "datetime")
)}'@{.DefaultValue}'@{else}@{.DefaultValue}@{end};//@{.Dc}@{end}
constructor(state?: Partial<State>) {
if (state) {
Object.assign(this, state);