♻️ Refactor av

This commit is contained in:
Daniel 2025-06-08 17:22:03 +08:00
parent 67b8566047
commit 28095c5ef7
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 112 additions and 87 deletions

View file

@ -16,7 +16,7 @@
package av
// BaseLayout 描述了布局的基础结构,包含通用的过滤、排序和分页信息
// BaseLayout 描述了布局的基础结构
type BaseLayout struct {
Spec int `json:"spec"` // 布局格式版本
ID string `json:"id"` // 布局 ID
@ -24,3 +24,32 @@ type BaseLayout struct {
Sorts []*ViewSort `json:"sorts"` // 排序规则
PageSize int `json:"pageSize"` // 每页行数
}
// BaseValue 描述了字段值的基础结构。
type BaseValue struct {
ID string `json:"id"` // 字段值 ID
Value *Value `json:"value"` // 字段值
ValueType KeyType `json:"valueType"` // 字段值类型
}
// BaseInstance 描述了实例的基础结构。
type BaseInstance struct {
ID string `json:"id"` // ID
Icon string `json:"icon"` // 图标
Name string `json:"name"` // 名称
Desc string `json:"desc"` // 描述
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
PageSize int `json:"pageSize"` // 每页项目
}
// BaseInstanceField 描述了实例字段的基础结构。
type BaseInstanceField struct {
ID string `json:"id"` // ID
Name string `json:"name"` // 字段名
Type KeyType `json:"type"` // 字段类型
Icon string `json:"icon"` // 字段图标
Hidden bool `json:"hidden"` // 是否隐藏
Desc string `json:"desc"` // 字段描述
}

View file

@ -38,17 +38,11 @@ type ViewGalleryCardField struct {
// Gallery 描述了画廊实例的结构。
type Gallery struct {
ID string `json:"id"` // 画廊布局 ID
Icon string `json:"icon"` // 画廊图标
Name string `json:"name"` // 画廊名称
Desc string `json:"desc"` // 画廊描述
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
*BaseInstance
Fields []*GalleryField `json:"fields"` // 画廊字段
Cards []*GalleryCard `json:"cards"` // 画廊卡片
CardCount int `json:"cardCount"` // 画廊总卡片数
PageSize int `json:"pageSize"` // 每页卡片数
}
// GalleryCard 描述了画廊实例卡片的结构。
@ -61,12 +55,7 @@ type GalleryCard struct {
// GalleryField 描述了画廊实例卡片字段的结构。
type GalleryField struct {
ID string `json:"id"` // 字段 ID
Name string `json:"name"` // 字段名
Type KeyType `json:"type"` // 字段类型
Icon string `json:"icon"` // 字段图标
Hidden bool `json:"hidden"` // 是否隐藏
Desc string `json:"desc"` // 字段描述
*BaseInstanceField
// 以下是某些字段类型的特有属性
@ -80,9 +69,7 @@ type GalleryField struct {
// GalleryFieldValue 描述了画廊实例字段值的结构。
type GalleryFieldValue struct {
ID string `json:"id"` // 字段值 ID
Value *Value `json:"value"` // 字段值
ValueType KeyType `json:"valueType"` // 字段值类型
*BaseValue
}
func (card *GalleryCard) GetBlockValue() (ret *Value) {

View file

@ -42,30 +42,20 @@ type ViewTableColumn struct {
// Table 描述了表格实例的结构。
type Table struct {
ID string `json:"id"` // 表格布局 ID
Icon string `json:"icon"` // 表格图标
Name string `json:"name"` // 表格名称
Desc string `json:"desc"` // 表格描述
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
Filters []*ViewFilter `json:"filters"` // 过滤规则
Sorts []*ViewSort `json:"sorts"` // 排序规则
*BaseInstance
Columns []*TableColumn `json:"columns"` // 表格列
Rows []*TableRow `json:"rows"` // 表格行
RowCount int `json:"rowCount"` // 表格总行数
PageSize int `json:"pageSize"` // 每页行数
}
// TableColumn 描述了表格实例列的结构。
type TableColumn struct {
ID string `json:"id"` // 列 ID
Name string `json:"name"` // 列名
Type KeyType `json:"type"` // 列类型
Icon string `json:"icon"` // 列图标
*BaseInstanceField
Wrap bool `json:"wrap"` // 是否换行
Hidden bool `json:"hidden"` // 是否隐藏
Pin bool `json:"pin"` // 是否固定
Width string `json:"width"` // 列宽度
Desc string `json:"desc"` // 列描述
Calc *ColumnCalc `json:"calc"` // 计算
// 以下是某些列类型的特有属性
@ -86,9 +76,8 @@ type TableRow struct {
// TableCell 描述了表格实例单元格的结构。
type TableCell struct {
ID string `json:"id"` // 单元格 ID
Value *Value `json:"value"` // 单元格值
ValueType KeyType `json:"valueType"` // 单元格值类型
*BaseValue
Color string `json:"color"` // 单元格颜色
BgColor string `json:"bgColor"` // 单元格背景颜色
}

View file

@ -1599,6 +1599,10 @@ func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
return
}
if "" == operation.Layout {
operation.Layout = av.LayoutTypeTable
}
var view *av.View
switch operation.Layout {
case av.LayoutTypeTable:

View file

@ -14,6 +14,7 @@ import (
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string) (ret *av.Gallery) {
ret = &av.Gallery{
BaseInstance: &av.BaseInstance{
ID: view.ID,
Icon: view.Icon,
Name: view.Name,
@ -21,6 +22,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
HideAttrViewName: view.HideAttrViewName,
Filters: view.Gallery.Filters,
Sorts: view.Gallery.Sorts,
},
Fields: []*av.GalleryField{},
Cards: []*av.GalleryCard{},
}
@ -35,12 +37,14 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
}
ret.Fields = append(ret.Fields, &av.GalleryField{
BaseInstanceField: &av.BaseInstanceField{
ID: key.ID,
Name: key.Name,
Type: key.Type,
Icon: key.Icon,
Hidden: field.Hidden,
Desc: key.Desc,
},
Options: key.Options,
NumberFormat: key.NumberFormat,
Template: key.Template,
@ -103,17 +107,21 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
for _, keyValues := range card {
if keyValues.Key.ID == field.ID {
fieldValue = &av.GalleryFieldValue{
BaseValue: &av.BaseValue{
ID: keyValues.Values[0].ID,
Value: keyValues.Values[0],
ValueType: field.Type,
},
}
break
}
}
if nil == fieldValue {
fieldValue = &av.GalleryFieldValue{
BaseValue: &av.BaseValue{
ID: ast.NewNodeID(),
ValueType: field.Type,
},
}
}
galleryCard.ID = cardID

View file

@ -28,15 +28,17 @@ import (
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table) {
ret = &av.Table{
BaseInstance: &av.BaseInstance{
ID: view.ID,
Icon: view.Icon,
Name: view.Name,
Desc: view.Desc,
HideAttrViewName: view.HideAttrViewName,
Columns: []*av.TableColumn{},
Rows: []*av.TableRow{},
Filters: view.Table.Filters,
Sorts: view.Table.Sorts,
},
Columns: []*av.TableColumn{},
Rows: []*av.TableRow{},
}
// 组装列
@ -49,10 +51,14 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
}
ret.Columns = append(ret.Columns, &av.TableColumn{
BaseInstanceField: &av.BaseInstanceField{
ID: key.ID,
Name: key.Name,
Type: key.Type,
Icon: key.Icon,
Hidden: col.Hidden,
Desc: key.Desc,
},
Options: key.Options,
NumberFormat: key.NumberFormat,
Template: key.Template,
@ -60,9 +66,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
Rollup: key.Rollup,
Date: key.Date,
Wrap: col.Wrap,
Hidden: col.Hidden,
Width: col.Width,
Desc: key.Desc,
Pin: col.Pin,
Calc: col.Calc,
})
@ -121,17 +125,21 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
for _, keyValues := range row {
if keyValues.Key.ID == col.ID {
tableCell = &av.TableCell{
BaseValue: &av.BaseValue{
ID: keyValues.Values[0].ID,
Value: keyValues.Values[0],
ValueType: col.Type,
},
}
break
}
}
if nil == tableCell {
tableCell = &av.TableCell{
BaseValue: &av.BaseValue{
ID: ast.NewNodeID(),
ValueType: col.Type,
},
}
}
tableRow.ID = rowID