diff --git a/kernel/av/av.go b/kernel/av/av.go index a886ca49b..76e1b5f00 100644 --- a/kernel/av/av.go +++ b/kernel/av/av.go @@ -200,7 +200,7 @@ type View struct { GroupVal *Value `json:"groupVal,omitempty"` // 分组值 GroupFolded bool `json:"groupFolded"` // 分组是否折叠 GroupHidden int `json:"groupHidden"` // 分组是否隐藏,0:显示,1:空白隐藏,2:手动隐藏 - GroupSort int `json:"groupSort"` // 分组排序值 + GroupSort int `json:"groupSort"` // 分组排序值,用于手动排序 } // GetGroupValue 获取分组视图的分组值。 diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 6011f20b1..ad67571bf 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1742,11 +1742,11 @@ func genAttrViewGroups(view *av.View, attrView *av.AttributeView) { v.GroupVal.MSelect = []*av.ValueSelect{{Content: opt.Name, Color: opt.Color}} } } + v.GroupSort = -1 view.Groups = append(view.Groups, v) } view.GroupCreated = time.Now().UnixMilli() - setAttrViewGroupStates(view, groupStates) } @@ -1784,6 +1784,26 @@ func setAttrViewGroupStates(view *av.View, groupStates map[string]*GroupState) { groupView.GroupSort = state.Sort } } + + defaultGroup := view.GetGroupByGroupValue(groupValueDefault) + if nil != defaultGroup { + if -1 == defaultGroup.GroupSort { + view.RemoveGroupByID(defaultGroup.ID) + } else { + defaultGroup = nil + } + } + + for i, groupView := range view.Groups { + if i != groupView.GroupSort && -1 == groupView.GroupSort { + groupView.GroupSort = i + } + } + + if nil != defaultGroup { + view.Groups = append(view.Groups, defaultGroup) + defaultGroup.GroupSort = len(view.Groups) - 1 + } } func GetCurrentAttributeViewImages(avID, viewID, query string) (ret []string, err error) {