From 7097610fad64f360e0d437ce13f158df596a9cb8 Mon Sep 17 00:00:00 2001 From: Yavolte Date: Fri, 11 Apr 2025 15:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E9=80=89=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- condition.go | 21 ++++++++------------- rest.go | 16 +++++++++++----- types/attribute.go | 37 +++++++++++++++++++------------------ types/schema.go | 12 ++++-------- 4 files changed, 42 insertions(+), 44 deletions(-) diff --git a/condition.go b/condition.go index dd68330..2395490 100644 --- a/condition.go +++ b/condition.go @@ -82,24 +82,19 @@ func BuildConditions(ctx context.Context, r *http.Request, query *Query, schemas if row.Native == 0 { continue } - if row.Format == "multiSelect" { - columnName := row.Column + "[]" - if qs.Has(columnName) && len(qs[columnName]) > 0 { - query.AndFilterWhere(newConditionWithOperator("IN", row.Column, qs[columnName])) - continue - } + //如果是多选的话,直接使用IN操作 + columnName := row.Column + "[]" + if qs.Has(columnName) && len(qs[columnName]) > 1 { + query.AndFilterWhere(newConditionWithOperator("IN", row.Column, qs[columnName])) + continue } formValue = qs.Get(row.Column) switch row.Format { case types.FormatString, types.FormatText: - if len(qs[row.Column]) > 0 { - query.AndFilterWhere(newConditionWithOperator("IN", row.Column, qs[row.Column])) + if row.Attribute.Match == types.MatchExactly { + query.AndFilterWhere(newCondition(row.Column, formValue)) } else { - if row.Attribute.Match == types.MatchExactly { - query.AndFilterWhere(newCondition(row.Column, formValue)) - } else { - query.AndFilterWhere(newCondition(row.Column, formValue).WithExpr("LIKE")) - } + query.AndFilterWhere(newCondition(row.Column, formValue).WithExpr("LIKE")) } case types.FormatTime, types.FormatDate, types.FormatDatetime, types.FormatTimestamp: var sep string diff --git a/rest.go b/rest.go index ecf42b5..96affda 100644 --- a/rest.go +++ b/rest.go @@ -4,6 +4,12 @@ import ( "context" "errors" "fmt" + "net/http" + "reflect" + "strconv" + "strings" + "time" + "git.nobla.cn/golang/kos/util/arrays" "git.nobla.cn/golang/kos/util/reflection" "git.nobla.cn/golang/rest/inflector" @@ -11,11 +17,6 @@ import ( "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" - "net/http" - "reflect" - "strconv" - "strings" - "time" ) var ( @@ -312,6 +313,11 @@ func fieldAttribute(field *schema.Field) types.Attribute { attr.Live.Columns = strings.Split(kv[1], ",") } } + if attr.Live.Enable { + if attr.Live.Method == "" { + attr.Live.Method = "GET" + } + } attr.Match = types.MatchExactly } diff --git a/types/attribute.go b/types/attribute.go index c7809b5..baff7b5 100644 --- a/types/attribute.go +++ b/types/attribute.go @@ -7,24 +7,25 @@ import ( type ( Attribute struct { - Match string `json:"match"` //匹配模式 - Tag string `json:"tag,omitempty"` //字段标签 - PrimaryKey bool `json:"primary_key"` //是否为主键 - DefaultValue string `json:"default_value"` //默认值 - Readonly []string `json:"readonly"` //只读场景 - Disable []string `json:"disable"` //禁用场景 - Visible []VisibleCondition `json:"visible"` //可见条 - Invisible bool `json:"invisible"` //不可见的字段,表示在UI界面看不到这个字段,但是这个字段需要 - EndOfNow bool `json:"end_of_now"` //最大时间为当前时间 - Values []EnumValue `json:"values"` //值 - Live LiveValue `json:"live"` //延时加载配置 - UploadUrl string `json:"upload_url,omitempty"` //上传地址 - Icon string `json:"icon,omitempty"` //显示图标 - Sort bool `json:"sort"` //是否允许排序 - Suffix string `json:"suffix,omitempty"` //追加内容 - Tooltip string `json:"tooltip,omitempty"` //字段提示信息 - Description string `json:"description,omitempty"` //字段说明信息 - DropdownOption *DropdownOption `json:"dropdown,omitempty"` //下拉选项 + Match string `json:"match"` //匹配模式 + Tag string `json:"tag,omitempty"` //字段标签 + PrimaryKey bool `json:"primary_key"` //是否为主键 + DefaultValue string `json:"default_value"` //默认值 + Readonly []string `json:"readonly"` //只读场景 + Disable []string `json:"disable"` //禁用场景 + Visible []VisibleCondition `json:"visible"` //显示场景 + Invisible bool `json:"invisible"` //不可见的字段,表示在UI界面看不到这个字段,但是这个字段需要 + EndOfNow bool `json:"end_of_now"` //最大时间为当前时间 + Values []EnumValue `json:"values"` //枚举的值 + Live LiveValue `json:"live"` //延时加载配置 + UploadUrl string `json:"upload_url,omitempty"` //上传地址 + Icon string `json:"icon,omitempty"` //显示图标 + Sort bool `json:"sort"` //是否允许排序 + Suffix string `json:"suffix,omitempty"` //追加内容 + Tooltip string `json:"tooltip,omitempty"` //字段提示信息 + Description string `json:"description,omitempty"` //字段说明信息 + MultipleForSearch bool `json:"multiple_for_search"` //下拉选择是否允许在搜索的时候多选 + DropdownOption *DropdownOption `json:"dropdown,omitempty"` //下拉选项 } ) diff --git a/types/schema.go b/types/schema.go index 2866135..fb20a0c 100644 --- a/types/schema.go +++ b/types/schema.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "slices" ) type ( @@ -22,8 +23,8 @@ type ( } VisibleCondition struct { - Column string `json:"column"` - Values []interface{} `json:"values"` + Column string `json:"column"` + Values []any `json:"values"` } DropdownOption struct { @@ -58,12 +59,7 @@ type ( ) func (n Scenarios) Has(str string) bool { - for _, v := range n { - if v == str { - return true - } - } - return false + return slices.Contains(n, str) } // Scan implements the Scanner interface.