Files
rill/internal/model/nav_link.go
T
kevin 4449250e97 新增头部导航链接配置与多语言支持
- 迁移 v10 新增 nav_links 与 nav_link_translations 两张表,文案按语言存储
- 公开 GET /api/nav-links 返回启用链接(按 sort/id 排序);管理员可增删改查与启停
- URL 仅允许站内路径、http(s) 与 mailto,拒绝 javascript: 等危险协议;译文替换与校验
- 前端删除写死的“主页”按钮,头部按当前语言渲染动态链接,新窗口加 rel=noopener noreferrer
- 后台管理页新增“头部导航链接”卡片(三语文案、URL、打开方式、排序、状态),改动即时生效
- 补充 nav 接口与迁移测试、三语文案,重新生成 Swagger 文档
2026-09-21 21:26:30 +08:00

32 lines
1.3 KiB
Go

package model
import "time"
// 导航链接状态。
const (
NavLinkStatusDisabled int8 = 0
NavLinkStatusEnabled int8 = 1
)
// NavLink 头部导航链接,文案按语言存放在 NavLinkTranslation。
type NavLink struct {
ID uint `gorm:"primaryKey" json:"id"`
URL string `gorm:"size:512;not null" json:"url"`
OpenInNewWindow bool `gorm:"not null;default:false" json:"open_in_new_window"`
Sort int `gorm:"not null;default:0" json:"sort"`
Status int8 `gorm:"not null" json:"status"`
Translations []NavLinkTranslation `gorm:"-" json:"translations"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// NavLinkTranslation 导航链接的多语言文案,同一链接同一语言唯一。
type NavLinkTranslation struct {
ID uint `gorm:"primaryKey" json:"-"`
NavLinkID uint `gorm:"uniqueIndex:idx_nav_link_locale;not null" json:"nav_link_id"`
Locale string `gorm:"size:10;uniqueIndex:idx_nav_link_locale;not null" json:"locale"`
Label string `gorm:"size:100;not null" json:"label"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
}