创建网站服务时强制填写域名/优化源站未填写时交互

This commit is contained in:
刘祥超
2022-05-07 20:26:40 +08:00
parent 34b7cfec6f
commit 36326697d7
4 changed files with 44 additions and 15 deletions

View File

@@ -80,7 +80,7 @@ func (this *CreateAction) RunPost(params struct {
ServerType string ServerType string
Addresses string Addresses string
ServerNames string ServerNames []byte
CertIdsJSON []byte CertIdsJSON []byte
Origins string Origins string
@@ -274,9 +274,9 @@ func (this *CreateAction) RunPost(params struct {
} }
// 域名 // 域名
var serverNames = []*serverconfigs.ServerNameConfig{}
if len(params.ServerNames) > 0 { if len(params.ServerNames) > 0 {
serverNames := []*serverconfigs.ServerNameConfig{} err := json.Unmarshal(params.ServerNames, &serverNames)
err := json.Unmarshal([]byte(params.ServerNames), &serverNames)
if err != nil { if err != nil {
this.Fail("域名解析失败:" + err.Error()) this.Fail("域名解析失败:" + err.Error())
} }
@@ -297,6 +297,9 @@ func (this *CreateAction) RunPost(params struct {
} }
} }
} }
if params.ServerType == serverconfigs.ServerTypeHTTPProxy && len(serverNames) == 0 {
this.FailField("emptyDomain", "请输入添加至少一个域名")
}
// 源站地址 // 源站地址
var reverseProxyRefJSON = []byte{} var reverseProxyRefJSON = []byte{}
@@ -308,7 +311,7 @@ func (this *CreateAction) RunPost(params struct {
this.Fail("源站地址解析失败:" + err.Error()) this.Fail("源站地址解析失败:" + err.Error())
} }
if len(originConfigs) == 0 { if len(originConfigs) == 0 {
this.Fail("请添加至少一个源站地址") this.FailField("emptyOrigin", "请添加至少一个源站地址")
} }
var originRefs = []*serverconfigs.OriginRef{} var originRefs = []*serverconfigs.OriginRef{}
@@ -387,7 +390,7 @@ func (this *CreateAction) RunPost(params struct {
return return
} }
req := &pb.CreateServerRequest{ var req = &pb.CreateServerRequest{
UserId: userId, UserId: userId,
UserPlanId: userPlanId, UserPlanId: userPlanId,
AdminId: this.AdminId(), AdminId: this.AdminId(),

View File

@@ -397,9 +397,9 @@ window.teaweb = {
}) })
}, },
warn: function (message, callback) { warn: function (message, callback) {
var width = "20em"; var width = "20em"
if (message.length > 30) { if (message.length > 30) {
width = "30em"; width = "30em"
} }
Swal.fire({ Swal.fire({
text: message, text: message,
@@ -415,16 +415,16 @@ window.teaweb = {
onAfterClose: function () { onAfterClose: function () {
if (typeof (callback) == "function") { if (typeof (callback) == "function") {
setTimeout(function () { setTimeout(function () {
callback(); callback()
}); })
} }
} }
}); })
}, },
confirm: function (message, callback) { confirm: function (message, callback) {
let width = "20em"; let width = "20em"
if (message.length > 30) { if (message.length > 30) {
width = "30em"; width = "30em"
} }
let config = { let config = {
confirmButtonText: "确定", confirmButtonText: "确定",
@@ -441,7 +441,7 @@ window.teaweb = {
width: width, width: width,
preConfirm: function () { preConfirm: function () {
if (typeof (callback) == "function") { if (typeof (callback) == "function") {
callback.call(Tea.Vue); callback.call(Tea.Vue)
} }
} }
} }

View File

@@ -3,7 +3,7 @@
<div class="margin"></div> <div class="margin"></div>
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success"> <form method="post" class="ui form" data-tea-action="$" data-tea-success="success" data-tea-fail="fail">
<table class="ui table selectable definition"> <table class="ui table selectable definition">
<tr> <tr>
<td class="title">服务名称 *</td> <td class="title">服务名称 *</td>
@@ -45,7 +45,7 @@
<tr v-if="serverType == 'httpProxy' || serverType == 'httpWeb'"> <tr v-if="serverType == 'httpProxy' || serverType == 'httpWeb'">
<td>绑定域名 *</td> <td>绑定域名 *</td>
<td> <td>
<server-name-box></server-name-box> <server-name-box ref="serverNameBox"></server-name-box>
<p class="comment">绑定后,才能通过域名可以访问不同的服务。</p> <p class="comment">绑定后,才能通过域名可以访问不同的服务。</p>
</td> </td>
</tr> </tr>

View File

@@ -6,6 +6,32 @@ Tea.context(function () {
this.success = NotifySuccess("保存成功", "/servers"); this.success = NotifySuccess("保存成功", "/servers");
this.fail = function (resp) {
if (resp.errors != null && resp.errors.length > 0) {
let isFiltered = false
let that = this
resp.errors.forEach(function (err) {
if (err.param == "emptyDomain") {
isFiltered = true
teaweb.warn(err.messages[0], function () {
that.$refs.serverNameBox.addServerName()
})
} else if (err.param == "emptyOrigin") {
isFiltered = true
teaweb.warn(err.messages[0], function () {
that.addOrigin()
})
}
})
if (isFiltered) {
return
}
}
Tea.failResponse(resp)
}
this.changeServerType = function () { this.changeServerType = function () {
this.origins = [] this.origins = []
this.tlsProtocolName = "" this.tlsProtocolName = ""