mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-13 20:00:25 +08:00
优化添加端口、添加源站相关交互
This commit is contained in:
@@ -9,11 +9,12 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 添加源站
|
||||
// AddPopupAction 添加源站
|
||||
type AddPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -64,11 +65,28 @@ func (this *AddPopupAction) RunPost(params struct {
|
||||
Field("addr", params.Addr).
|
||||
Require("请输入源站地址")
|
||||
|
||||
addr := regexp.MustCompile(`\s+`).ReplaceAllString(params.Addr, "")
|
||||
portIndex := strings.LastIndex(params.Addr, ":")
|
||||
addr := params.Addr
|
||||
|
||||
// 是否是完整的地址
|
||||
if params.Protocol == "http" || params.Protocol == "https" {
|
||||
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 params.Protocol == "http" {
|
||||
addr += ":80"
|
||||
} else if params.Protocol == "https" {
|
||||
addr += ":443"
|
||||
} else {
|
||||
this.Fail("地址中需要带有端口")
|
||||
}
|
||||
portIndex = strings.LastIndex(addr, ":")
|
||||
}
|
||||
host := addr[:portIndex]
|
||||
port := addr[portIndex+1:]
|
||||
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 修改源站
|
||||
// UpdatePopupAction 修改源站
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -118,11 +119,28 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Field("addr", params.Addr).
|
||||
Require("请输入源站地址")
|
||||
|
||||
addr := regexp.MustCompile(`\s+`).ReplaceAllString(params.Addr, "")
|
||||
portIndex := strings.LastIndex(params.Addr, ":")
|
||||
addr := params.Addr
|
||||
|
||||
// 是否是完整的地址
|
||||
if params.Protocol == "http" || params.Protocol == "https" {
|
||||
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 params.Protocol == "http" {
|
||||
addr += ":80"
|
||||
} else if params.Protocol == "https" {
|
||||
addr += ":443"
|
||||
} else {
|
||||
this.Fail("地址中需要带有端口")
|
||||
}
|
||||
portIndex = strings.LastIndex(addr, ":")
|
||||
}
|
||||
host := addr[:portIndex]
|
||||
port := addr[portIndex+1:]
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<tr>
|
||||
<td>网络协议</td>
|
||||
<td>
|
||||
<select class="ui dropdown auto-width" name="protocol" v-model="protocol">
|
||||
<select class="ui dropdown auto-width" name="protocol" v-model="protocol" @change="changeProtocol">
|
||||
<option v-for="p in protocols" :value="p.code">{{p.name}}</option>
|
||||
</select>
|
||||
</td>
|
||||
@@ -17,8 +17,8 @@
|
||||
<td>
|
||||
<input type="text" name="address" ref="focus" v-model="address"/>
|
||||
<p class="comment">可以是一个数字端口(通常不超过65535),也可以是"地址:端口"的方式。
|
||||
<span v-if="protocol == 'http'">HTTP常用端口为80。</span>
|
||||
<span v-if="protocol == 'https'">HTTPS常用端口为443。</span>
|
||||
<span v-if="protocol == 'http'">HTTP常用端口为<a href="" title="点击添加" @click.prevent="addPort('80')">80</a>。</span>
|
||||
<span v-if="protocol == 'https'">HTTPS常用端口为<a href="" title="点击添加" @click.prevent="addPort('443')">443</a>。</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -6,6 +6,11 @@ Tea.context(function () {
|
||||
this.address = ""
|
||||
this.protocol = this.protocols[0].code
|
||||
|
||||
// 初始化
|
||||
if (this.protocol == "http") {
|
||||
this.address = "80"
|
||||
}
|
||||
|
||||
if (window.parent.UPDATING_ADDR != null) {
|
||||
this.isUpdating = true
|
||||
let addr = window.parent.UPDATING_ADDR
|
||||
@@ -16,4 +21,18 @@ Tea.context(function () {
|
||||
this.address = addr.host + ":" + addr.portRange
|
||||
}
|
||||
}
|
||||
|
||||
this.changeProtocol = function () {
|
||||
switch (this.protocol) {
|
||||
case "http":
|
||||
this.address = "80"
|
||||
break
|
||||
case "https":
|
||||
this.address = "443"
|
||||
}
|
||||
}
|
||||
|
||||
this.addPort = function (port) {
|
||||
this.address = port
|
||||
}
|
||||
});
|
||||
@@ -21,6 +21,7 @@
|
||||
<tr>
|
||||
<td class="title">绑定端口 *</td>
|
||||
<td>
|
||||
<span class="red" v-if="httpConfig.isOn && httpConfig.addresses == null || httpConfig.addresses.length == 0">还没有添加端口绑定,会导致HTTP服务无法访问。</span>
|
||||
<network-addresses-box :v-server-type="serverType" :v-addresses="httpConfig.addresses" :v-protocol="'http'"></network-addresses-box>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<tr>
|
||||
<td class="title">绑定端口 *</td>
|
||||
<td>
|
||||
<span class="red" v-if="httpsConfig.isOn && httpsConfig.addresses == null || httpsConfig.addresses.length == 0">还没有添加端口绑定,会导致HTTPS服务无法访问。</span>
|
||||
<network-addresses-box :v-server-type="serverType" :v-addresses="httpsConfig.addresses" :v-protocol="'https'"></network-addresses-box>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<td>源站协议</td>
|
||||
<td>
|
||||
<!-- HTTP -->
|
||||
<select class="ui dropdown auto-width" name="protocol" v-if="serverType == 'httpProxy' || serverType == 'httpWeb'">
|
||||
<select class="ui dropdown auto-width" name="protocol" v-model="protocol" v-if="serverType == 'httpProxy' || serverType == 'httpWeb'">
|
||||
<option value="http">HTTP</option>
|
||||
<option value="https">HTTPS</option>
|
||||
</select>
|
||||
@@ -25,7 +25,7 @@
|
||||
<tr>
|
||||
<td class="title">源站地址 *</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>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
Tea.context(function () {
|
||||
this.addr = ""
|
||||
this.protocol = ""
|
||||
|
||||
if (this.isHTTP) {
|
||||
this.protocol = "http"
|
||||
}
|
||||
|
||||
this.changeAddr = function () {
|
||||
if (this.serverType == "httpProxy") {
|
||||
if (this.addr.startsWith("http://")) {
|
||||
this.protocol = "http"
|
||||
} else if (this.addr.startsWith("https://")) {
|
||||
this.protocol = "https"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -27,7 +27,7 @@
|
||||
<tr>
|
||||
<td class="title">源站地址</td>
|
||||
<td>
|
||||
<input type="text" name="addr" ref="focus" v-model="origin.addr"/>
|
||||
<input type="text" name="addr" ref="focus" v-model="origin.addr" @input="changeAddr"/>
|
||||
<p class="comment">源站服务器地址,通常是一个IP(或域名)加端口<span v-if="serverType == 'httpProxy'">,不需要加 http:// 或 https://</span>。</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
Tea.context(function () {
|
||||
this.changeAddr = function () {
|
||||
if (this.serverType == "httpProxy") {
|
||||
if (this.origin.addr.startsWith("http://")) {
|
||||
this.origin.protocol = "http"
|
||||
} else if (this.origin.addr.startsWith("https://")) {
|
||||
this.origin.protocol = "https"
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user