支持套餐相关操作

This commit is contained in:
GoEdgeLab
2021-11-09 15:36:18 +08:00
parent 92a0c7acbc
commit 63a09bb5a6
12 changed files with 294 additions and 23 deletions

View File

@@ -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,

View File

@@ -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()
})
}

View File

@@ -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()
}

View File

@@ -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": "访问控制",

View File

@@ -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": "访问控制",

View File

@@ -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 改进 <plan-user-selector> 组件
})
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()
}

View File

@@ -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()
}

View File

@@ -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: `<div>
<select class="ui dropdown auto-width" name="userId" v-model="userId">
<option value="0">[选择用户]</option>
<option v-for="user in users" :value="user.id">{{user.fullname}} ({{user.username}})</option>
</select>
</div>`
})

View File

@@ -4,22 +4,50 @@
<div class="margin"></div>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<table class="ui table selectable definition">
<table class="ui table selectable definition">
<tr>
<td class="title">服务名称 *</td>
<td>
<input type="text" name="name" maxlength="60" ref="focus"/>
</td>
</tr>
<tr>
<td>选择用户</td>
<td>
<user-selector @change="changeUserId"></user-selector>
</td>
</tr>
<tr v-if="plans.length > 0">
<td>选择套餐</td>
<td>
<select class="ui dropdown auto-width" name="userPlanId">
<option value="0">[选择套餐]</option>
<option v-for="plan in plans" :value="plan.id">{{plan.name}}{{plan.dayTo}}</option>
</select>
</td>
</tr>
<tr>
<td>部署的集群 *</td>
<td>
<select class="ui dropdown auto-width" name="clusterId">
<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
</select>
<p class="comment">当前服务将会部署到所选集群的节点上。</p>
<div v-if="userId == 0">
<select class="ui dropdown auto-width" name="clusterId">
<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
</select>
<p class="comment">当前服务将会部署到所选集群的节点上。</p>
</div>
<div v-else>跟随用户设置。</div>
</td>
</tr>
<!-- 域名 -->
<tr v-if="serverType == 'httpProxy' || serverType == 'httpWeb'">
<td>绑定域名</td>
<td>
<server-name-box></server-name-box>
<p class="comment">绑定后,才能通过域名可以访问不同的服务。</p>
</td>
</tr>
<tr>
<td>服务类型 *</td>
<td>
@@ -36,15 +64,6 @@
</td>
</tr>
<!-- 域名 -->
<tr v-if="serverType == 'httpProxy' || serverType == 'httpWeb'">
<td>绑定域名</td>
<td>
<server-name-box></server-name-box>
<p class="comment">绑定后,才能通过域名可以访问不同的服务。</p>
</td>
</tr>
<!-- 证书 -->
<tbody v-if="tlsProtocolName.length > 0">
<tr>
@@ -113,5 +132,6 @@
</tr>
</tbody>
</table>
<submit-btn></submit-btn>
</form>

View File

@@ -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
})
}
})

View File

@@ -19,6 +19,15 @@
<input type="text" name="name" maxlength="60" ref="focus" v-model="server.name"/>
</td>
</tr>
<tr v-if="plans.length > 0">
<td>选择套餐</td>
<td>
<select class="ui dropdown auto-width" name="userPlanId" v-model="userPlanId">
<option value="0">[选择套餐]</option>
<option v-for="plan in plans" :value="plan.id">{{plan.name}}{{plan.dayTo}}</option>
</select>
</td>
</tr>
<tr>
<td>部署的集群 *</td>
<td>

View File

@@ -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)
}
})