请求条件增加不区分大小写选项

This commit is contained in:
GoEdgeLab
2021-12-12 16:11:25 +08:00
parent 6b7c559af2
commit 8ade6b2ec1
8 changed files with 190 additions and 20 deletions

View File

@@ -10,12 +10,13 @@ import (
) )
type CondJSComponent struct { type CondJSComponent struct {
Type string `json:"type"` Type string `json:"type"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Component string `json:"component"` Component string `json:"component"`
ParamsTitle string `json:"paramsTitle"` ParamsTitle string `json:"paramsTitle"`
IsRequest bool `json:"isRequest"` IsRequest bool `json:"isRequest"`
CaseInsensitive bool `json:"caseInsensitive"`
} }
// ReadAllAvailableCondTypes 读取所有可用的条件 // ReadAllAvailableCondTypes 读取所有可用的条件

View File

@@ -97,7 +97,8 @@ Vue.component("http-cond-url-prefix", {
isRequest: true, isRequest: true,
param: "${requestPath}", param: "${requestPath}",
operator: "prefix", operator: "prefix",
value: "" value: "",
isCaseInsensitive: false
} }
if (this.vCond != null && typeof (this.vCond.value) == "string") { if (this.vCond != null && typeof (this.vCond.value) == "string") {
cond.value = this.vCond.value cond.value = this.vCond.value
@@ -106,6 +107,11 @@ Vue.component("http-cond-url-prefix", {
cond: cond cond: cond
} }
}, },
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div> template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/> <input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/> <input type="text" v-model="cond.value"/>
@@ -121,7 +127,8 @@ Vue.component("http-cond-url-not-prefix", {
param: "${requestPath}", param: "${requestPath}",
operator: "prefix", operator: "prefix",
value: "", value: "",
isReverse: true isReverse: true,
isCaseInsensitive: false
} }
if (this.vCond != null && typeof this.vCond.value == "string") { if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value cond.value = this.vCond.value
@@ -130,6 +137,11 @@ Vue.component("http-cond-url-not-prefix", {
cond: cond cond: cond
} }
}, },
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div> template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/> <input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/> <input type="text" v-model="cond.value"/>
@@ -145,7 +157,8 @@ Vue.component("http-cond-url-eq", {
isRequest: true, isRequest: true,
param: "${requestPath}", param: "${requestPath}",
operator: "eq", operator: "eq",
value: "" value: "",
isCaseInsensitive: false
} }
if (this.vCond != null && typeof this.vCond.value == "string") { if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value cond.value = this.vCond.value
@@ -154,6 +167,11 @@ Vue.component("http-cond-url-eq", {
cond: cond cond: cond
} }
}, },
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div> template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/> <input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/> <input type="text" v-model="cond.value"/>
@@ -169,7 +187,8 @@ Vue.component("http-cond-url-not-eq", {
param: "${requestPath}", param: "${requestPath}",
operator: "eq", operator: "eq",
value: "", value: "",
isReverse: true isReverse: true,
isCaseInsensitive: false
} }
if (this.vCond != null && typeof this.vCond.value == "string") { if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value cond.value = this.vCond.value
@@ -178,6 +197,11 @@ Vue.component("http-cond-url-not-eq", {
cond: cond cond: cond
} }
}, },
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div> template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/> <input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/> <input type="text" v-model="cond.value"/>
@@ -193,7 +217,8 @@ Vue.component("http-cond-url-regexp", {
isRequest: true, isRequest: true,
param: "${requestPath}", param: "${requestPath}",
operator: "regexp", operator: "regexp",
value: "" value: "",
isCaseInsensitive: false
} }
if (this.vCond != null && typeof this.vCond.value == "string") { if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value cond.value = this.vCond.value
@@ -202,6 +227,11 @@ Vue.component("http-cond-url-regexp", {
cond: cond cond: cond
} }
}, },
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div> template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/> <input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/> <input type="text" v-model="cond.value"/>
@@ -217,7 +247,8 @@ Vue.component("http-cond-url-not-regexp", {
isRequest: true, isRequest: true,
param: "${requestPath}", param: "${requestPath}",
operator: "not regexp", operator: "not regexp",
value: "" value: "",
isCaseInsensitive: false
} }
if (this.vCond != null && typeof this.vCond.value == "string") { if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value cond.value = this.vCond.value
@@ -226,6 +257,11 @@ Vue.component("http-cond-url-not-regexp", {
cond: cond cond: cond
} }
}, },
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div> template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/> <input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/> <input type="text" v-model="cond.value"/>
@@ -233,6 +269,67 @@ Vue.component("http-cond-url-not-regexp", {
</div>` </div>`
}) })
// User-Agent正则匹配
Vue.component("http-cond-user-agent-regexp", {
props: ["v-cond"],
data: function () {
let cond = {
isRequest: true,
param: "${userAgent}",
operator: "regexp",
value: "",
isCaseInsensitive: false
}
if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value
}
return {
cond: cond
}
},
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/>
<p class="comment">匹配User-Agent的正则表达式比如<code-label>Android|iPhone</code-label>。</p>
</div>`
})
// User-Agent正则不匹配
Vue.component("http-cond-user-agent-not-regexp", {
props: ["v-cond"],
data: function () {
let cond = {
isRequest: true,
param: "${userAgent}",
operator: "not regexp",
value: "",
isCaseInsensitive: false
}
if (this.vCond != null && typeof this.vCond.value == "string") {
cond.value = this.vCond.value
}
return {
cond: cond
}
},
methods: {
changeCaseInsensitive: function (isCaseInsensitive) {
this.cond.isCaseInsensitive = isCaseInsensitive
}
},
template: `<div>
<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
<input type="text" v-model="cond.value"/>
<p class="comment">匹配User-Agent的正则表达式比如<code-label>Android|iPhone</code-label>,如果匹配,则排除此条件。</p>
</div>`
})
// 根据MimeType // 根据MimeType
Vue.component("http-cond-mime-type", { Vue.component("http-cond-mime-type", {
props: ["v-cond"], props: ["v-cond"],
@@ -376,7 +473,8 @@ Vue.component("http-cond-params", {
isRequest: true, isRequest: true,
param: "", param: "",
operator: window.REQUEST_COND_OPERATORS[0].op, operator: window.REQUEST_COND_OPERATORS[0].op,
value: "" value: "",
isCaseInsensitive: false
} }
if (this.vCond != null) { if (this.vCond != null) {
cond = this.vCond cond = this.vCond
@@ -582,5 +680,15 @@ Vue.component("http-cond-params", {
</div> </div>
</td> </td>
</tr> </tr>
<tr v-if="['regexp', 'not regexp', 'eq', 'not', 'prefix', 'suffix', 'contains', 'not contains', 'in', 'not in'].$contains(cond.operator)">
<td>不区分大小写</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="cond.isCaseInsensitive"/>
<label></label>
</div>
<p class="comment">选中后表示对比时忽略参数值的大小写。</p>
</td>
</tr>
</tbody>` </tbody>`
}) })

View File

@@ -70,6 +70,7 @@ Vue.component("http-request-conds-box", {
<var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var> <var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var>
<var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{typeName(cond)}}: </var> <var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{typeName(cond)}}: </var>
{{cond.value}} {{cond.value}}
<sup v-if="cond.isCaseInsensitive" title="不区分大小写"><i class="icon info small"></i></sup>
</span> </span>
<var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var> <var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var>

View File

@@ -58,6 +58,7 @@ Vue.component("http-request-conds-view", {
<var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var> <var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var>
<var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{cond.typeName}}: </var> <var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{cond.typeName}}: </var>
{{cond.value}} {{cond.value}}
<sup v-if="cond.isCaseInsensitive" title="不区分大小写"><i class="icon info small"></i></sup>
</span> </span>
<var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var> <var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var>

View File

@@ -13,7 +13,8 @@
"description": "根据URL中的文件路径前缀进行过滤", "description": "根据URL中的文件路径前缀进行过滤",
"component": "http-cond-url-prefix", "component": "http-cond-url-prefix",
"paramsTitle": "URL前缀", "paramsTitle": "URL前缀",
"isRequest": true "isRequest": true,
"caseInsensitive": true
}, },
{ {
"type": "url-eq", "type": "url-eq",
@@ -21,7 +22,8 @@
"description": "检查URL中的文件路径是否一致", "description": "检查URL中的文件路径是否一致",
"component": "http-cond-url-eq", "component": "http-cond-url-eq",
"paramsTitle": "URL完整路径", "paramsTitle": "URL完整路径",
"isRequest": true "isRequest": true,
"caseInsensitive": true
}, },
{ {
"type": "url-regexp", "type": "url-regexp",
@@ -29,7 +31,17 @@
"description": "使用正则表达式检查URL中的文件路径是否一致", "description": "使用正则表达式检查URL中的文件路径是否一致",
"component": "http-cond-url-regexp", "component": "http-cond-url-regexp",
"paramsTitle": "正则表达式", "paramsTitle": "正则表达式",
"isRequest": true "isRequest": true,
"caseInsensitive": true
},
{
"type": "user-agent-regexp",
"name": "User-Agent正则匹配",
"description": "使用正则表达式检查User-Agent中是否含有某些浏览器和系统标识",
"component": "http-cond-user-agent-regexp",
"paramsTitle": "正则表达式",
"isRequest": true,
"caseInsensitive": true
}, },
{ {
"type": "params", "type": "params",
@@ -45,7 +57,8 @@
"description": "根据URL中的文件路径前缀进行过滤", "description": "根据URL中的文件路径前缀进行过滤",
"component": "http-cond-url-not-prefix", "component": "http-cond-url-not-prefix",
"paramsTitle": "URL前缀", "paramsTitle": "URL前缀",
"isRequest": true "isRequest": true,
"caseInsensitive": true
}, },
{ {
"type": "url-not-eq", "type": "url-not-eq",
@@ -53,7 +66,8 @@
"description": "检查URL中的文件路径是否一致", "description": "检查URL中的文件路径是否一致",
"component": "http-cond-url-not-eq", "component": "http-cond-url-not-eq",
"paramsTitle": "URL完整路径", "paramsTitle": "URL完整路径",
"isRequest": true "isRequest": true,
"caseInsensitive": true
}, },
{ {
"type": "url-not-regexp", "type": "url-not-regexp",
@@ -61,7 +75,17 @@
"description": "使用正则表达式检查URL中的文件路径是否一致如果一致则不匹配", "description": "使用正则表达式检查URL中的文件路径是否一致如果一致则不匹配",
"component": "http-cond-url-not-regexp", "component": "http-cond-url-not-regexp",
"paramsTitle": "正则表达式", "paramsTitle": "正则表达式",
"isRequest": true "isRequest": true,
"caseInsensitive": true
},
{
"type": "user-agent-not-regexp",
"name": "排除User-Agent正则匹配",
"description": "使用正则表达式检查User-Agent中是否含有某些浏览器和系统标识如果含有则不匹配",
"component": "http-cond-user-agent-not-regexp",
"paramsTitle": "正则表达式",
"isRequest": true,
"caseInsensitive": true
}, },
{ {
"type": "mime-type", "type": "mime-type",

View File

@@ -20,11 +20,21 @@
<td> <td>
{$ range .components} {$ range .components}
{$if not (eq .Type "params") } {$if not (eq .Type "params") }
<{$ .Component} v-if="condType == '{$ .Type}'" :v-cond="cond"></{$ .Component}> <{$ .Component} v-if="condType == '{$ .Type}'" :v-cond="cond" ref="component"></{$ .Component}>
{$end} {$end}
{$ end} {$ end}
</td> </td>
</tr> </tr>
<tr v-if="paramsCaseInsensitive">
<td>不区分大小写</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="isCaseInsensitive" @change="changeCaseInsensitive"/>
<label></label>
</div>
<p class="comment">选中后表示对比时忽略参数值的大小写。</p>
</td>
</tr>
<!-- 变量相关 --> <!-- 变量相关 -->
<tbody is="http-cond-params" :v-cond="cond" v-if="condType == 'params'"></tbody> <tbody is="http-cond-params" :v-cond="cond" v-if="condType == 'params'"></tbody>

View File

@@ -2,6 +2,8 @@ Tea.context(function () {
this.isUpdating = false this.isUpdating = false
this.cond = null this.cond = null
this.paramsTitle = "" this.paramsTitle = ""
this.paramsCaseInsensitive = false
this.isCaseInsensitive = false
this.success = NotifyPopup this.success = NotifyPopup
this.condType = (this.components.length > 0) ? this.components[0].type : "" this.condType = (this.components.length > 0) ? this.components[0].type : ""
@@ -11,6 +13,9 @@ Tea.context(function () {
this.isUpdating = true this.isUpdating = true
this.condType = window.parent.UPDATING_COND.type this.condType = window.parent.UPDATING_COND.type
this.cond = window.parent.UPDATING_COND this.cond = window.parent.UPDATING_COND
if (typeof (this.cond.isCaseInsensitive) == "boolean") {
this.isCaseInsensitive = this.cond.isCaseInsensitive
}
} }
this.changeCondType = function () { this.changeCondType = function () {
@@ -20,12 +25,31 @@ Tea.context(function () {
}) })
if (c == null || c.paramsTitle.length == 0) { if (c == null || c.paramsTitle.length == 0) {
that.paramsTitle = "条件参数" that.paramsTitle = "条件参数"
that.paramsCaseInsensitive = false
} else { } else {
that.paramsTitle = c.paramsTitle that.paramsTitle = c.paramsTitle
if (typeof (c.caseInsensitive) != "undefined") {
that.paramsCaseInsensitive = c.caseInsensitive
that.$delay(function () {
that.changeCaseInsensitive()
})
} else {
that.paramsCaseInsensitive = false
}
} }
} }
this.$delay(function () { this.$delay(function () {
this.changeCondType() this.changeCondType()
}) })
this.changeCaseInsensitive = function () {
let componentRef = this.$refs.component
if (componentRef == null) {
return
}
if (typeof (componentRef.changeCaseInsensitive) == "function") {
componentRef.changeCaseInsensitive(this.isCaseInsensitive)
}
}
}) })

View File

@@ -14,6 +14,7 @@
<var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var> <var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{cond.param}} <var>{{cond.operator}}</var></var>
<var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{typeName(cond)}}: </var> <var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{typeName(cond)}}: </var>
{{cond.value}} {{cond.value}}
<sup v-if="cond.isCaseInsensitive" title="不区分大小写"><i class="icon info small"></i></sup> &nbsp;
<a href="" title="修改" @click.prevent="updateCond(index, cond)"><i class="icon pencil small"></i></a> <a href="" title="删除" @click.prevent="removeCond(index)"><i class="icon remove"></i></a> </span> <a href="" title="修改" @click.prevent="updateCond(index, cond)"><i class="icon pencil small"></i></a> <a href="" title="删除" @click.prevent="removeCond(index)"><i class="icon remove"></i></a> </span>
<var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var> <var v-if="index < group.conds.length - 1"> {{group.connector}} &nbsp;</var>
</var> </var>