diff --git a/internal/web/actions/default/servers/server/settings/cache/createPopup.go b/internal/web/actions/default/servers/server/settings/cache/createPopup.go index 1ede0d45..053cb37b 100644 --- a/internal/web/actions/default/servers/server/settings/cache/createPopup.go +++ b/internal/web/actions/default/servers/server/settings/cache/createPopup.go @@ -15,7 +15,11 @@ func (this *CreatePopupAction) Init() { this.Nav("", "", "") } -func (this *CreatePopupAction) RunGet(params struct{}) { +func (this *CreatePopupAction) RunGet(params struct { + IsReverse bool +}) { + this.Data["isReverse"] = params.IsReverse + this.Show() } diff --git a/internal/web/actions/default/servers/server/settings/conds/addCondPopup.go b/internal/web/actions/default/servers/server/settings/conds/addCondPopup.go index 0235bf10..b752c2a7 100644 --- a/internal/web/actions/default/servers/server/settings/conds/addCondPopup.go +++ b/internal/web/actions/default/servers/server/settings/conds/addCondPopup.go @@ -32,6 +32,10 @@ func (this *AddCondPopupAction) RunPost(params struct { if err != nil { this.Fail("解析条件设置时发生了错误:" + err.Error()) } + err = condConfig.Init() + if err != nil { + this.Fail("校验条件设置时失败:" + err.Error()) + } condConfig.Type = params.CondType this.Data["cond"] = condConfig diff --git a/internal/web/actions/default/servers/server/settings/conds/addGroupPopup.go b/internal/web/actions/default/servers/server/settings/conds/addGroupPopup.go index b23ce5a6..35a12aba 100644 --- a/internal/web/actions/default/servers/server/settings/conds/addGroupPopup.go +++ b/internal/web/actions/default/servers/server/settings/conds/addGroupPopup.go @@ -32,6 +32,11 @@ func (this *AddGroupPopupAction) RunPost(params struct { this.Fail("解析条件时发生错误:" + err.Error()) } + err = groupConfig.Init() + if err != nil { + this.Fail("校验条件设置时失败:" + err.Error()) + } + this.Data["group"] = groupConfig this.Success() } diff --git a/internal/web/actions/default/servers/server/settings/conds/condutils/utils.go b/internal/web/actions/default/servers/server/settings/conds/condutils/utils.go index 3b2e1147..672aa324 100644 --- a/internal/web/actions/default/servers/server/settings/conds/condutils/utils.go +++ b/internal/web/actions/default/servers/server/settings/conds/condutils/utils.go @@ -14,6 +14,7 @@ type CondJSComponent struct { Name string `json:"name"` Description string `json:"description"` Component string `json:"component"` + ParamsTitle string `json:"paramsTitle"` IsRequest bool `json:"isRequest"` } diff --git a/web/public/js/components/server/http-cache-ref-box.js b/web/public/js/components/server/http-cache-ref-box.js index 8f077880..4df8f0cb 100644 --- a/web/public/js/components/server/http-cache-ref-box.js +++ b/web/public/js/components/server/http-cache-ref-box.js @@ -1,5 +1,6 @@ +// 单个缓存条件设置 Vue.component("http-cache-ref-box", { - props: ["v-cache-ref"], + props: ["v-cache-ref", "v-is-reverse"], data: function () { let ref = this.vCacheRef if (ref == null) { @@ -14,7 +15,8 @@ Vue.component("http-cache-ref-box", { skipSetCookie: true, enableRequestCachePragma: false, conds: null, - allowChunkedEncoding: true + allowChunkedEncoding: true, + isReverse: this.vIsReverse } } if (ref.life == null) { @@ -51,50 +53,50 @@ Vue.component("http-cache-ref-box", { -
用来区分不同缓存内容的唯一Key。
选中后,Gzip和Chunked内容可以直接缓存,无需检查内容长度。
允许缓存的HTTP状态码列表。
当响应的Cache-Control为这些值时不缓存响应内容,而且不区分大小写。
选中后,当响应的Header中有Set-Cookie时不缓存响应内容。
| 缓存条件 | +条件 | +分组关系 | 缓存时间 | 操作 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| + |
|
- {{cacheRef.life.count}} {{timeUnitName(cacheRef.life.unit)}} | ++ 和 + 或 + | ++ {{cacheRef.life.count}} {{timeUnitName(cacheRef.life.unit)}} + 不缓存 + |
修改
删除
diff --git a/web/public/js/components/server/http-cache-refs-config-box.js b/web/public/js/components/server/http-cache-refs-config-box.js
index 13e462d0..e53a0f63 100644
--- a/web/public/js/components/server/http-cache-refs-config-box.js
+++ b/web/public/js/components/server/http-cache-refs-config-box.js
@@ -1,16 +1,37 @@
Vue.component("http-cache-refs-config-box", {
props: ["v-cache-refs"],
+ mounted: function () {
+ let that = this
+ sortTable(function (ids) {
+ let newRefs = []
+ ids.forEach(function (id) {
+ that.refs.forEach(function (ref) {
+ if (ref.id == id) {
+ newRefs.push(ref)
+ }
+ })
+ })
+ that.refs = newRefs
+ })
+ },
data: function () {
let refs = this.vCacheRefs
if (refs == null) {
refs = []
}
+
+ let id = 0
+ refs.forEach(function (ref) {
+ id++
+ ref.id = id
+ })
return {
- refs: refs
+ refs: refs,
+ id: id // 用来对条件进行排序
}
},
methods: {
- addRef: function () {
+ addRef: function (isReverse) {
window.UPDATING_CACHE_REF = null
let width = window.innerWidth
@@ -22,10 +43,12 @@ Vue.component("http-cache-refs-config-box", {
height = 500
}
let that = this
- teaweb.popup("/servers/server/settings/cache/createPopup", {
+ teaweb.popup("/servers/server/settings/cache/createPopup?isReverse=" + (isReverse ? 1 : 0), {
width: width + "px",
height: height + "px",
callback: function (resp) {
+ that.id++
+ resp.data.cacheRef.id = that.id
that.refs.push(resp.data.cacheRef)
}
})
@@ -46,7 +69,11 @@ Vue.component("http-cache-refs-config-box", {
width: width + "px",
height: height + "px",
callback: function (resp) {
+ resp.data.cacheRef.id = that.refs[index].id
Vue.set(that.refs, index, resp.data.cacheRef)
+
+ // 通知子组件更新
+ that.$refs.cacheRef[index].notifyChange()
}
})
},
@@ -78,27 +105,40 @@ Vue.component("http-cache-refs-config-box", {
-
所有条件匹配顺序为从上到下,可以拖动左侧的排序。 - + +添加不缓存设置 ` diff --git a/web/public/js/components/server/http-cond-definitions.js b/web/public/js/components/server/http-cond-definitions.js index 114da667..9b601c95 100644 --- a/web/public/js/components/server/http-cond-definitions.js +++ b/web/public/js/components/server/http-cond-definitions.js @@ -2,18 +2,26 @@ Vue.component("http-cond-url-extension", { props: ["v-cond"], data: function () { - let cond = this.vCond - if (cond == null) { - cond = { - isRequest: true, - param: "${requestPathExtension}", - operator: "in", - value: "[]" - } + let cond = { + isRequest: true, + param: "${requestPathExtension}", + operator: "in", + value: "[]" } + if (this.vCond != null && this.vCond.param == cond.param) { + cond.value = this.vCond.value + } + + let extensions = [] + try { + extensions = JSON.parse(cond.value) + } catch (e) { + + } + return { cond: cond, - extensions: JSON.parse(cond.value), // TODO 可以拖动排序 + extensions: extensions, // TODO 可以拖动排序 isAdding: false, addingExt: "" @@ -49,7 +57,7 @@ Vue.component("http-cond-url-extension", { if (this.addingExt[0] != ".") { this.addingExt = "." + this.addingExt } - this.addingExt = this.addingExt.replace(/\s+/g, "") + this.addingExt = this.addingExt.replace(/\s+/g, "").toLowerCase() this.extensions.push(this.addingExt) // 清除状态 @@ -74,7 +82,9 @@ Vue.component("http-cond-url-extension", { - +
+
+
扩展名需要包含点(.)符号,例如.jpg、.png之类。 ` }) @@ -83,14 +93,14 @@ Vue.component("http-cond-url-extension", { Vue.component("http-cond-url-prefix", { props: ["v-cond"], data: function () { - let cond = this.vCond - if (cond == null) { - cond = { - isRequest: true, - param: "${requestPath}", - operator: "prefix", - value: "" - } + let cond = { + isRequest: true, + param: "${requestPath}", + operator: "prefix", + value: "" + } + if (this.vCond != null && typeof (this.vCond.value) == "string") { + cond.value = this.vCond.value } return { cond: cond @@ -99,6 +109,31 @@ Vue.component("http-cond-url-prefix", { template: `
+ `
+})
+
+Vue.component("http-cond-url-not-prefix", {
+ props: ["v-cond"],
+ data: function () {
+ let cond = {
+ isRequest: true,
+ param: "${requestPath}",
+ operator: "prefix",
+ value: "",
+ isReverse: true
+ }
+ if (this.vCond != null && typeof this.vCond.value == "string") {
+ cond.value = this.vCond.value
+ }
+ return {
+ cond: cond
+ }
+ },
+ template: `URL前缀,通常以
+
+
+ `
})
@@ -106,22 +141,47 @@ Vue.component("http-cond-url-prefix", {
Vue.component("http-cond-url-eq", {
props: ["v-cond"],
data: function () {
- let cond = this.vCond
- if (cond == null) {
- cond = {
- isRequest: true,
- param: "${requestPath}",
- operator: "eq",
- value: ""
- }
+ let cond = {
+ isRequest: true,
+ param: "${requestPath}",
+ operator: "eq",
+ value: ""
+ }
+ if (this.vCond != null && typeof this.vCond.value == "string") {
+ cond.value = this.vCond.value
}
return {
cond: cond
}
},
template: `要排除的URL前缀,通常以
-
+
+ `
+})
+
+Vue.component("http-cond-url-not-eq", {
+ props: ["v-cond"],
+ data: function () {
+ let cond = {
+ isRequest: true,
+ param: "${requestPath}",
+ operator: "eq",
+ value: "",
+ isReverse: true
+ }
+ if (this.vCond != null && typeof this.vCond.value == "string") {
+ cond.value = this.vCond.value
+ }
+ return {
+ cond: cond
+ }
+ },
+ template: `完整的URL路径,通常以
+
+
+ `
})
@@ -129,22 +189,23 @@ Vue.component("http-cond-url-eq", {
Vue.component("http-cond-url-regexp", {
props: ["v-cond"],
data: function () {
- let cond = this.vCond
- if (cond == null) {
- cond = {
- isRequest: true,
- param: "${requestPath}",
- operator: "regexp",
- value: ""
- }
+ let cond = {
+ isRequest: true,
+ param: "${requestPath}",
+ operator: "regexp",
+ value: ""
+ }
+ if (this.vCond != null && typeof this.vCond.value == "string") {
+ cond.value = this.vCond.value
}
return {
cond: cond
}
},
template: `要排除的完整的URL路径,通常以
-
+
+ `
})
@@ -152,22 +213,23 @@ Vue.component("http-cond-url-regexp", {
Vue.component("http-cond-url-not-regexp", {
props: ["v-cond"],
data: function () {
- let cond = this.vCond
- if (cond == null) {
- cond = {
- isRequest: true,
- param: "${requestPath}",
- operator: "not regexp",
- value: ""
- }
+ let cond = {
+ isRequest: true,
+ param: "${requestPath}",
+ operator: "not regexp",
+ value: ""
+ }
+ if (this.vCond != null && typeof this.vCond.value == "string") {
+ cond.value = this.vCond.value
}
return {
cond: cond
}
},
template: `匹配URL的正则表达式,比如
-
+
+ `
})
@@ -175,14 +237,14 @@ Vue.component("http-cond-url-not-regexp", {
Vue.component("http-cond-mime-type", {
props: ["v-cond"],
data: function () {
- let cond = this.vCond
- if (cond == null) {
- cond = {
- isRequest: false,
- param: "${response.contentType}",
- operator: "mime type",
- value: "[]"
- }
+ let cond = {
+ isRequest: false,
+ param: "${response.contentType}",
+ operator: "mime type",
+ value: "[]"
+ }
+ if (this.vCond != null && this.vCond.param == cond.param) {
+ cond.value = this.vCond.value
}
return {
cond: cond,
@@ -244,7 +306,9 @@ Vue.component("http-cond-mime-type", {
-
+ 不要匹配URL的正则表达式,意即只要匹配成功则排除此条件,比如
+
+
服务器返回的内容的MimeType,比如text/html、image/*等。 ` }) \ No newline at end of file diff --git a/web/public/js/components/server/http-request-conds-box.js b/web/public/js/components/server/http-request-conds-box.js index 971762df..2fbba2a6 100644 --- a/web/public/js/components/server/http-request-conds-box.js +++ b/web/public/js/components/server/http-request-conds-box.js @@ -63,7 +63,7 @@ Vue.component("http-request-conds-box", {
-
+
- - 只要满足其中一个条件分组即可。 - 需要满足所有条件分组。 - ` }) \ No newline at end of file diff --git a/web/public/js/components/server/http-request-conds-view.js b/web/public/js/components/server/http-request-conds-view.js index 2a12226a..bd708869 100644 --- a/web/public/js/components/server/http-request-conds-view.js +++ b/web/public/js/components/server/http-request-conds-view.js @@ -9,35 +9,53 @@ Vue.component("http-request-conds-view", { groups: [] } } + + let that = this + conds.groups.forEach(function (group) { + group.conds.forEach(function (cond) { + cond.typeName = that.typeName(cond) + }) + }) + return { initConds: conds, - components: window.REQUEST_COND_COMPONENTS + version: 0 // 为了让组件能及时更新加入此变量 } }, computed: { // 之所以使用computed,是因为需要动态更新 conds: function () { return this.initConds - }, + } }, methods: { typeName: function (cond) { - let c = this.components.$find(function (k, v) { + let c = window.REQUEST_COND_COMPONENTS.$find(function (k, v) { return v.type == cond.type }) if (c != null) { return c.name; } return cond.param + " " + cond.operator + }, + notifyChange: function () { + this.version++ + let that = this + this.initConds.groups.forEach(function (group) { + group.conds.forEach(function (cond) { + cond.typeName = that.typeName(cond) + }) + }) } }, template: `
+ {{version}}
{{cond.param}} {{cond.operator}}
- {{typeName(cond)}}:
+ {{cond.typeName}}:
{{cond.value}}
diff --git a/web/public/js/conds/official.json b/web/public/js/conds/official.json
index 232970ad..2941ca09 100644
--- a/web/public/js/conds/official.json
+++ b/web/public/js/conds/official.json
@@ -4,6 +4,7 @@
"name": "URL扩展名",
"description": "根据URL中的文件路径扩展名进行过滤",
"component": "http-cond-url-extension",
+ "paramsTitle": "扩展名列表",
"isRequest": true
},
{
@@ -11,6 +12,7 @@
"name": "URL前缀",
"description": "根据URL中的文件路径前缀进行过滤",
"component": "http-cond-url-prefix",
+ "paramsTitle": "URL前缀",
"isRequest": true
},
{
@@ -18,6 +20,7 @@
"name": "URL精准匹配",
"description": "检查URL中的文件路径是否一致",
"component": "http-cond-url-eq",
+ "paramsTitle": "URL完整路径",
"isRequest": true
},
{
@@ -25,13 +28,31 @@
"name": "URL正则匹配",
"description": "使用正则表达式检查URL中的文件路径是否一致",
"component": "http-cond-url-regexp",
+ "paramsTitle": "正则表达式",
+ "isRequest": true
+ },
+ {
+ "type": "url-not-prefix",
+ "name": "排除:URL前缀",
+ "description": "根据URL中的文件路径前缀进行过滤",
+ "component": "http-cond-url-not-prefix",
+ "paramsTitle": "URL前缀",
+ "isRequest": true
+ },
+ {
+ "type": "url-not-eq",
+ "name": "排除:URL精准匹配",
+ "description": "检查URL中的文件路径是否一致",
+ "component": "http-cond-url-not-eq",
+ "paramsTitle": "URL完整路径",
"isRequest": true
},
{
"type": "url-not-regexp",
- "name": "排除URL正则匹配",
+ "name": "排除:URL正则匹配",
"description": "使用正则表达式检查URL中的文件路径是否一致,如果一致,则不匹配",
"component": "http-cond-url-not-regexp",
+ "paramsTitle": "正则表达式",
"isRequest": true
},
{
@@ -39,6 +60,7 @@
"name": "内容MimeType",
"description": "根据服务器返回的内容的MimeType进行过滤。注意:当用于缓存条件时,此条件需要结合别的请求条件使用。",
"component": "http-cond-mime-type",
+ "paramsTitle": "MimeType列表",
"isRequest": false
}
]
\ No newline at end of file
diff --git a/web/views/@default/servers/server/settings/cache/createPopup.html b/web/views/@default/servers/server/settings/cache/createPopup.html
index 2376848f..41f692a1 100644
--- a/web/views/@default/servers/server/settings/cache/createPopup.html
+++ b/web/views/@default/servers/server/settings/cache/createPopup.html
@@ -1,10 +1,11 @@
{$layout "layout_popup"}
- 添加缓存设置- +添加缓存设置+添加不缓存设置\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/createPopup.js b/web/views/@default/servers/server/settings/cache/createPopup.js index b208fb78..ffca28c1 100644 --- a/web/views/@default/servers/server/settings/cache/createPopup.js +++ b/web/views/@default/servers/server/settings/cache/createPopup.js @@ -4,5 +4,6 @@ Tea.context(function () { if (window.parent.UPDATING_CACHE_REF != null) { this.cacheRef = window.parent.UPDATING_CACHE_REF + this.isReverse = this.cacheRef.isReverse } }) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/conds/addCondPopup.html b/web/views/@default/servers/server/settings/conds/addCondPopup.html index e3129e2f..d51a05bb 100644 --- a/web/views/@default/servers/server/settings/conds/addCondPopup.html +++ b/web/views/@default/servers/server/settings/conds/addCondPopup.html @@ -7,7 +7,7 @@选择条件类型 |
- |
设置条件参数 |
+ {{paramsTitle}} |
{$ range .components}
<{$ .Component} v-if="condType == '{$ .Type}'" :v-cond="cond">{$ .Component}>
diff --git a/web/views/@default/servers/server/settings/conds/addCondPopup.js b/web/views/@default/servers/server/settings/conds/addCondPopup.js
index f4e99611..3afab029 100644
--- a/web/views/@default/servers/server/settings/conds/addCondPopup.js
+++ b/web/views/@default/servers/server/settings/conds/addCondPopup.js
@@ -1,6 +1,7 @@
Tea.context(function () {
this.isUpdating = false
this.cond = null
+ this.paramsTitle = ""
this.success = NotifyPopup
this.condType = (this.components.length > 0) ? this.components[0].type : ""
@@ -11,4 +12,20 @@ Tea.context(function () {
this.condType = window.parent.UPDATING_COND.type
this.cond = window.parent.UPDATING_COND
}
+
+ this.changeCondType = function () {
+ let that = this
+ let c = this.components.$find(function (k, v) {
+ return v.type == that.condType
+ })
+ if (c == null || c.paramsTitle.length == 0) {
+ that.paramsTitle = "条件参数"
+ } else {
+ that.paramsTitle = c.paramsTitle
+ }
+ }
+
+ this.$delay(function () {
+ this.changeCondType()
+ })
})
\ No newline at end of file
diff --git a/web/views/@default/servers/server/settings/conds/addGroupPopup.html b/web/views/@default/servers/server/settings/conds/addGroupPopup.html
index 400243f8..950362a0 100644
--- a/web/views/@default/servers/server/settings/conds/addGroupPopup.html
+++ b/web/views/@default/servers/server/settings/conds/addGroupPopup.html
@@ -1,7 +1,7 @@
{$layout "layout_popup"}
- | 添加条件- +添加条件分组+修改条件分组 |