refactor: UI

This commit is contained in:
leookun
2026-08-07 01:50:20 +08:00
parent 5bd39ed317
commit 225de8bb85
39 changed files with 1734 additions and 1604 deletions
+25
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"time"
@@ -36,6 +37,8 @@ const (
// ModelAdapterConfig 定义了当前模块中的 ModelAdapterConfig 类型。
type ModelAdapterConfig struct {
ID string `json:"id,omitempty"`
// Sort 表示模型渠道的展示顺序。
Sort int `json:"sort"`
// DisplayName 表示当前声明中的 DisplayName。
DisplayName string `json:"displayName"`
// Type 表示当前声明中的 Type。
@@ -103,6 +106,7 @@ func NormalizeModelAdapterConfigs(input []ModelAdapterConfig) ([]ModelAdapterCon
return nil, err
}
next := ModelAdapterConfig{
Sort: item.Sort,
DisplayName: strings.TrimSpace(item.DisplayName),
Type: normalizeModelAdapterType(item.Type),
BaseURL: baseURL,
@@ -163,9 +167,30 @@ func NormalizeModelAdapterConfigs(input []ModelAdapterConfig) ([]ModelAdapterCon
seenChannelIDs[next.ID] = struct{}{}
normalized = append(normalized, next)
}
normalizeModelAdapterSorts(normalized)
return normalized, nil
}
func normalizeModelAdapterSorts(adapters []ModelAdapterConfig) {
sort.SliceStable(adapters, func(leftIndex, rightIndex int) bool {
left := adapters[leftIndex].Sort
right := adapters[rightIndex].Sort
switch {
case left <= 0 && right <= 0:
return false
case left <= 0:
return false
case right <= 0:
return true
default:
return left < right
}
})
for index := range adapters {
adapters[index].Sort = index + 1
}
}
func validateJSONMap(value string, fieldName string) error {
text := strings.TrimSpace(value)
if text == "" {