♻️ Refactor av

This commit is contained in:
Daniel 2025-06-08 16:54:27 +08:00
parent 1dcc635f4d
commit 67b8566047
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 55 additions and 28 deletions

View file

@ -572,8 +572,11 @@ func renderAttributeView(c *gin.Context) {
var views []map[string]interface{} var views []map[string]interface{}
for _, v := range attrView.Views { for _, v := range attrView.Views {
pSize := 10 pSize := 10
if nil != v.Table && av.LayoutTypeTable == v.LayoutType { switch v.LayoutType {
case av.LayoutTypeTable:
pSize = v.Table.PageSize pSize = v.Table.PageSize
case av.LayoutTypeGallery:
pSize = v.Gallery.PageSize
} }
view := map[string]interface{}{ view := map[string]interface{}{

View file

@ -208,12 +208,14 @@ func NewTableView() (ret *View) {
Name: getI18nName("table"), Name: getI18nName("table"),
LayoutType: LayoutTypeTable, LayoutType: LayoutTypeTable,
Table: &LayoutTable{ Table: &LayoutTable{
BaseLayout: &BaseLayout{
Spec: 0, Spec: 0,
ID: ast.NewNodeID(), ID: ast.NewNodeID(),
Filters: []*ViewFilter{}, Filters: []*ViewFilter{},
Sorts: []*ViewSort{}, Sorts: []*ViewSort{},
PageSize: TableViewDefaultPageSize, PageSize: TableViewDefaultPageSize,
}, },
},
} }
return return
} }
@ -225,12 +227,14 @@ func NewTableViewWithBlockKey(blockKeyID string) (view *View, blockKey, selectKe
Name: name, Name: name,
LayoutType: LayoutTypeTable, LayoutType: LayoutTypeTable,
Table: &LayoutTable{ Table: &LayoutTable{
BaseLayout: &BaseLayout{
Spec: 0, Spec: 0,
ID: ast.NewNodeID(), ID: ast.NewNodeID(),
Filters: []*ViewFilter{}, Filters: []*ViewFilter{},
Sorts: []*ViewSort{}, Sorts: []*ViewSort{},
PageSize: TableViewDefaultPageSize, PageSize: TableViewDefaultPageSize,
}, },
},
} }
blockKey = NewKey(blockKeyID, getI18nName("key"), "", KeyTypeBlock) blockKey = NewKey(blockKeyID, getI18nName("key"), "", KeyTypeBlock)
view.Table.Columns = []*ViewTableColumn{{ID: blockKeyID}} view.Table.Columns = []*ViewTableColumn{{ID: blockKeyID}}
@ -246,12 +250,14 @@ func NewGalleryView() (ret *View) {
Name: getI18nName("gallery"), Name: getI18nName("gallery"),
LayoutType: LayoutTypeGallery, LayoutType: LayoutTypeGallery,
Gallery: &LayoutGallery{ Gallery: &LayoutGallery{
BaseLayout: &BaseLayout{
Spec: 0, Spec: 0,
ID: ast.NewNodeID(), ID: ast.NewNodeID(),
Filters: []*ViewFilter{}, Filters: []*ViewFilter{},
Sorts: []*ViewSort{}, Sorts: []*ViewSort{},
PageSize: GalleryViewDefaultPageSize, PageSize: GalleryViewDefaultPageSize,
}, },
},
} }
return return
} }

26
kernel/av/layout.go Normal file
View file

@ -0,0 +1,26 @@
// SiYuan - Refactor your thinking
// Copyright (c) 2020-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package av
// BaseLayout 描述了布局的基础结构,包含通用的过滤、排序和分页信息。
type BaseLayout struct {
Spec int `json:"spec"` // 布局格式版本
ID string `json:"id"` // 布局 ID
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
PageSize int `json:"pageSize"` // 每页行数
}

View file

@ -20,16 +20,12 @@ import "sort"
// LayoutGallery 描述了画廊布局的结构。 // LayoutGallery 描述了画廊布局的结构。
type LayoutGallery struct { type LayoutGallery struct {
Spec int `json:"spec"` // 布局格式版本 *BaseLayout
ID string `json:"id"` // 布局 ID
CoverFrom int `json:"coverFrom"` // 封面来源01内容图2资源字段 CoverFrom int `json:"coverFrom"` // 封面来源01内容图2资源字段
CoverFromAssetKeyID string `json:"coverFromAssetKeyId,omitempty"` // 资源字段 IDCoverFrom 为 2 时有效 CoverFromAssetKeyID string `json:"coverFromAssetKeyId,omitempty"` // 资源字段 IDCoverFrom 为 2 时有效
CardFields []*ViewGalleryCardField `json:"fields"` // 画廊卡片字段 CardFields []*ViewGalleryCardField `json:"fields"` // 画廊卡片字段
CardIDs []string `json:"cardIds"` // 卡片 ID用于自定义排序 CardIDs []string `json:"cardIds"` // 卡片 ID用于自定义排序
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
PageSize int `json:"pageSize"` // 每页卡片数
} }
// ViewGalleryCardField 描述了画廊卡片字段的结构。 // ViewGalleryCardField 描述了画廊卡片字段的结构。

View file

@ -22,14 +22,10 @@ import (
// LayoutTable 描述了表格布局的结构。 // LayoutTable 描述了表格布局的结构。
type LayoutTable struct { type LayoutTable struct {
Spec int `json:"spec"` // 布局格式版本 *BaseLayout
ID string `json:"id"` // 布局 ID
Columns []*ViewTableColumn `json:"columns"` // 表格列 Columns []*ViewTableColumn `json:"columns"` // 表格列
RowIDs []string `json:"rowIds"` // 行 ID用于自定义排序 RowIDs []string `json:"rowIds"` // 行 ID用于自定义排序
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
PageSize int `json:"pageSize"` // 每页行数
} }
// ViewTableColumn 描述了表格列的结构。 // ViewTableColumn 描述了表格列的结构。