🎨 Improve av

This commit is contained in:
Daniel 2025-08-13 23:35:16 +08:00
parent cd10072554
commit b78e2edfb8
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 22 additions and 17 deletions

View file

@ -72,10 +72,14 @@ func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query
func RenderView(attrView *av.AttributeView, view *av.View, query string) (ret av.Viewable) {
depth := 1
return renderView(attrView, view, query, &depth)
renderedAttrViews := map[string]*av.AttributeView{}
renderedAttrViews[attrView.ID] = attrView
ret = renderView(attrView, view, query, &depth, renderedAttrViews)
return
}
func renderView(attrView *av.AttributeView, view *av.View, query string, depth *int) (ret av.Viewable) {
func renderView(attrView *av.AttributeView, view *av.View, query string,
depth *int, renderedAttrViews map[string]*av.AttributeView) (ret av.Viewable) {
if 7 < *depth {
return
}
@ -83,9 +87,9 @@ func renderView(attrView *av.AttributeView, view *av.View, query string, depth *
*depth++
switch view.LayoutType {
case av.LayoutTypeTable:
ret = RenderAttributeViewTable(attrView, view, query, depth)
ret = RenderAttributeViewTable(attrView, view, query, depth, renderedAttrViews)
case av.LayoutTypeGallery:
ret = RenderAttributeViewGallery(attrView, view, query, depth)
ret = RenderAttributeViewGallery(attrView, view, query, depth, renderedAttrViews)
}
return
}
@ -321,9 +325,8 @@ func fillAttributeViewBaseValue(baseValue *av.BaseValue, fieldID, itemID string,
}
}
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues, depth *int) {
avCache := map[string]*av.AttributeView{}
avCache[attrView.ID] = attrView
func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection av.Collection, ials map[string]map[string]string, items map[string][]*av.KeyValues,
depth *int, renderedAttrViews map[string]*av.AttributeView) {
for _, item := range collection.GetItems() {
for _, value := range item.GetValues() {
itemID := item.GetID()
@ -354,11 +357,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
break
}
destAv := avCache[relKey.Relation.AvID]
destAv := renderedAttrViews[relKey.Relation.AvID]
if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv {
avCache[relKey.Relation.AvID] = destAv
renderedAttrViews[relKey.Relation.AvID] = destAv
}
}
if nil == destAv {
@ -373,7 +376,7 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
var viewable av.Viewable
if av.KeyTypeTemplate == destKey.Type {
// 渲染目标视图,这样才能汇总渲染后的模板字段值
viewable = renderView(destAv, destAv.Views[0], "", depth)
viewable = renderView(destAv, destAv.Views[0], "", depth, renderedAttrViews)
}
for _, blockID := range relVal.Relation.BlockIDs {
@ -409,11 +412,11 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
value.Relation.Contents = nil
relKey, _ := attrView.GetKey(value.KeyID)
if nil != relKey && nil != relKey.Relation {
destAv := avCache[relKey.Relation.AvID]
destAv := renderedAttrViews[relKey.Relation.AvID]
if nil == destAv {
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
if nil != destAv {
avCache[relKey.Relation.AvID] = destAv
renderedAttrViews[relKey.Relation.AvID] = destAv
}
}
if nil != destAv {