diff --git a/internal/web/actions/default/servers/create.go b/internal/web/actions/default/servers/create.go index a76870c7..d7370d99 100644 --- a/internal/web/actions/default/servers/create.go +++ b/internal/web/actions/default/servers/create.go @@ -63,8 +63,12 @@ func (this *CreateAction) RunGet(params struct{}) { func (this *CreateAction) RunPost(params struct { Name string Description string - ClusterId int64 - GroupIds []int64 + + UserId int64 + UserPlanId int64 + ClusterId int64 + + GroupIds []int64 ServerType string Addresses string @@ -86,11 +90,22 @@ func (this *CreateAction) RunPost(params struct { Field("name", params.Name). Require("请输入服务名称") - if params.ClusterId <= 0 { + var clusterId = params.ClusterId + + // 用户 + var userId = params.UserId + clusterIdResp, err := this.RPC().UserRPC().FindUserNodeClusterId(this.AdminContext(), &pb.FindUserNodeClusterIdRequest{UserId: userId}) + if err != nil { + this.ErrorPage(err) + return + } + clusterId = clusterIdResp.NodeClusterId + if clusterId <= 0 { this.Fail("请选择部署的集群") } - // TODO 验证集群ID + // 套餐 + var userPlanId = params.UserPlanId // 端口地址 var httpConfig *serverconfigs.HTTPProtocolConfig = nil @@ -260,7 +275,7 @@ func (this *CreateAction) RunPost(params struct { if len(allServerNames) > 0 { dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{ ServerNames: allServerNames, - NodeClusterId: params.ClusterId, + NodeClusterId: clusterId, }) if err != nil { this.ErrorPage(err) @@ -359,13 +374,14 @@ func (this *CreateAction) RunPost(params struct { } req := &pb.CreateServerRequest{ - UserId: 0, + UserId: userId, + UserPlanId: userPlanId, AdminId: this.AdminId(), Type: params.ServerType, Name: params.Name, ServerNamesJON: []byte(params.ServerNames), Description: params.Description, - NodeClusterId: params.ClusterId, + NodeClusterId: clusterId, IncludeNodesJSON: includeNodesJSON, ExcludeNodesJSON: excludeNodesJSON, WebId: webId, diff --git a/internal/web/actions/default/servers/init.go b/internal/web/actions/default/servers/init.go index 2ea55885..ad09c24c 100644 --- a/internal/web/actions/default/servers/init.go +++ b/internal/web/actions/default/servers/init.go @@ -2,6 +2,7 @@ package servers import ( "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/users" "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" "github.com/iwind/TeaGo" ) @@ -24,6 +25,12 @@ func init() { GetPost("/addOriginPopup", new(AddOriginPopupAction)). Get("/serverNamesPopup", new(ServerNamesPopupAction)). Post("/status", new(StatusAction)). + + // + Post("/users/options", new(users.OptionsAction)). + Post("/users/plans", new(users.PlansAction)). + + // EndAll() }) } diff --git a/internal/web/actions/default/servers/server/settings/index.go b/internal/web/actions/default/servers/server/settings/index.go index 8b5bb850..a6b73987 100644 --- a/internal/web/actions/default/servers/server/settings/index.go +++ b/internal/web/actions/default/servers/server/settings/index.go @@ -64,6 +64,36 @@ func (this *IndexAction) RunGet(params struct { this.Data["user"] = nil } + // 套餐 + var userPlanMap = maps.Map{"id": server.UserPlanId, "dayTo": "", "plan": maps.Map{}} + if server.UserPlanId > 0 { + userPlanResp, err := this.RPC().UserPlanRPC().FindEnabledUserPlan(this.AdminContext(), &pb.FindEnabledUserPlanRequest{UserPlanId: server.UserPlanId}) + if err != nil { + this.ErrorPage(err) + return + } + var userPlan = userPlanResp.UserPlan + if userPlan != nil { + planResp, err := this.RPC().PlanRPC().FindEnabledPlan(this.AdminContext(), &pb.FindEnabledPlanRequest{PlanId: userPlan.PlanId}) + if err != nil { + this.ErrorPage(err) + return + } + var plan = planResp.Plan + if plan != nil { + userPlanMap = maps.Map{ + "id": userPlan.Id, + "dayTo": userPlan.DayTo, + "plan": maps.Map{ + "id": plan.Id, + "name": plan.Name, + }, + } + } + } + } + this.Data["userPlan"] = userPlanMap + // 集群 clusterId := int64(0) this.Data["clusterName"] = "" @@ -123,6 +153,7 @@ func (this *IndexAction) RunPost(params struct { ClusterId int64 GroupIds []int64 IsOn bool + UserPlanId int64 Must *actions.Must }) { @@ -137,6 +168,7 @@ func (this *IndexAction) RunPost(params struct { this.Fail("请选择部署的集群") } + // 修改基本信息 _, err := this.RPC().ServerRPC().UpdateServerBasic(this.AdminContext(), &pb.UpdateServerBasicRequest{ ServerId: params.ServerId, Name: params.Name, @@ -150,5 +182,17 @@ func (this *IndexAction) RunPost(params struct { return } + // 修改套餐 + if params.UserPlanId > 0 { + _, err = this.RPC().ServerRPC().UpdateServerUserPlan(this.AdminContext(), &pb.UpdateServerUserPlanRequest{ + ServerId: params.ServerId, + UserPlanId: params.UserPlanId, + }) + if err != nil { + this.ErrorPage(err) + return + } + } + this.Success() } diff --git a/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go b/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go index 94074a40..d43c3c99 100644 --- a/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go +++ b/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go @@ -98,7 +98,7 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString "name": "缓存", "url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString, "isActive": secondMenuItem == "cache", - "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn && len(locationConfig.Web.Cache.CacheRefs) > 0, + "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn, }) menuItems = append(menuItems, maps.Map{ "name": "访问控制", diff --git a/internal/web/actions/default/servers/serverutils/server_helper.go b/internal/web/actions/default/servers/serverutils/server_helper.go index 6eee620f..4555955a 100644 --- a/internal/web/actions/default/servers/serverutils/server_helper.go +++ b/internal/web/actions/default/servers/serverutils/server_helper.go @@ -272,7 +272,7 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri "name": "缓存", "url": "/servers/server/settings/cache?serverId=" + serverIdString, "isActive": secondMenuItem == "cache", - "isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn && len(serverConfig.Web.Cache.CacheRefs) > 0, + "isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn, }) menuItems = append(menuItems, maps.Map{ "name": "访问控制", diff --git a/internal/web/actions/default/servers/users/options.go b/internal/web/actions/default/servers/users/options.go new file mode 100644 index 00000000..7628ba63 --- /dev/null +++ b/internal/web/actions/default/servers/users/options.go @@ -0,0 +1,37 @@ +package users + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" +) + +type OptionsAction struct { + actionutils.ParentAction +} + +func (this *OptionsAction) RunPost(params struct { + Keyword string +}) { + usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{ + Keyword: params.Keyword, + Offset: 0, + Size: 10000, // TODO 改进 组件 + }) + if err != nil { + this.ErrorPage(err) + return + } + + userMaps := []maps.Map{} + for _, user := range usersResp.Users { + userMaps = append(userMaps, maps.Map{ + "id": user.Id, + "fullname": user.Fullname, + "username": user.Username, + }) + } + this.Data["users"] = userMaps + + this.Success() +} diff --git a/internal/web/actions/default/servers/users/plans.go b/internal/web/actions/default/servers/users/plans.go new file mode 100644 index 00000000..efb09337 --- /dev/null +++ b/internal/web/actions/default/servers/users/plans.go @@ -0,0 +1,49 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package users + +import ( + teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" +) + +type PlansAction struct { + actionutils.ParentAction +} + +func (this *PlansAction) RunPost(params struct { + UserId int64 + ServerId int64 +}) { + if !teaconst.IsPlus || params.UserId <= 0 { + this.Data["plans"] = []maps.Map{} + this.Success() + } + + // TODO 优化用户套餐查询 + userPlansResp, err := this.RPC().UserPlanRPC().FindAllEnabledUserPlansForServer(this.AdminContext(), &pb.FindAllEnabledUserPlansForServerRequest{ + UserId: params.UserId, + ServerId: params.ServerId, + }) + if err != nil { + this.ErrorPage(err) + return + } + var userPlanMaps = []maps.Map{} + for _, userPlan := range userPlansResp.UserPlans { + if userPlan.Plan == nil { + continue + } + + userPlanMaps = append(userPlanMaps, maps.Map{ + "id": userPlan.Id, + "name": userPlan.Plan.Name, + "dayTo": userPlan.DayTo, + }) + } + this.Data["plans"] = userPlanMaps + + this.Success() +} diff --git a/web/public/js/components/server/user-selector.js b/web/public/js/components/server/user-selector.js new file mode 100644 index 00000000..f3959093 --- /dev/null +++ b/web/public/js/components/server/user-selector.js @@ -0,0 +1,33 @@ +Vue.component("user-selector", { + mounted: function () { + let that = this + + Tea.action("/servers/users/options") + .post() + .success(function (resp) { + that.users = resp.data.users + }) + }, + props: ["v-user-id"], + data: function () { + let userId = this.vUserId + if (userId == null) { + userId = 0 + } + return { + users: [], + userId: userId + } + }, + watch: { + userId: function (v) { + this.$emit("change", v) + } + }, + template: `
+ +
` +}) \ No newline at end of file diff --git a/web/views/@default/servers/create.html b/web/views/@default/servers/create.html index 163e9eb8..a9d4d5b1 100644 --- a/web/views/@default/servers/create.html +++ b/web/views/@default/servers/create.html @@ -4,22 +4,50 @@
- +
+ + + + + + + + + + + + + + + - - - - - - @@ -113,5 +132,6 @@
服务名称 *
选择用户 + +
选择套餐 + +
部署的集群 * - -

当前服务将会部署到所选集群的节点上。

+
+ +

当前服务将会部署到所选集群的节点上。

+
+
跟随用户设置。
绑定域名 + +

绑定后,才能通过域名可以访问不同的服务。

+
服务类型 * @@ -36,15 +64,6 @@
绑定域名 - -

绑定后,才能通过域名可以访问不同的服务。

-
+
\ No newline at end of file diff --git a/web/views/@default/servers/create.js b/web/views/@default/servers/create.js index 7c876849..eff75282 100644 --- a/web/views/@default/servers/create.js +++ b/web/views/@default/servers/create.js @@ -46,4 +46,27 @@ Tea.context(function () { this.tlsProtocolName = "https" } } + + /** + * 用户相关 + */ + this.userId = 0 + this.plans = [] + + this.changeUserId = function (v) { + this.userId = v + + if (this.userId == 0) { + this.plans = [] + return + } + + this.$post("/servers/users/plans") + .params({ + userId: this.userId + }) + .success(function (resp) { + this.plans = resp.data.plans + }) + } }) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/index.html b/web/views/@default/servers/server/settings/index.html index bd755897..6bb42493 100644 --- a/web/views/@default/servers/server/settings/index.html +++ b/web/views/@default/servers/server/settings/index.html @@ -19,6 +19,15 @@ + + 选择套餐 + + + + 部署的集群 * diff --git a/web/views/@default/servers/server/settings/index.js b/web/views/@default/servers/server/settings/index.js index 295a9aaf..a03b7917 100644 --- a/web/views/@default/servers/server/settings/index.js +++ b/web/views/@default/servers/server/settings/index.js @@ -1,3 +1,36 @@ Tea.context(function () { this.success = NotifyReloadSuccess("保存成功") + + /** + * 用户相关 + */ + this.userId = 0 + this.plans = [] + this.userPlanId = 0 + + if (this.userPlan != null) { + this.userPlanId = this.userPlan.id + } + + this.changeUserId = function (v) { + this.userId = v + + if (this.userId == 0) { + this.plans = [] + return + } + + this.$post("/servers/users/plans") + .params({ + userId: this.userId, + serverId: this.serverId + }) + .success(function (resp) { + this.plans = resp.data.plans + }) + } + + if (this.user != null) { + this.changeUserId(this.user.id) + } }) \ No newline at end of file