58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
|
|
package models
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"time"
|
|||
|
|
|
|||
|
|
"gorm.io/gorm"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// Template 前端页面模板(内置 / 自定义布局包)
|
|||
|
|
type Template struct {
|
|||
|
|
ID uint `json:"id" gorm:"primaryKey;column:id"`
|
|||
|
|
Slug string `json:"slug" gorm:"column:slug;uniqueIndex"`
|
|||
|
|
Name string `json:"name" gorm:"column:name"`
|
|||
|
|
Type string `json:"type" gorm:"column:type"` // builtin | custom
|
|||
|
|
Description string `json:"description" gorm:"column:description;type:text"`
|
|||
|
|
Manifest string `json:"-" gorm:"column:manifest;type:longtext"` // 解析后的 manifest.json(DB 冗余,避免读盘)
|
|||
|
|
LayoutJSON string `json:"-" gorm:"column:layout_json;type:longtext"` // 解析后的 layout.json(仅 custom)
|
|||
|
|
SkinCSSPath string `json:"skinCssPath" gorm:"column:skin_css_path;type:varchar(500)"` // 皮肤 CSS 相对路径 /uploads/templates/{slug}/skin.css
|
|||
|
|
IsSystem bool `json:"isSystem" gorm:"column:is_system;default:0"`
|
|||
|
|
IsActive bool `json:"isActive" gorm:"column:is_active;default:1"`
|
|||
|
|
SortOrder int `json:"sortOrder" gorm:"column:sort_order;default:0"`
|
|||
|
|
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
|
|||
|
|
UpdatedAt int64 `json:"updatedAt" gorm:"column:updated_at"`
|
|||
|
|
DeletedAt int64 `json:"deletedAt" gorm:"column:deleted_at;default:0"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Template) TableName() string {
|
|||
|
|
return "templates"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (t *Template) BeforeCreate(tx *gorm.DB) error {
|
|||
|
|
now := time.Now().Unix()
|
|||
|
|
if t.CreatedAt == 0 {
|
|||
|
|
t.CreatedAt = now
|
|||
|
|
}
|
|||
|
|
if t.UpdatedAt == 0 {
|
|||
|
|
t.UpdatedAt = now
|
|||
|
|
}
|
|||
|
|
return nil
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (t *Template) BeforeUpdate(tx *gorm.DB) error {
|
|||
|
|
t.UpdatedAt = time.Now().Unix()
|
|||
|
|
return nil
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// TemplateDescriptor 公开接口返回的模板描述(供自定义布局渲染引擎拉取)
|
|||
|
|
type TemplateDescriptor struct {
|
|||
|
|
Slug string `json:"slug"`
|
|||
|
|
Name string `json:"name"`
|
|||
|
|
Type string `json:"type"`
|
|||
|
|
Description string `json:"description"`
|
|||
|
|
Manifest interface{} `json:"manifest,omitempty"`
|
|||
|
|
Layout interface{} `json:"layout,omitempty"`
|
|||
|
|
SkinCssPath string `json:"skinCssPath,omitempty"`
|
|||
|
|
AssetsBase string `json:"assetsBase"`
|
|||
|
|
}
|