🎨 Card view supports displaying field names https://github.com/siyuan-note/siyuan/issues/15180

This commit is contained in:
Daniel 2025-07-30 10:40:04 +08:00
parent 78c3479fc3
commit 692665f100
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 36 additions and 0 deletions

View file

@ -29,6 +29,7 @@ type LayoutGallery struct {
CardAspectRatio CardAspectRatio `json:"cardAspectRatio"` // 卡片宽高比
CardSize CardSize `json:"cardSize"` // 卡片大小0小卡片1中卡片2大卡片
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
DisplayFieldName bool `json:"displayFieldName"` // 是否显示字段名称
CardFields []*ViewGalleryCardField `json:"fields"` // 卡片字段
@ -94,6 +95,7 @@ type Gallery struct {
CardAspectRatio CardAspectRatio `json:"cardAspectRatio"` // 卡片宽高比
CardSize CardSize `json:"cardSize"` // 卡片大小
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
DisplayFieldName bool `json:"displayFieldName"` // 是否显示字段名称
Fields []*GalleryField `json:"fields"` // 卡片字段
Cards []*GalleryCard `json:"cards"` // 卡片
CardCount int `json:"cardCount"` // 总卡片数

View file

@ -514,6 +514,36 @@ func setAttrViewFitImage(operation *Operation) (err error) {
return
}
func (tx *Transaction) doSetAttrViewDisplayFieldName(operation *Operation) (ret *TxErr) {
err := setAttrViewDisplayFieldName(operation)
if err != nil {
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
}
return
}
func setAttrViewDisplayFieldName(operation *Operation) (err error) {
attrView, err := av.ParseAttributeView(operation.AvID)
if err != nil {
return
}
view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)
if err != nil {
return
}
switch view.LayoutType {
case av.LayoutTypeTable:
return
case av.LayoutTypeGallery:
view.Gallery.DisplayFieldName = operation.Data.(bool)
}
err = av.SaveAttributeView(attrView)
return
}
func (tx *Transaction) doSetAttrViewCardSize(operation *Operation) (ret *TxErr) {
err := setAttrViewCardSize(operation)
if err != nil {
@ -2503,6 +2533,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
view.Gallery.CoverFromAssetKeyID = masterView.Gallery.CoverFromAssetKeyID
view.Gallery.CardSize = masterView.Gallery.CardSize
view.Gallery.FitImage = masterView.Gallery.FitImage
view.Gallery.DisplayFieldName = masterView.Gallery.DisplayFieldName
view.Gallery.ShowIcon = masterView.Gallery.ShowIcon
view.Gallery.WrapField = masterView.Gallery.WrapField
}

View file

@ -289,6 +289,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewCardSize(op)
case "setAttrViewFitImage":
ret = tx.doSetAttrViewFitImage(op)
case "setDisplayFieldName":
ret = tx.doSetAttrViewDisplayFieldName(op)
case "setAttrViewShowIcon":
ret = tx.doSetAttrViewShowIcon(op)
case "setAttrViewWrapField":

View file

@ -26,6 +26,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
CardAspectRatio: view.Gallery.CardAspectRatio,
CardSize: view.Gallery.CardSize,
FitImage: view.Gallery.FitImage,
DisplayFieldName: view.Gallery.DisplayFieldName,
Fields: []*av.GalleryField{},
Cards: []*av.GalleryCard{},
}