修改多选的逻辑
This commit is contained in:
parent
44e6e2b34f
commit
7097610fad
21
condition.go
21
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
|
||||
|
|
16
rest.go
16
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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"` //下拉选项
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue