This commit is contained in:
Daniel 2025-07-29 13:16:29 +08:00
parent 445a738e74
commit 008cce474a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -1740,7 +1740,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
v.GroupItemIDs = append(v.GroupItemIDs, item.GetID()) v.GroupItemIDs = append(v.GroupItemIDs, item.GetID())
} }
v.Name = "" v.Name = "" // 分组视图的名称在渲染时才填充
v.GroupValue = name v.GroupValue = name
view.Groups = append(view.Groups, v) view.Groups = append(view.Groups, v)
} }
@ -1755,7 +1755,8 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
} }
} }
// 恢复分组视图的顺序 if av.GroupOrderMan == view.Group.Order {
// 恢复分组视图的自定义顺序
if len(groupStates) > 0 { if len(groupStates) > 0 {
sort.SliceStable(view.Groups, func(i, j int) bool { sort.SliceStable(view.Groups, func(i, j int) bool {
if stateI, ok := groupStates[view.Groups[i].GroupValue]; ok { if stateI, ok := groupStates[view.Groups[i].GroupValue]; ok {
@ -1766,8 +1767,70 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
return false return false
}) })
} }
} else {
if av.GroupMethodDateRelative == view.Group.Method {
var monthGroups []*av.View
var last30Days, last7Days, yesterday, today, tomorrow, next7Days, next30Days *av.View
for _, groupView := range view.Groups {
_, err := time.Parse("2006-01", groupView.GroupValue)
if nil == err { // 如果能解析出来说明是 30 天之前或 30 天之后的分组形式
monthGroups = append(monthGroups, groupView)
} else { // 否则是相对日期分组形式
switch groupView.GroupValue {
case groupValueLast30Days:
last30Days = groupView
case groupValueLast7Days:
last7Days = groupView
case groupValueYesterday:
yesterday = groupView
case groupValueToday:
today = groupView
case groupValueTomorrow:
tomorrow = groupView
case groupValueNext7Days:
next7Days = groupView
case groupValueNext30Days:
next30Days = groupView
}
}
}
if av.GroupOrderMan != view.Group.Order { sort.SliceStable(monthGroups, func(i, j int) bool {
return monthGroups[i].GroupValue < monthGroups[j].GroupValue
})
var idx int
thisMonth := todayStart.Format("2006-01")
for i, monthGroup := range monthGroups {
if monthGroup.GroupValue > thisMonth {
idx = i
break
}
}
if nil != next30Days {
util.InsertElem(monthGroups, idx, next30Days)
}
if nil != next7Days {
util.InsertElem(monthGroups, idx, next7Days)
}
if nil != tomorrow {
util.InsertElem(monthGroups, idx, tomorrow)
}
if nil != today {
util.InsertElem(monthGroups, idx, today)
}
if nil != yesterday {
util.InsertElem(monthGroups, idx, yesterday)
}
if nil != last7Days {
util.InsertElem(monthGroups, idx, last7Days)
}
if nil != last30Days {
util.InsertElem(monthGroups, idx, last30Days)
}
view.Groups = monthGroups
} else {
sort.SliceStable(view.Groups, func(i, j int) bool { sort.SliceStable(view.Groups, func(i, j int) bool {
iVal, jVal := view.Groups[i].GroupValue, view.Groups[j].GroupValue iVal, jVal := view.Groups[i].GroupValue, view.Groups[j].GroupValue
if av.GroupOrderAsc == view.Group.Order { if av.GroupOrderAsc == view.Group.Order {
@ -1776,6 +1839,7 @@ func genAttrViewViewGroups(view *av.View, attrView *av.AttributeView) {
return util.NaturalCompare(jVal, iVal) return util.NaturalCompare(jVal, iVal)
}) })
} }
}
} }
func isGroupByDate(view *av.View) bool { func isGroupByDate(view *av.View) bool {