Daniel 2025-06-30 12:50:50 +08:00
parent 60d44fec3d
commit 3c21d39e52
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 52 additions and 23 deletions

View file

@ -23,6 +23,9 @@ type BaseLayout struct {
Spec int `json:"spec"` // 布局格式版本 Spec int `json:"spec"` // 布局格式版本
ID string `json:"id"` // 布局 ID ID string `json:"id"` // 布局 ID
ShowIcon bool `json:"showIcon"` // 是否显示字段图标
WrapField bool `json:"wrapField"` // 是否换行字段内容
// TODO 以下三个字段已经废弃,计划于 2026 年 6 月 30 日后删除 https://github.com/siyuan-note/siyuan/issues/15162 // TODO 以下三个字段已经废弃,计划于 2026 年 6 月 30 日后删除 https://github.com/siyuan-note/siyuan/issues/15162
//Deprecated //Deprecated
@ -51,6 +54,8 @@ type BaseInstance struct {
Sorts []*ViewSort `json:"sorts"` // 排序规则 Sorts []*ViewSort `json:"sorts"` // 排序规则
Group *ViewGroup `json:"group"` // 分组规则 Group *ViewGroup `json:"group"` // 分组规则
PageSize int `json:"pageSize"` // 每页项目数 PageSize int `json:"pageSize"` // 每页项目数
ShowIcon bool `json:"showIcon"` // 是否显示字段图标
WrapField bool `json:"wrapField"` // 是否换行字段内容
} }
func (baseInstance *BaseInstance) GetSorts() []*ViewSort { func (baseInstance *BaseInstance) GetSorts() []*ViewSort {
@ -64,11 +69,12 @@ func (baseInstance *BaseInstance) GetFilters() []*ViewFilter {
// BaseInstanceField 描述了实例字段的基础结构。 // BaseInstanceField 描述了实例字段的基础结构。
type BaseInstanceField struct { type BaseInstanceField struct {
ID string `json:"id"` // ID ID string `json:"id"` // ID
Name string `json:"name"` // 字段名 Name string `json:"name"` // 名称
Type KeyType `json:"type"` // 字段类型 Type KeyType `json:"type"` // 类型
Icon string `json:"icon"` // 字段图标 Icon string `json:"icon"` // 图标
Wrap bool `json:"wrap"` // 是否换行
Hidden bool `json:"hidden"` // 是否隐藏 Hidden bool `json:"hidden"` // 是否隐藏
Desc string `json:"desc"` // 字段描述 Desc string `json:"desc"` // 描述
// 以下是某些字段类型的特有属性 // 以下是某些字段类型的特有属性

View file

@ -29,8 +29,6 @@ type LayoutGallery struct {
CardAspectRatio CardAspectRatio `json:"cardAspectRatio"` // 卡片宽高比 CardAspectRatio CardAspectRatio `json:"cardAspectRatio"` // 卡片宽高比
CardSize CardSize `json:"cardSize"` // 卡片大小0小卡片1中卡片2大卡片 CardSize CardSize `json:"cardSize"` // 卡片大小0小卡片1中卡片2大卡片
FitImage bool `json:"fitImage"` // 是否适应封面图片大小 FitImage bool `json:"fitImage"` // 是否适应封面图片大小
ShowIcon bool `json:"showIcon"` // 是否显示字段图标
WrapField bool `json:"wrapField"` // 是否换行字段内容
CardFields []*ViewGalleryCardField `json:"fields"` // 画廊卡片字段 CardFields []*ViewGalleryCardField `json:"fields"` // 画廊卡片字段
CardIDs []string `json:"cardIds"` // 卡片 ID用于自定义排序 CardIDs []string `json:"cardIds"` // 卡片 ID用于自定义排序
@ -45,11 +43,11 @@ func NewLayoutGallery() *LayoutGallery {
BaseLayout: &BaseLayout{ BaseLayout: &BaseLayout{
Spec: 0, Spec: 0,
ID: ast.NewNodeID(), ID: ast.NewNodeID(),
ShowIcon: true,
}, },
CoverFrom: CoverFromContentImage, CoverFrom: CoverFromContentImage,
CardAspectRatio: CardAspectRatio16_9, CardAspectRatio: CardAspectRatio16_9,
CardSize: CardSizeMedium, CardSize: CardSizeMedium,
ShowIcon: true,
} }
} }
@ -86,6 +84,7 @@ const (
type ViewGalleryCardField struct { type ViewGalleryCardField struct {
ID string `json:"id"` // 字段 ID ID string `json:"id"` // 字段 ID
Wrap bool `json:"wrap"` // 是否换行
Hidden bool `json:"hidden"` // 是否隐藏 Hidden bool `json:"hidden"` // 是否隐藏
Desc string `json:"desc,omitempty"` // 字段描述 Desc string `json:"desc,omitempty"` // 字段描述
} }

View file

@ -37,6 +37,7 @@ func NewLayoutTable() *LayoutTable {
BaseLayout: &BaseLayout{ BaseLayout: &BaseLayout{
Spec: 0, Spec: 0,
ID: ast.NewNodeID(), ID: ast.NewNodeID(),
ShowIcon: true,
}, },
} }
} }
@ -66,7 +67,6 @@ type Table struct {
type TableColumn struct { type TableColumn struct {
*BaseInstanceField *BaseInstanceField
Wrap bool `json:"wrap"` // 是否换行
Pin bool `json:"pin"` // 是否固定 Pin bool `json:"pin"` // 是否固定
Width string `json:"width"` // 列宽度 Width string `json:"width"` // 列宽度
Calc *ColumnCalc `json:"calc"` // 计算 Calc *ColumnCalc `json:"calc"` // 计算

View file

@ -195,11 +195,18 @@ func setAttrViewWrapField(operation *Operation) (err error) {
return return
} }
allFieldWrap := operation.Data.(bool)
switch view.LayoutType { switch view.LayoutType {
case av.LayoutTypeTable: case av.LayoutTypeTable:
return view.Table.WrapField = allFieldWrap
for _, col := range view.Table.Columns {
col.Wrap = allFieldWrap
}
case av.LayoutTypeGallery: case av.LayoutTypeGallery:
view.Gallery.WrapField = operation.Data.(bool) view.Gallery.WrapField = allFieldWrap
for _, field := range view.Gallery.CardFields {
field.Wrap = allFieldWrap
}
} }
err = av.SaveAttributeView(attrView) err = av.SaveAttributeView(attrView)
@ -227,7 +234,7 @@ func setAttrViewShowIcon(operation *Operation) (err error) {
switch view.LayoutType { switch view.LayoutType {
case av.LayoutTypeTable: case av.LayoutTypeTable:
return view.Table.ShowIcon = operation.Data.(bool)
case av.LayoutTypeGallery: case av.LayoutTypeGallery:
view.Gallery.ShowIcon = operation.Data.(bool) view.Gallery.ShowIcon = operation.Data.(bool)
} }
@ -1900,10 +1907,13 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
} }
view.Table.RowIDs = masterView.Table.RowIDs view.Table.RowIDs = masterView.Table.RowIDs
view.Table.ShowIcon = masterView.Table.ShowIcon
view.Table.WrapField = masterView.Table.WrapField
case av.LayoutTypeGallery: case av.LayoutTypeGallery:
for _, field := range masterView.Gallery.CardFields { for _, field := range masterView.Gallery.CardFields {
view.Gallery.CardFields = append(view.Gallery.CardFields, &av.ViewGalleryCardField{ view.Gallery.CardFields = append(view.Gallery.CardFields, &av.ViewGalleryCardField{
ID: field.ID, ID: field.ID,
Wrap: field.Wrap,
Hidden: field.Hidden, Hidden: field.Hidden,
Desc: field.Desc, Desc: field.Desc,
}) })
@ -2750,6 +2760,8 @@ func duplicateAttributeViewKey(operation *Operation) (err error) {
view.Gallery.CardFields = append(view.Gallery.CardFields[:i+1], append([]*av.ViewGalleryCardField{ view.Gallery.CardFields = append(view.Gallery.CardFields[:i+1], append([]*av.ViewGalleryCardField{
{ {
ID: copyKey.ID, ID: copyKey.ID,
Wrap: field.Wrap,
Hidden: field.Hidden,
Desc: field.Desc, Desc: field.Desc,
}, },
}, view.Gallery.CardFields[i+1:]...)...) }, view.Gallery.CardFields[i+1:]...)...)
@ -2817,16 +2829,25 @@ func setAttributeViewColWrap(operation *Operation) (err error) {
return return
} }
newWrap := operation.Data.(bool)
allFieldWrap := true
switch view.LayoutType { switch view.LayoutType {
case av.LayoutTypeTable: case av.LayoutTypeTable:
for _, column := range view.Table.Columns { for _, column := range view.Table.Columns {
if column.ID == operation.ID { if column.ID == operation.ID {
column.Wrap = operation.Data.(bool) column.Wrap = newWrap
break
} }
allFieldWrap = allFieldWrap && column.Wrap
} }
view.Table.WrapField = allFieldWrap
case av.LayoutTypeGallery: case av.LayoutTypeGallery:
return for _, field := range view.Gallery.CardFields {
if field.ID == operation.ID {
field.Wrap = newWrap
}
allFieldWrap = allFieldWrap && field.Wrap
}
view.Gallery.WrapField = allFieldWrap
} }
err = av.SaveAttributeView(attrView) err = av.SaveAttributeView(attrView)

View file

@ -26,14 +26,14 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
Filters: view.Filters, Filters: view.Filters,
Sorts: view.Sorts, Sorts: view.Sorts,
Group: view.Group, Group: view.Group,
ShowIcon: view.Gallery.ShowIcon,
WrapField: view.Gallery.WrapField,
}, },
CoverFrom: view.Gallery.CoverFrom, CoverFrom: view.Gallery.CoverFrom,
CoverFromAssetKeyID: view.Gallery.CoverFromAssetKeyID, CoverFromAssetKeyID: view.Gallery.CoverFromAssetKeyID,
CardAspectRatio: view.Gallery.CardAspectRatio, CardAspectRatio: view.Gallery.CardAspectRatio,
CardSize: view.Gallery.CardSize, CardSize: view.Gallery.CardSize,
FitImage: view.Gallery.FitImage, FitImage: view.Gallery.FitImage,
ShowIcon: view.Gallery.ShowIcon,
WrapField: view.Gallery.WrapField,
Fields: []*av.GalleryField{}, Fields: []*av.GalleryField{},
Cards: []*av.GalleryCard{}, Cards: []*av.GalleryCard{},
} }
@ -53,6 +53,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
Name: key.Name, Name: key.Name,
Type: key.Type, Type: key.Type,
Icon: key.Icon, Icon: key.Icon,
Wrap: field.Wrap,
Hidden: field.Hidden, Hidden: field.Hidden,
Desc: key.Desc, Desc: key.Desc,
Options: key.Options, Options: key.Options,

View file

@ -33,6 +33,8 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
Filters: view.Filters, Filters: view.Filters,
Sorts: view.Sorts, Sorts: view.Sorts,
Group: view.Group, Group: view.Group,
ShowIcon: view.Table.ShowIcon,
WrapField: view.Table.WrapField,
}, },
Columns: []*av.TableColumn{}, Columns: []*av.TableColumn{},
Rows: []*av.TableRow{}, Rows: []*av.TableRow{},
@ -53,6 +55,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
Name: key.Name, Name: key.Name,
Type: key.Type, Type: key.Type,
Icon: key.Icon, Icon: key.Icon,
Wrap: col.Wrap,
Hidden: col.Hidden, Hidden: col.Hidden,
Desc: key.Desc, Desc: key.Desc,
Options: key.Options, Options: key.Options,
@ -62,7 +65,6 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
Rollup: key.Rollup, Rollup: key.Rollup,
Date: key.Date, Date: key.Date,
}, },
Wrap: col.Wrap,
Width: col.Width, Width: col.Width,
Pin: col.Pin, Pin: col.Pin,
Calc: col.Calc, Calc: col.Calc,