This commit is contained in:
孟帅
2024-11-27 18:44:19 +08:00
parent 6254505a7d
commit 2fd3854aeb
69 changed files with 656 additions and 245 deletions

View File

@@ -136,6 +136,16 @@ func GenHashOption(key interface{}, label string, extra ...any) *model.Option {
}
}
// GetOption 通过key找到label
func GetOption(ses []*model.Option, key interface{}) *model.Option {
for _, v := range ses {
if gconv.String(v.Key) == gconv.String(key) {
return v
}
}
return nil
}
// GetOptionLabel 通过key找到label
func GetOptionLabel(ses []*model.Option, key interface{}) string {
for _, v := range ses {
@@ -155,3 +165,16 @@ func HasOptionKey(ses []*model.Option, key interface{}) bool {
}
return false
}
// UniqueOption 去重选项
func UniqueOption(src []*model.Option) (dst []*model.Option) {
temp := map[string]struct{}{}
for _, item := range src {
key := gconv.String(item.Key)
if _, ok := temp[key]; !ok {
temp[key] = struct{}{}
dst = append(dst, item)
}
}
return dst
}