feat: implement core backend for team owner management with SQLite, auto-add APIs, and a frontend owner list component.

This commit is contained in:
2026-01-30 20:20:35 +08:00
parent 3c5bb04d82
commit 10cda012af
6 changed files with 125 additions and 14 deletions

View File

@@ -111,6 +111,7 @@ func startServer(cfg *config.Config) {
mux.HandleFunc("/api/db/owners", api.CORS(handleGetOwners))
mux.HandleFunc("/api/db/owners/stats", api.CORS(handleGetOwnerStats))
mux.HandleFunc("/api/db/owners/clear", api.CORS(handleClearOwners))
mux.HandleFunc("/api/db/owners/clear-used", api.CORS(handleClearUsedOwners)) // 清理已使用
mux.HandleFunc("/api/db/owners/delete/", api.CORS(handleDeleteOwner)) // DELETE /api/db/owners/delete/{id}
mux.HandleFunc("/api/db/owners/batch-delete", api.CORS(handleBatchDeleteOwners)) // POST 批量删除
mux.HandleFunc("/api/db/owners/refetch-account-ids", api.CORS(api.HandleRefetchAccountIDs))
@@ -609,7 +610,24 @@ func handleGetOwners(w http.ResponseWriter, r *http.Request) {
return
}
owners, total, err := database.Instance.GetTeamOwners("", 50, 0)
// 读取分页参数
query := r.URL.Query()
limit := 20
offset := 0
status := query.Get("status")
if l := query.Get("limit"); l != "" {
if parsed, err := strconv.Atoi(l); err == nil && parsed > 0 {
limit = parsed
}
}
if o := query.Get("offset"); o != "" {
if parsed, err := strconv.Atoi(o); err == nil && parsed >= 0 {
offset = parsed
}
}
owners, total, err := database.Instance.GetTeamOwners(status, limit, offset)
if err != nil {
api.Error(w, http.StatusInternalServerError, fmt.Sprintf("查询失败: %v", err))
return
@@ -645,6 +663,25 @@ func handleClearOwners(w http.ResponseWriter, r *http.Request) {
api.Success(w, map[string]string{"message": "已清空"})
}
// handleClearUsedOwners POST /api/db/owners/clear-used - 清理已使用的母号
func handleClearUsedOwners(w http.ResponseWriter, r *http.Request) {
if database.Instance == nil {
api.Error(w, http.StatusInternalServerError, "数据库未初始化")
return
}
deleted, err := database.Instance.ClearUsedOwners()
if err != nil {
api.Error(w, http.StatusInternalServerError, fmt.Sprintf("清理失败: %v", err))
return
}
api.Success(w, map[string]interface{}{
"message": fmt.Sprintf("已清理 %d 个已使用的母号", deleted),
"deleted": deleted,
})
}
// handleDeleteOwner DELETE /api/db/owners/delete/{id} - 删除单个 owner
func handleDeleteOwner(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete && r.Method != http.MethodPost {