- Add new PrefillGroup model with CRUD operations * Support for model, tag, and endpoint group types * JSON storage for group items with GORM datatypes * Automatic database migration support - Implement backend API endpoints * GET /api/prefill_group - List groups by type with admin auth * POST /api/prefill_group - Create new groups * PUT /api/prefill_group - Update existing groups * DELETE /api/prefill_group/:id - Delete groups - Add comprehensive frontend management interface * PrefillGroupManagement component for group listing * EditPrefillGroupModal for group creation/editing * Integration with EditModelModal for auto-filling * Responsive design with CardTable and SideSheet - Enhance model editing workflow * Tag group selection with auto-fill functionality * Endpoint group selection with auto-fill functionality * Seamless integration with existing model forms - Create reusable UI components * Extract common rendering utilities to models/ui/ * Shared renderLimitedItems and renderDescription functions * Consistent styling across all model-related components - Improve user experience * Empty state illustrations matching existing patterns * Fixed column positioning for operation buttons * Item content display with +x indicators for overflow * Tooltip support for long descriptions
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package controller
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"one-api/common"
|
|
"one-api/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GetPrefillGroups 获取预填组列表,可通过 ?type=xxx 过滤
|
|
func GetPrefillGroups(c *gin.Context) {
|
|
groupType := c.Query("type")
|
|
groups, err := model.GetAllPrefillGroups(groupType)
|
|
if err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
common.ApiSuccess(c, groups)
|
|
}
|
|
|
|
// CreatePrefillGroup 创建新的预填组
|
|
func CreatePrefillGroup(c *gin.Context) {
|
|
var g model.PrefillGroup
|
|
if err := c.ShouldBindJSON(&g); err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
if g.Name == "" || g.Type == "" {
|
|
common.ApiErrorMsg(c, "组名称和类型不能为空")
|
|
return
|
|
}
|
|
if err := g.Insert(); err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
common.ApiSuccess(c, &g)
|
|
}
|
|
|
|
// UpdatePrefillGroup 更新预填组
|
|
func UpdatePrefillGroup(c *gin.Context) {
|
|
var g model.PrefillGroup
|
|
if err := c.ShouldBindJSON(&g); err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
if g.Id == 0 {
|
|
common.ApiErrorMsg(c, "缺少组 ID")
|
|
return
|
|
}
|
|
if err := g.Update(); err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
common.ApiSuccess(c, &g)
|
|
}
|
|
|
|
// DeletePrefillGroup 删除预填组
|
|
func DeletePrefillGroup(c *gin.Context) {
|
|
idStr := c.Param("id")
|
|
id, err := strconv.Atoi(idStr)
|
|
if err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
if err := model.DeletePrefillGroupByID(id); err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
common.ApiSuccess(c, nil)
|
|
}
|