feat: 前台动态路由与积木页面、网页路径/发布/模式、PAGE_BUILDER 文档

Made-with: Cursor
This commit is contained in:
whm
2026-03-19 16:20:48 +08:00
parent b17e99eb93
commit ea163dbf8e
11 changed files with 732 additions and 29 deletions

View File

@@ -67,11 +67,14 @@ func GetPageByID(c *gin.Context) {
// CreatePageInput 创建网页
type CreatePageInput struct {
SiteID string `json:"site_id" binding:"required"`
Slug string `json:"slug" binding:"required"`
Title string `json:"title" binding:"required"`
Type string `json:"type"` // homepage, page
Content string `json:"content"`
SiteID string `json:"site_id" binding:"required"`
Slug string `json:"slug" binding:"required"`
Title string `json:"title" binding:"required"`
Type string `json:"type"` // homepage, page
Content string `json:"content"`
ContentMode string `json:"content_mode"` // html | builder
RoutePath string `json:"route_path"`
Published *bool `json:"published"`
}
// CreatePage 创建网页
@@ -98,6 +101,15 @@ func CreatePage(c *gin.Context) {
"content": input.Content,
"updated_at": now,
}
if input.ContentMode != "" {
doc["content_mode"] = input.ContentMode
}
if input.RoutePath != "" {
doc["route_path"] = input.RoutePath
}
if input.Published != nil {
doc["published"] = *input.Published
}
res, err := coll.InsertOne(ctx, doc)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
@@ -108,10 +120,13 @@ func CreatePage(c *gin.Context) {
// UpdatePageInput 更新网页
type UpdatePageInput struct {
Slug *string `json:"slug"`
Title *string `json:"title"`
Type *string `json:"type"`
Content *string `json:"content"`
Slug *string `json:"slug"`
Title *string `json:"title"`
Type *string `json:"type"`
Content *string `json:"content"`
ContentMode *string `json:"content_mode"`
RoutePath *string `json:"route_path"`
Published *bool `json:"published"`
}
// UpdatePage 更新网页
@@ -142,6 +157,15 @@ func UpdatePage(c *gin.Context) {
if input.Content != nil {
set["content"] = *input.Content
}
if input.ContentMode != nil {
set["content_mode"] = *input.ContentMode
}
if input.RoutePath != nil {
set["route_path"] = *input.RoutePath
}
if input.Published != nil {
set["published"] = *input.Published
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()