Vue.component("http-cache-refs-config-box", { props: ["v-cache-refs", "v-cache-config", "v-cache-policy-id", "v-web-id", "v-max-bytes"], 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.updateRefs(newRefs) that.change() }) }, data: function () { let refs = this.vCacheRefs if (refs == null) { refs = [] } let maxBytes = this.vMaxBytes let id = 0 refs.forEach(function (ref) { // preset variables id++ ref.id = id ref.visible = true // check max size if (ref.maxSize != null && maxBytes != null && maxBytes.count > 0 && teaweb.compareSizeCapacity(ref.maxSize, maxBytes) > 0) { ref.overMaxSize = maxBytes } }) return { refs: refs, id: id // 用来对条件进行排序 } }, methods: { addRef: function (isReverse) { window.UPDATING_CACHE_REF = null let height = window.innerHeight if (height > 500) { height = 500 } let that = this teaweb.popup("/servers/server/settings/cache/createPopup?isReverse=" + (isReverse ? 1 : 0), { height: height + "px", callback: function (resp) { let newRef = resp.data.cacheRef if (newRef.conds == null) { return } that.id++ newRef.id = that.id if (newRef.isReverse) { let newRefs = [] let isAdded = false that.refs.forEach(function (v) { if (!v.isReverse && !isAdded) { newRefs.push(newRef) isAdded = true } newRefs.push(v) }) if (!isAdded) { newRefs.push(newRef) } that.updateRefs(newRefs) } else { that.refs.push(newRef) } // move to bottom var afterChangeCallback = function () { setTimeout(function () { let rightBox = document.querySelector(".right-box") if (rightBox != null) { rightBox.scrollTo(0, isReverse ? 0 : 100000) } }, 100) } that.change(afterChangeCallback) } }) }, updateRef: function (index, cacheRef) { window.UPDATING_CACHE_REF = teaweb.clone(cacheRef) let height = window.innerHeight if (height > 500) { height = 500 } let that = this teaweb.popup("/servers/server/settings/cache/createPopup", { height: height + "px", callback: function (resp) { resp.data.cacheRef.id = that.refs[index].id Vue.set(that.refs, index, resp.data.cacheRef) that.change() that.$refs.cacheRef[index].updateConds(resp.data.cacheRef.conds, resp.data.cacheRef.simpleCond) that.$refs.cacheRef[index].notifyChange() } }) }, disableRef: function (ref) { ref.isOn = false this.change() }, enableRef: function (ref) { ref.isOn = true this.change() }, removeRef: function (index) { let that = this teaweb.confirm("确定要删除此缓存设置吗?", function () { that.refs.$remove(index) that.change() }) }, updateRefs: function (newRefs) { this.refs = newRefs if (this.vCacheConfig != null) { this.vCacheConfig.cacheRefs = newRefs } }, timeUnitName: function (unit) { switch (unit) { case "ms": return "毫秒" case "second": return "秒" case "minute": return "分钟" case "hour": return "小时" case "day": return "天" case "week": return "周 " } return unit }, change: function (callback) { this.$forceUpdate() // 自动保存 if (this.vCachePolicyId != null && this.vCachePolicyId > 0) { // 缓存策略 Tea.action("/servers/components/cache/updateRefs") .params({ cachePolicyId: this.vCachePolicyId, refsJSON: JSON.stringify(this.refs) }) .post() } else if (this.vWebId != null && this.vWebId > 0) { // Server Web or Group Web Tea.action("/servers/server/settings/cache/updateRefs") .params({ webId: this.vWebId, refsJSON: JSON.stringify(this.refs) }) .success(function (resp) { if (resp.data.isUpdated) { teaweb.successToast("保存成功", null, function () { if (typeof callback == "function") { callback() } }) } }) .post() } }, search: function (keyword) { if (typeof keyword != "string") { keyword = "" } this.refs.forEach(function (ref) { if (keyword.length == 0) { ref.visible = true return } ref.visible = false // simple cond if (ref.simpleCond != null && typeof ref.simpleCond.value == "string" && teaweb.match(ref.simpleCond.value, keyword)) { ref.visible = true return } // composed conds if (ref.conds == null || ref.conds.groups == null || ref.conds.groups.length == 0) { return } ref.conds.groups.forEach(function (group) { if (group.conds != null) { group.conds.forEach(function (cond) { if (typeof cond.value == "string" && teaweb.match(cond.value, keyword)) { ref.visible = true } }) } }) }) this.$forceUpdate() } }, template: `
暂时还没有缓存条件。
| 缓存条件 | 缓存时间 | 操作 | |
|---|---|---|---|
|
|
{{cacheRef.life.count}} {{timeUnitName(cacheRef.life.unit)}} 不缓存 | 修改 暂停恢复 删除 |
所有条件匹配顺序为从上到下,可以拖动左侧的排序。服务设置的优先级比全局缓存策略设置的优先级要高。
+添加不缓存条件