This commit is contained in:
Daniel 2025-07-28 22:53:04 +08:00
parent 0816925e76
commit f7d28dc1de
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -3038,15 +3038,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID { if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID {
if groupView := view.GetGroup(groupID); nil != groupView { if groupView := view.GetGroup(groupID); nil != groupView {
if keyValues, _ := attrView.GetKeyValues(groupKey.ID); nil != keyValues { if keyValues, _ := attrView.GetKeyValues(groupKey.ID); nil != keyValues {
var newValue *av.Value newValue := getNewValueByNearItem(nearItem, groupKey, blockID)
if nil != nearItem {
defaultVal := nearItem.GetValue(groupKey.ID)
newValue = defaultVal.Clone()
}
if nil == newValue {
newValue = av.GetAttributeViewDefaultValue(ast.NewNodeID(), groupKey.ID, blockID, groupKey.Type)
}
if av.KeyTypeBlock == newValue.Type { if av.KeyTypeBlock == newValue.Type {
// 如果是主键的话前面已经添加过了,这里仅修改内容 // 如果是主键的话前面已经添加过了,这里仅修改内容
blockValue.Block.Content = newValue.Block.Content blockValue.Block.Content = newValue.Block.Content
@ -3079,6 +3071,17 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
return return
} }
func getNewValueByNearItem(nearItem av.Item, key *av.Key, blockID string) (ret *av.Value) {
if nil != nearItem {
defaultVal := nearItem.GetValue(key.ID)
ret = defaultVal.Clone()
}
if nil == ret {
ret = av.GetAttributeViewDefaultValue(ast.NewNodeID(), key.ID, blockID, key.Type)
}
return
}
func getNearItem(attrView *av.AttributeView, view, groupView *av.View, previousItemID string) (ret av.Item) { func getNearItem(attrView *av.AttributeView, view, groupView *av.View, previousItemID string) (ret av.Item) {
viewable := sql.RenderGroupView(attrView, view, groupView) viewable := sql.RenderGroupView(attrView, view, groupView)
av.Filter(viewable, attrView) av.Filter(viewable, attrView)
@ -3566,33 +3569,31 @@ func sortAttributeViewRow(operation *Operation) (err error) {
} }
groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...) groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...)
targetGroupView := groupView if operation.GroupID != operation.TargetGroupID { // 跨分组排序
if operation.GroupID != operation.TargetGroupID { // 跨分组拖拽 if targetGroupView := view.GetGroup(operation.TargetGroupID); nil != targetGroupView {
targetGroupView = view.GetGroup(operation.TargetGroupID) groupKey := view.GetGroupKey(attrView)
} nearItem := getNearItem(attrView, view, targetGroupView, operation.PreviousID)
if nil != targetGroupView { newValue := getNewValueByNearItem(nearItem, groupKey, operation.ID)
groupKey := view.GetGroupKey(attrView) val := attrView.GetValue(groupKey.ID, operation.ID)
nearItem := getNearItem(attrView, view, targetGroupView, operation.PreviousID) newValueRaw := newValue.GetValByType(groupKey.Type)
var newValue *av.Value val.SetValByType(groupKey.Type, newValueRaw)
if nil != nearItem {
defaultVal := nearItem.GetValue(view.Group.Field)
newValue = defaultVal.Clone()
}
if nil == newValue {
newValue = av.GetAttributeViewDefaultValue(ast.NewNodeID(), groupKey.ID, operation.ID, groupKey.Type)
for i, r := range targetGroupView.GroupItemIDs {
if r == operation.PreviousID {
previousIndex = i + 1
break
}
}
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
} }
val := attrView.GetValue(groupKey.ID, operation.ID) } else { // 同分组内排序
newValueRaw := newValue.GetValByType(groupKey.Type) for i, r := range groupView.GroupItemIDs {
val.SetValByType(groupKey.Type, newValueRaw)
for i, r := range targetGroupView.GroupItemIDs {
if r == operation.PreviousID { if r == operation.PreviousID {
previousIndex = i + 1 previousIndex = i + 1
break break
} }
} }
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID) groupView.GroupItemIDs = util.InsertElem(groupView.GroupItemIDs, previousIndex, itemID)
} }
} }
} else { } else {