修改多选的逻辑

This commit is contained in:
Yavolte 2025-04-11 15:24:49 +08:00
parent 44e6e2b34f
commit 7097610fad
4 changed files with 42 additions and 44 deletions

View File

@ -82,25 +82,20 @@ func BuildConditions(ctx context.Context, r *http.Request, query *Query, schemas
if row.Native == 0 { if row.Native == 0 {
continue continue
} }
if row.Format == "multiSelect" { //如果是多选的话直接使用IN操作
columnName := row.Column + "[]" columnName := row.Column + "[]"
if qs.Has(columnName) && len(qs[columnName]) > 0 { if qs.Has(columnName) && len(qs[columnName]) > 1 {
query.AndFilterWhere(newConditionWithOperator("IN", row.Column, qs[columnName])) query.AndFilterWhere(newConditionWithOperator("IN", row.Column, qs[columnName]))
continue continue
} }
}
formValue = qs.Get(row.Column) formValue = qs.Get(row.Column)
switch row.Format { switch row.Format {
case types.FormatString, types.FormatText: case types.FormatString, types.FormatText:
if len(qs[row.Column]) > 0 {
query.AndFilterWhere(newConditionWithOperator("IN", row.Column, qs[row.Column]))
} else {
if row.Attribute.Match == types.MatchExactly { if row.Attribute.Match == types.MatchExactly {
query.AndFilterWhere(newCondition(row.Column, formValue)) query.AndFilterWhere(newCondition(row.Column, formValue))
} else { } 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: case types.FormatTime, types.FormatDate, types.FormatDatetime, types.FormatTimestamp:
var sep string var sep string
seps := []byte{',', '/'} seps := []byte{',', '/'}

16
rest.go
View File

@ -4,6 +4,12 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"net/http"
"reflect"
"strconv"
"strings"
"time"
"git.nobla.cn/golang/kos/util/arrays" "git.nobla.cn/golang/kos/util/arrays"
"git.nobla.cn/golang/kos/util/reflection" "git.nobla.cn/golang/kos/util/reflection"
"git.nobla.cn/golang/rest/inflector" "git.nobla.cn/golang/rest/inflector"
@ -11,11 +17,6 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
"net/http"
"reflect"
"strconv"
"strings"
"time"
) )
var ( var (
@ -312,6 +313,11 @@ func fieldAttribute(field *schema.Field) types.Attribute {
attr.Live.Columns = strings.Split(kv[1], ",") attr.Live.Columns = strings.Split(kv[1], ",")
} }
} }
if attr.Live.Enable {
if attr.Live.Method == "" {
attr.Live.Method = "GET"
}
}
attr.Match = types.MatchExactly attr.Match = types.MatchExactly
} }

View File

@ -13,10 +13,10 @@ type (
DefaultValue string `json:"default_value"` //默认值 DefaultValue string `json:"default_value"` //默认值
Readonly []string `json:"readonly"` //只读场景 Readonly []string `json:"readonly"` //只读场景
Disable []string `json:"disable"` //禁用场景 Disable []string `json:"disable"` //禁用场景
Visible []VisibleCondition `json:"visible"` //可见条 Visible []VisibleCondition `json:"visible"` //显示场景
Invisible bool `json:"invisible"` //不可见的字段表示在UI界面看不到这个字段但是这个字段需要 Invisible bool `json:"invisible"` //不可见的字段表示在UI界面看不到这个字段但是这个字段需要
EndOfNow bool `json:"end_of_now"` //最大时间为当前时间 EndOfNow bool `json:"end_of_now"` //最大时间为当前时间
Values []EnumValue `json:"values"` // Values []EnumValue `json:"values"` //枚举的
Live LiveValue `json:"live"` //延时加载配置 Live LiveValue `json:"live"` //延时加载配置
UploadUrl string `json:"upload_url,omitempty"` //上传地址 UploadUrl string `json:"upload_url,omitempty"` //上传地址
Icon string `json:"icon,omitempty"` //显示图标 Icon string `json:"icon,omitempty"` //显示图标
@ -24,6 +24,7 @@ type (
Suffix string `json:"suffix,omitempty"` //追加内容 Suffix string `json:"suffix,omitempty"` //追加内容
Tooltip string `json:"tooltip,omitempty"` //字段提示信息 Tooltip string `json:"tooltip,omitempty"` //字段提示信息
Description string `json:"description,omitempty"` //字段说明信息 Description string `json:"description,omitempty"` //字段说明信息
MultipleForSearch bool `json:"multiple_for_search"` //下拉选择是否允许在搜索的时候多选
DropdownOption *DropdownOption `json:"dropdown,omitempty"` //下拉选项 DropdownOption *DropdownOption `json:"dropdown,omitempty"` //下拉选项
} }
) )

View File

@ -2,6 +2,7 @@ package types
import ( import (
"encoding/json" "encoding/json"
"slices"
) )
type ( type (
@ -23,7 +24,7 @@ type (
VisibleCondition struct { VisibleCondition struct {
Column string `json:"column"` Column string `json:"column"`
Values []interface{} `json:"values"` Values []any `json:"values"`
} }
DropdownOption struct { DropdownOption struct {
@ -58,12 +59,7 @@ type (
) )
func (n Scenarios) Has(str string) bool { func (n Scenarios) Has(str string) bool {
for _, v := range n { return slices.Contains(n, str)
if v == str {
return true
}
}
return false
} }
// Scan implements the Scanner interface. // Scan implements the Scanner interface.