// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. //go:build plus package routes import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" ) type IndexAction struct { actionutils.ParentAction } func (this *IndexAction) Init() { this.Nav("", "", "index") } func (this *IndexAction) RunGet(params struct { CategoryId int64 }) { this.Data["categoryId"] = params.CategoryId routesResp, err := this.RPC().NSRouteRPC().FindAllNSRoutes(this.AdminContext(), &pb.FindAllNSRoutesRequest{ NsClusterId: 0, NsDomainId: 0, UserId: 0, NsRouteCategoryId: params.CategoryId, }) if err != nil { this.ErrorPage(err) return } var routeMaps = []maps.Map{} for _, route := range routesResp.NsRoutes { // 分类 var categoryMap = maps.Map{ "id": 0, } if route.NsRouteCategory != nil { categoryMap = maps.Map{ "id": route.NsRouteCategory.Id, "name": route.NsRouteCategory.Name, } } routeMaps = append(routeMaps, maps.Map{ "id": route.Id, "name": route.Name, "isOn": route.IsOn, "isPublic": route.IsPublic, "priority": route.Priority, "category": categoryMap, }) } this.Data["routes"] = routeMaps // 所有分类 categoriesResp, err := this.RPC().NSRouteCategoryRPC().FindAllNSRouteCategories(this.AdminContext(), &pb.FindAllNSRouteCategoriesRequest{}) if err != nil { this.ErrorPage(err) return } var categoryMaps = []maps.Map{} for _, category := range categoriesResp.NsRouteCategories { categoryMaps = append(categoryMaps, maps.Map{ "id": category.Id, "name": category.Name, }) } this.Data["categories"] = categoryMaps this.Show() }