更新小程序首页精选推荐逻辑,调整展示的章节数据源为排名接口,优化展开功能以支持动态加载更多章节。修复图标组件的SVG映射,确保图标显示一致性。更新开发环境配置为本地地址,提升开发体验。

This commit is contained in:
Alex-larget
2026-03-20 17:02:09 +08:00
parent 1b87fa92f7
commit 905e8f1e8d
24 changed files with 337 additions and 161 deletions

View File

@@ -377,6 +377,7 @@ func DBBookAction(c *gin.Context) {
"chapterTitle": ch.ChapterTitle,
"editionStandard": ch.EditionStandard,
"editionPremium": ch.EditionPremium,
"previewPercent": ch.PreviewPercent,
},
})
return
@@ -517,6 +518,7 @@ func DBBookAction(c *gin.Context) {
TargetPartTitle string `json:"targetPartTitle"`
TargetChapterTitle string `json:"targetChapterTitle"`
ID string `json:"id"`
NewID string `json:"newId"` // 修改章节 ID 时传入,后端会更新 id 列
Title string `json:"title"`
Content string `json:"content"`
Price *float64 `json:"price"`
@@ -524,6 +526,7 @@ func DBBookAction(c *gin.Context) {
IsNew *bool `json:"isNew"` // stitch_soul标记最新新增
EditionStandard *bool `json:"editionStandard"` // 是否属于普通版
EditionPremium *bool `json:"editionPremium"` // 是否属于增值版
PreviewPercent *int `json:"previewPercent"` // 未解锁显示前 N%,空则用全局
PartID string `json:"partId"`
PartTitle string `json:"partTitle"`
ChapterID string `json:"chapterId"`
@@ -684,6 +687,14 @@ func DBBookAction(c *gin.Context) {
if body.HotScore != nil {
updates["hot_score"] = *body.HotScore
}
if body.PreviewPercent != nil {
p := *body.PreviewPercent
if p <= 0 || p > 100 {
updates["preview_percent"] = nil // 无效值则清空,用全局
} else {
updates["preview_percent"] = p
}
}
if body.PartID != "" {
updates["part_id"] = body.PartID
}
@@ -696,6 +707,9 @@ func DBBookAction(c *gin.Context) {
if body.ChapterTitle != "" {
updates["chapter_title"] = body.ChapterTitle
}
if body.NewID != "" && body.NewID != body.ID {
updates["id"] = body.NewID
}
var existing model.Chapter
err = db.Where("id = ?", body.ID).First(&existing).Error
if err == gorm.ErrRecordNotFound {
@@ -741,6 +755,9 @@ func DBBookAction(c *gin.Context) {
if body.IsNew != nil {
ch.IsNew = body.IsNew
}
if body.PreviewPercent != nil && *body.PreviewPercent > 0 && *body.PreviewPercent <= 100 {
ch.PreviewPercent = body.PreviewPercent
}
if err := db.Create(&ch).Error; err != nil {
c.JSON(http.StatusOK, gin.H{"success": false, "error": err.Error()})
return
@@ -761,7 +778,12 @@ func DBBookAction(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": false, "error": err.Error()})
return
}
cache.InvalidateChapterContentByID(body.ID)
// id 变更后需按 mid 失效缓存(按 id 查会失败)
if body.NewID != "" && body.NewID != body.ID {
cache.InvalidateChapterContent(existing.MID)
} else {
cache.InvalidateChapterContentByID(body.ID)
}
cache.InvalidateBookParts()
InvalidateChaptersByPartCache()
cache.InvalidateBookCache()