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
This commit is contained in:
2026-05-10 23:38:04 +08:00
parent 5561587cde
commit df4ad079f3
4 changed files with 304 additions and 56 deletions
+142
View File
@@ -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),
})
}