mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-09-17 16:56:39 +08:00
fix model.ts
This commit is contained in:
parent
1688aaf371
commit
e3eb4bd728
@ -124,10 +124,17 @@ func (l *gCurd) generateWebModelStateItems(ctx context.Context, in *CurdPreviewI
|
|||||||
if value == nil {
|
if value == nil {
|
||||||
value = "null"
|
value = "null"
|
||||||
}
|
}
|
||||||
//注释为空判断 避免模版生成的model.ts重复加引号
|
if value == "" {
|
||||||
//if value == "" {
|
// 修复字符串字段为空时的处理
|
||||||
// value = `''`
|
if isStringType(field.TsType, dataType) {
|
||||||
//}
|
value = "" // 模板会自动加引号变成 ''
|
||||||
|
} else {
|
||||||
|
value = "null"
|
||||||
|
}
|
||||||
|
} else if valueStr, ok := value.(string); ok && isStringType(field.TsType, dataType) {
|
||||||
|
// 对于字符串类型,直接使用原值,模板会自动加引号
|
||||||
|
value = valueStr
|
||||||
|
}
|
||||||
|
|
||||||
// 选项组件默认值调整
|
// 选项组件默认值调整
|
||||||
if gconv.Int(value) == 0 && IsSelectFormMode(field.FormMode) {
|
if gconv.Int(value) == 0 && IsSelectFormMode(field.FormMode) {
|
||||||
@ -146,6 +153,7 @@ func (l *gCurd) generateWebModelStateItems(ctx context.Context, in *CurdPreviewI
|
|||||||
items = append(items, &StateItem{
|
items = append(items, &StateItem{
|
||||||
Name: field.TsName,
|
Name: field.TsName,
|
||||||
DefaultValue: value,
|
DefaultValue: value,
|
||||||
|
DataType: dataType,
|
||||||
Dc: field.Dc,
|
Dc: field.Dc,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -452,3 +460,26 @@ func (l *gCurd) generateWebModelColumnsEach(buffer *bytes.Buffer, in *CurdPrevie
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isStringType 判断字段是否为字符串类型
|
||||||
|
func isStringType(tsType, dataType string) bool {
|
||||||
|
// 根据 TypeScript 类型判断
|
||||||
|
if tsType == "string" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据数据库数据类型判断
|
||||||
|
stringTypes := []string{
|
||||||
|
"varchar", "char", "text", "longtext", "mediumtext", "tinytext",
|
||||||
|
"nvarchar", "nchar", "ntext",
|
||||||
|
"string", "enum", "set",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range stringTypes {
|
||||||
|
if strings.EqualFold(dataType, t) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user