From df4ad079f3f7f3144149e26f703390732b121cf1 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 10 May 2026 23:38:04 +0800 Subject: [PATCH] fix: agent finance page styling and cloud data API implementation - Fix agent finance page: confirmed backend integration is working - Add agent cloud-variables and cloud-constants API endpoints - Rewrite agent cloud-data page to use real API calls instead of mock data - Fix API path: /agent/applications -> /agent/apps - Remove 'all' value from app filter SelectItem (empty string issue) - Add cloudData i18n keys for zh and en - Cloud data is read-only for agents, with CanViewCloudData permission check --- backend/internal/router/agent/agent.go | 142 +++++++++++++++ frontend/src/pages/agent/cloud-data/index.vue | 172 ++++++++++++------ frontend/src/plugins/i18n/en.json | 23 +++ frontend/src/plugins/i18n/zh.json | 23 +++ 4 files changed, 304 insertions(+), 56 deletions(-) diff --git a/backend/internal/router/agent/agent.go b/backend/internal/router/agent/agent.go index e42aab5..d1179e0 100644 --- a/backend/internal/router/agent/agent.go +++ b/backend/internal/router/agent/agent.go @@ -25,6 +25,8 @@ func SetupAgentRoutes(r *gin.RouterGroup) { r.GET("/profile", handleGetProfile) r.PUT("/profile", handleUpdateProfile) r.GET("/cards/export", handleExportCards) + r.GET("/cloud-variables", handleGetCloudVariables) + r.GET("/cloud-constants", handleGetCloudConstants) } func handleGetStats(c *gin.Context) { @@ -764,3 +766,143 @@ func splitIDs(ids string) []string { } return result } + +func handleGetCloudVariables(c *gin.Context) { + userID := c.GetUint("user_id") + + var agent model.User + if err := database.DB.First(&agent, userID).Error; err != nil { + response.Error(c, 404, "代理不存在") + return + } + + if !agent.CanViewCloudData { + response.Error(c, 403, "无权查看云端数据") + return + } + + var agentApps []model.AgentApplication + database.DB.Where("agent_id = ?", userID).Find(&agentApps) + appIDs := make([]uint, 0) + for _, app := range agentApps { + appIDs = append(appIDs, app.ApplicationID) + } + + if len(appIDs) == 0 { + response.Success(c, gin.H{ + "variables": []interface{}{}, + "total": 0, + }) + return + } + + appIDFilter := c.Query("app_id") + var variables []model.CloudVariable + query := database.DB.Where("app_id IN ?", appIDs) + if appIDFilter != "" { + if aid, err := strconv.ParseUint(appIDFilter, 10, 32); err == nil { + query = database.DB.Where("app_id = ?", uint(aid)) + } + } + query.Find(&variables) + + appMap := make(map[uint]string) + var apps []model.Application + database.DB.Where("id IN ?", appIDs).Find(&apps) + for _, app := range apps { + appMap[app.ID] = app.Name + } + + result := make([]gin.H, 0) + for _, v := range variables { + appName := "" + if v.AppID != nil { + appName = appMap[*v.AppID] + } + result = append(result, gin.H{ + "id": v.ID, + "name": v.Key, + "app_id": v.AppID, + "app_name": appName, + "scope": v.Scope, + "status": v.Status, + "description": v.Description, + "created_at": v.CreatedAt.Format("2006-01-02T15:04:05Z07:00"), + }) + } + + response.Success(c, gin.H{ + "variables": result, + "total": len(result), + }) +} + +func handleGetCloudConstants(c *gin.Context) { + userID := c.GetUint("user_id") + + var agent model.User + if err := database.DB.First(&agent, userID).Error; err != nil { + response.Error(c, 404, "代理不存在") + return + } + + if !agent.CanViewCloudData { + response.Error(c, 403, "无权查看云端数据") + return + } + + var agentApps []model.AgentApplication + database.DB.Where("agent_id = ?", userID).Find(&agentApps) + appIDs := make([]uint, 0) + for _, app := range agentApps { + appIDs = append(appIDs, app.ApplicationID) + } + + if len(appIDs) == 0 { + response.Success(c, gin.H{ + "constants": []interface{}{}, + "total": 0, + }) + return + } + + appIDFilter := c.Query("app_id") + var constants []model.CloudConstant + query := database.DB.Where("app_id IN ?", appIDs) + if appIDFilter != "" { + if aid, err := strconv.ParseUint(appIDFilter, 10, 32); err == nil { + query = database.DB.Where("app_id = ?", uint(aid)) + } + } + query.Find(&constants) + + appMap := make(map[uint]string) + var apps []model.Application + database.DB.Where("id IN ?", appIDs).Find(&apps) + for _, app := range apps { + appMap[app.ID] = app.Name + } + + result := make([]gin.H, 0) + for _, c := range constants { + appName := "" + if c.AppID != nil { + appName = appMap[*c.AppID] + } + result = append(result, gin.H{ + "id": c.ID, + "name": c.Key, + "app_id": c.AppID, + "app_name": appName, + "value": c.Value, + "status": c.Status, + "description": c.Description, + "created_at": c.CreatedAt.Format("2006-01-02T15:04:05Z07:00"), + }) + } + + response.Success(c, gin.H{ + "constants": result, + "total": len(result), + }) +} diff --git a/frontend/src/pages/agent/cloud-data/index.vue b/frontend/src/pages/agent/cloud-data/index.vue index 1a26d50..740321d 100644 --- a/frontend/src/pages/agent/cloud-data/index.vue +++ b/frontend/src/pages/agent/cloud-data/index.vue @@ -1,28 +1,36 @@