优化页面、修复BUG

This commit is contained in:
李琦
2026-06-24 16:50:04 +08:00
parent 88ba9be318
commit 3f653bc336
36 changed files with 1672 additions and 2401 deletions

View File

@@ -1,6 +1,7 @@
package models
import (
"encoding/json"
"time"
"gorm.io/gorm"
@@ -76,6 +77,8 @@ type PostHistory struct {
Version int `json:"version" gorm:"column:version"`
Title string `json:"title" gorm:"column:title"`
CategoryID uint `json:"categoryId" gorm:"column:category_id"`
ColumnID *uint `json:"columnId,omitempty" gorm:"column:column_id"`
TagIDs string `json:"tagIds,omitempty" gorm:"column:tag_ids;type:json"`
Excerpt string `json:"excerpt" gorm:"column:excerpt"`
Content string `json:"content" gorm:"column:content;type:text"`
IsPublished int `json:"isPublished" gorm:"column:is_published"`
@@ -84,6 +87,18 @@ type PostHistory struct {
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
}
// GetTagIDList parses stored tag_ids JSON into a slice of uint IDs.
func (ph *PostHistory) GetTagIDList() []uint {
if ph.TagIDs == "" {
return nil
}
var ids []uint
if err := json.Unmarshal([]byte(ph.TagIDs), &ids); err != nil {
return nil
}
return ids
}
// TableName 指定表名
func (PostHistory) TableName() string {
return "post_history"
@@ -108,10 +123,29 @@ type PostHistoryResponse struct {
Version int `json:"version"`
Title string `json:"title"`
CategoryID uint `json:"categoryId"`
CategoryName string `json:"categoryName"`
CategoryName string `json:"categoryName,omitempty"`
ColumnID *uint `json:"columnId,omitempty"`
TagIDs []uint `json:"tagIds,omitempty"`
Excerpt string `json:"excerpt,omitempty"`
Content string `json:"content,omitempty"`
Date string `json:"date"`
IsPublished int `json:"isPublished"`
ModifiedBy uint `json:"modifiedBy"`
ModifiedAt string `json:"modifiedAt"`
CreatedAt string `json:"createdAt"`
}
// PostHistoryFieldDiff 字段对比结果
type PostHistoryFieldDiff struct {
From string `json:"from"`
To string `json:"to"`
Changed bool `json:"changed"`
Diff string `json:"diff,omitempty"`
}
// PostHistoryDiffResponse 版本对比响应
type PostHistoryDiffResponse struct {
FromVersion int `json:"fromVersion"`
ToVersion int `json:"toVersion"`
Fields map[string]PostHistoryFieldDiff `json:"fields"`
}