优化界面

This commit is contained in:
GoEdgeLab
2021-06-07 16:23:37 +08:00
parent b13f9c5dfe
commit b3d3f251b3
3 changed files with 68 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"net/url"
"regexp" "regexp"
"strings" "strings"
) )
@@ -36,11 +37,28 @@ func (this *AddOriginPopupAction) RunPost(params struct {
Field("addr", params.Addr). Field("addr", params.Addr).
Require("请输入源站地址") Require("请输入源站地址")
addr := regexp.MustCompile(`\s+`).ReplaceAllString(params.Addr, "") addr := params.Addr
portIndex := strings.LastIndex(params.Addr, ":")
// 是否是完整的地址
if (params.Protocol == "http" || params.Protocol == "https") && regexp.MustCompile(`^(http|https)://`).MatchString(addr) {
u, err := url.Parse(addr)
if err == nil {
addr = u.Host
}
}
addr = regexp.MustCompile(`\s+`).ReplaceAllString(addr, "")
portIndex := strings.LastIndex(addr, ":")
if portIndex < 0 { if portIndex < 0 {
if params.Protocol == "http" {
addr += ":80"
} else if params.Protocol == "https" {
addr += ":443"
} else {
this.Fail("地址中需要带有端口") this.Fail("地址中需要带有端口")
} }
portIndex = strings.LastIndex(addr, ":")
}
host := addr[:portIndex] host := addr[:portIndex]
port := addr[portIndex+1:] port := addr[portIndex+1:]

View File

@@ -8,7 +8,7 @@
<td>源站协议</td> <td>源站协议</td>
<td> <td>
<!-- HTTP --> <!-- HTTP -->
<select class="ui dropdown auto-width" name="protocol" v-if="serverType == 'httpProxy' || serverType == 'httpWeb'"> <select class="ui dropdown auto-width" name="protocol" v-if="serverType == 'httpProxy' || serverType == 'httpWeb'" @change="changeProtocol" v-model="protocol">
<option value="http">HTTP</option> <option value="http">HTTP</option>
<option value="https">HTTPS</option> <option value="https">HTTPS</option>
</select> </select>
@@ -28,8 +28,8 @@
<tr> <tr>
<td class="title">源站地址</td> <td class="title">源站地址</td>
<td> <td>
<input type="text" name="addr" ref="focus"/> <input type="text" name="addr" ref="focus" v-model="addr" @input="changeAddr"/>
<p class="comment">源站服务器地址通常是一个IP或域名加端口<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span></p> <p class="comment"><span class="red" v-if="addrError.length > 0">{{addrError}}</span>源站服务器地址通常是一个IP或域名加端口<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span></p>
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -0,0 +1,44 @@
Tea.context(function () {
this.addr = ""
this.protocol = ""
this.addrError = ""
if (this.serverType == "httpProxy") {
this.protocol = "http"
}
this.changeProtocol = function () {
this.checkPort()
}
this.changeAddr = function () {
if (this.serverType == "httpProxy") {
if (this.addr.startsWith("http://")) {
this.protocol = "http"
} else if (this.addr.startsWith("https://")) {
this.protocol = "https"
}
}
this.checkPort()
}
this.checkPort = function () {
this.addrError = ""
// HTTP
if (this.protocol == "http") {
if (this.addr.endsWith(":443")) {
this.addrError = "443通常是HTTPS协议端口请确认源站协议选择是否正确。"
}
}
// HTTPS
if (this.protocol == "https") {
if (this.addr.endsWith(":80")) {
this.addrError = "80通常是HTTP协议端口请确认源站协议选择是否正确。"
}
}
}
})