优化页面、修复BUG

This commit is contained in:
李琦
2026-07-04 17:58:19 +08:00
parent e4baa4b585
commit 88c447fe18
34 changed files with 5884 additions and 13 deletions

164
server/models/video.go Normal file
View File

@@ -0,0 +1,164 @@
package models
import (
"time"
"gorm.io/gorm"
)
// VideoCategory 视频分类模型
type VideoCategory struct {
ID uint `json:"id" gorm:"primaryKey;column:id"`
Name string `json:"name" gorm:"column:name"`
Slug string `json:"slug" gorm:"column:slug;uniqueIndex"`
Description string `json:"description" gorm:"column:description;type:text"`
SortOrder uint `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 (VideoCategory) TableName() string { return "video_categories" }
func (vc *VideoCategory) BeforeCreate(tx *gorm.DB) error {
now := time.Now().Unix()
if vc.CreatedAt == 0 {
vc.CreatedAt = now
}
if vc.UpdatedAt == 0 {
vc.UpdatedAt = now
}
return nil
}
func (vc *VideoCategory) BeforeUpdate(tx *gorm.DB) error {
vc.UpdatedAt = time.Now().Unix()
return nil
}
// VideoCategoryResponse 视频分类 API 响应
type VideoCategoryResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description string `json:"description"`
SortOrder uint `json:"sortOrder"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
VideoCount int64 `json:"videoCount,omitempty"`
AlbumCount int64 `json:"albumCount,omitempty"`
}
// VideoAlbum 视频专辑模型
type VideoAlbum struct {
ID uint `json:"id" gorm:"primaryKey;column:id"`
Name string `json:"name" gorm:"column:name"`
Description string `json:"description" gorm:"column:description;type:text"`
Cover string `json:"cover" gorm:"column:cover"`
CategoryID uint `json:"categoryId" gorm:"column:category_id;index"`
IsActive int `json:"isActive" gorm:"column:is_active;default:1"`
SortOrder uint `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 (VideoAlbum) TableName() string { return "video_albums" }
func (va *VideoAlbum) BeforeCreate(tx *gorm.DB) error {
now := time.Now().Unix()
if va.CreatedAt == 0 {
va.CreatedAt = now
}
if va.UpdatedAt == 0 {
va.UpdatedAt = now
}
return nil
}
func (va *VideoAlbum) BeforeUpdate(tx *gorm.DB) error {
va.UpdatedAt = time.Now().Unix()
return nil
}
// VideoAlbumResponse 视频专辑 API 响应
type VideoAlbumResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Cover string `json:"cover"`
CategoryID uint `json:"categoryId"`
CategoryName string `json:"categoryName,omitempty"`
IsActive int `json:"isActive"`
SortOrder uint `json:"sortOrder"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
VideoCount int64 `json:"videoCount,omitempty"`
}
// Video 视频模型
type Video struct {
ID string `json:"id" gorm:"primaryKey;column:id"`
Title string `json:"title" gorm:"column:title"`
Description string `json:"description" gorm:"column:description;type:text"`
VideoURL string `json:"videoUrl" gorm:"column:video_url"`
Cover string `json:"cover" gorm:"column:cover"`
Poster string `json:"poster" gorm:"column:poster"`
CategoryID uint `json:"categoryId" gorm:"column:category_id;index"`
Duration int `json:"duration" gorm:"column:duration;default:0"`
IsPublished int `json:"isPublished" gorm:"column:is_published;default:1"`
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 (Video) TableName() string { return "videos" }
func (v *Video) BeforeCreate(tx *gorm.DB) error {
now := time.Now().Unix()
if v.CreatedAt == 0 {
v.CreatedAt = now
}
if v.UpdatedAt == 0 {
v.UpdatedAt = now
}
return nil
}
func (v *Video) BeforeUpdate(tx *gorm.DB) error {
v.UpdatedAt = time.Now().Unix()
return nil
}
// VideoResponse 视频 API 响应
type VideoResponse struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
VideoURL string `json:"videoUrl"`
Cover string `json:"cover"`
Poster string `json:"poster"`
CategoryID uint `json:"categoryId"`
CategoryName string `json:"categoryName,omitempty"`
Duration int `json:"duration"`
IsPublished int `json:"isPublished"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
// AlbumVideo 专辑视频关联
type AlbumVideo struct {
AlbumID uint `json:"albumId" gorm:"primaryKey;column:album_id"`
VideoID string `json:"videoId" gorm:"primaryKey;column:video_id"`
SortOrder uint `json:"sortOrder" gorm:"column:sort_order;default:0"`
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
}
func (AlbumVideo) TableName() string { return "album_videos" }
func (av *AlbumVideo) BeforeCreate(tx *gorm.DB) error {
if av.CreatedAt == 0 {
av.CreatedAt = time.Now().Unix()
}
return nil
}

View File

@@ -13,6 +13,8 @@ type Work struct {
Category string `json:"category" gorm:"column:category"`
Year string `json:"year" gorm:"column:year"`
HeroImg string `json:"heroImg" gorm:"column:hero_img"`
HeroVideo string `json:"heroVideo" gorm:"column:hero_video"`
VideoID string `json:"videoId" gorm:"column:video_id"`
Description string `json:"desc" gorm:"column:description;type:text"`
Links string `json:"links" gorm:"column:links;type:text"` // JSON格式存储链接
IsFeatured int `json:"isFeatured" gorm:"column:is_featured;default:0"`
@@ -107,6 +109,9 @@ type WorkResponse struct {
Category string `json:"category"`
Year string `json:"year"`
HeroImg string `json:"heroImg"`
HeroVideo string `json:"heroVideo,omitempty"`
VideoID string `json:"videoId,omitempty"`
VideoURL string `json:"videoUrl,omitempty"`
Desc string `json:"desc"`
TechStack []map[string]interface{} `json:"techStack"`
Gallery []string `json:"gallery"`