query_set_components_layout_rule.go 1.3 KB
package domain

const (
	CellTypeTable      = "Table"
	CellTypeTableField = "TableField"
	CellTypeText       = "Text"
	CellTypeNull       = "Null"
)

const (
	DirectionNone  = "Null"
	DirectionRight = "Right"
	DirectionDown  = "Down"
)

type LayoutRule struct {
	Layout
}

type Layout struct {
	Cells [][]*LayoutCell `json:"cells"`
}

type LayoutCell struct {
	Type      string          `json:"type,omitempty"` // Table TableField  Text Null
	Data      *LayoutCellData `json:"data,omitempty"`
	Direction string          `json:"direction,omitempty"` // 向右:Right 向下:Down
	X         int             `json:"-,omitempty"`
	Y         int             `json:"-,omitempty"`
	Length    int             `json:"-"`
	BlockData []string        `json:"-"`
	ImageData string          `json:"-"`
}

type LayoutCellData struct {
	//Table      *Table      `json:"table,omitempty"`
	//Field      *Field      `json:"field,omitempty"`
	TableField *TableField `json:"tableField"`
	Text       string      `json:"text,omitempty"`
}

func (l *Layout) LayoutCells() []*LayoutCell {
	var cells = make([]*LayoutCell, 0)
	for i, rows := range l.Cells {
		for j, item := range rows {
			if item.Type == CellTypeNull || item.Type == "" {
				continue
			}
			item.X = i
			item.Y = j
			cells = append(cells, item)
		}
	}
	return cells
}