添加、修改、删除HTTP Header时增加通用Header提示

This commit is contained in:
刘祥超
2022-10-24 15:42:18 +08:00
parent 6a920f964f
commit bf597fe41c
11 changed files with 99 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package headers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
type OptionsAction struct {
actionutils.ParentAction
}
func (this *OptionsAction) RunPost(params struct {
Type string
}) {
if params.Type == "request" {
this.Data["headers"] = serverconfigs.AllHTTPCommonRequestHeaders
} else if params.Type == "response" {
this.Data["headers"] = serverconfigs.AllHTTPCommonResponseHeaders
} else {
this.Data["headers"] = []string{}
}
this.Success()
}

View File

@@ -2,6 +2,7 @@ package servers
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders" "github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/headers"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/users" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/users"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo" "github.com/iwind/TeaGo"
@@ -26,10 +27,13 @@ func init() {
Get("/serverNamesPopup", new(ServerNamesPopupAction)). Get("/serverNamesPopup", new(ServerNamesPopupAction)).
Post("/status", new(StatusAction)). Post("/status", new(StatusAction)).
// // user
Post("/users/options", new(users.OptionsAction)). Post("/users/options", new(users.OptionsAction)).
Post("/users/plans", new(users.PlansAction)). Post("/users/plans", new(users.PlansAction)).
// header
Post("/headers/options", new(headers.OptionsAction)).
// //
EndAll() EndAll()
}) })

View File

@@ -19,8 +19,10 @@ func (this *CreateDeletePopupAction) Init() {
func (this *CreateDeletePopupAction) RunGet(params struct { func (this *CreateDeletePopupAction) RunGet(params struct {
HeaderPolicyId int64 HeaderPolicyId int64
Type string
}) { }) {
this.Data["headerPolicyId"] = params.HeaderPolicyId this.Data["headerPolicyId"] = params.HeaderPolicyId
this.Data["type"] = params.Type
this.Show() this.Show()
} }

View File

@@ -8,7 +8,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
) )
// 删除Header // DeleteAction 删除Header
type DeleteAction struct { type DeleteAction struct {
actionutils.ParentAction actionutils.ParentAction
} }

View File

@@ -0,0 +1,44 @@
Vue.component("http-header-assistant", {
props: ["v-type", "v-value"],
mounted: function () {
let that = this
Tea.action("/servers/headers/options?type=" + this.vType)
.post()
.success(function (resp) {
that.allHeaders = resp.data.headers
})
},
data: function () {
return {
allHeaders: [],
matchedHeaders: [],
selectedHeaderName: ""
}
},
watch: {
vValue: function (v) {
if (v != this.selectedHeaderName) {
this.selectedHeaderName = ""
}
if (v.length == 0) {
this.matchedHeaders = []
return
}
this.matchedHeaders = this.allHeaders.filter(function (header) {
return teaweb.match(header, v)
}).slice(0, 5)
}
},
methods: {
select: function (header) {
this.$emit("select", header)
this.selectedHeaderName = header
}
},
template: `<span v-if="selectedHeaderName.length == 0">
<a href="" v-for="header in matchedHeaders" class="ui label basic tiny blue" style="font-weight: normal" @click.prevent="select(header)">{{header}}</a>
<span v-if="matchedHeaders.length > 0">&nbsp; &nbsp;</span>
</span>`
})

View File

@@ -7,8 +7,8 @@
<tr> <tr>
<td class="title">名称<em>Name</em></td> <td class="title">名称<em>Name</em></td>
<td> <td>
<input type="text" name="name" maxlength="100" ref="focus"/> <input type="text" name="name" maxlength="100" ref="focus" v-model="headerName"/>
<p class="comment">请注意名称的大小写如无特殊需求Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label></p> <p class="comment"><http-header-assistant :v-type="type" :v-value="headerName" @select="selectHeader"></http-header-assistant>请注意名称的大小写如无特殊需求Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label></p>
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -0,0 +1,7 @@
Tea.context(function () {
this.headerName = ""
this.selectHeader = function (headerName) {
this.headerName = headerName
}
})

View File

@@ -7,8 +7,8 @@
<tr> <tr>
<td class="title">名称<em>Name</em> *</td> <td class="title">名称<em>Name</em> *</td>
<td> <td>
<input type="text" name="name" value="" maxlength="200" placeholder="类似于Server、Content-Type之类" ref="focus"/> <input type="text" name="name" value="" maxlength="200" placeholder="类似于Server、Content-Type之类" ref="focus" v-model="headerName" autocomplete="off"/>
<p class="comment">请注意名称的大小写如无特殊需求Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label></p> <p class="comment"><http-header-assistant :v-type="type" :v-value="headerName" @select="selectHeader"></http-header-assistant>请注意名称的大小写如无特殊需求Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label></p>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -1,3 +1,8 @@
Tea.context(function () { Tea.context(function () {
this.shouldReplace = false this.shouldReplace = false
this.headerName = ""
this.selectHeader = function (headerName) {
this.headerName = headerName
}
}) })

View File

@@ -9,7 +9,7 @@
<td class="title">名称<em>Name</em> *</td> <td class="title">名称<em>Name</em> *</td>
<td> <td>
<input type="text" name="name" value="" v-model="headerConfig.name" maxlength="200" placeholder="类似于Server、Content-Type之类" ref="focus"/> <input type="text" name="name" value="" v-model="headerConfig.name" maxlength="200" placeholder="类似于Server、Content-Type之类" ref="focus"/>
<p class="comment">请注意名称的大小写如无特殊需求Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label></p> <p class="comment"><http-header-assistant :v-type="type" :v-value="headerConfig.name" @select="selectHeader"></http-header-assistant>请注意名称的大小写如无特殊需求Header名称的格式通常为<code-label>Xxx</code-label>或者<code-label>Xxx-Yyy</code-label></p>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@@ -4,4 +4,8 @@ Tea.context(function () {
if (this.headerConfig.status != null && this.headerConfig.status.codes != null) { if (this.headerConfig.status != null && this.headerConfig.status.codes != null) {
this.statusList = this.headerConfig.status.codes this.statusList = this.headerConfig.status.codes
} }
this.selectHeader = function (headerName) {
this.headerConfig.name = headerName
}
}) })