Files
nl-blogs/server/models/template.go
2026-08-24 13:06:04 +08:00

58 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.jsonDB 冗余,避免读盘)
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"`
}