From f738ba915296c6862e205782d7c315770fcee338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 24 May 2021 09:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=94=AF=E6=8C=81=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servers/components/cache/update.go | 32 +++++- .../components/server/http-cache-refs-box.js | 58 ++++++++++ .../server/http-cache-refs-config-box.js | 105 ++++++++++++++++++ .../servers/components/cache/policy.html | 6 + .../servers/components/cache/update.html | 4 + 5 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 web/public/js/components/server/http-cache-refs-box.js create mode 100644 web/public/js/components/server/http-cache-refs-config-box.js diff --git a/internal/web/actions/default/servers/components/cache/update.go b/internal/web/actions/default/servers/components/cache/update.go index a9c049eb..0de9d202 100644 --- a/internal/web/actions/default/servers/components/cache/update.go +++ b/internal/web/actions/default/servers/components/cache/update.go @@ -63,8 +63,13 @@ func (this *UpdateAction) RunPost(params struct { Description string IsOn bool + RefsJSON []byte + Must *actions.Must }) { + // 创建日志 + defer this.CreateLog(oplogs.LevelInfo, "修改缓存策略:%d", params.CachePolicyId) + params.Must. Field("name", params.Name). Require("请输入策略名称") @@ -104,6 +109,22 @@ func (this *UpdateAction) RunPost(params struct { this.ErrorPage(err) return } + + // 校验缓存条件 + refs := []*serverconfigs.HTTPCacheRef{} + if len(params.RefsJSON) > 0 { + err = json.Unmarshal(params.RefsJSON, &refs) + if err != nil { + this.Fail("缓存条件解析失败:" + err.Error()) + } + for _, ref := range refs { + err = ref.Init() + if err != nil { + this.Fail("缓存条件校验失败:" + err.Error()) + } + } + } + _, err = this.RPC().HTTPCachePolicyRPC().UpdateHTTPCachePolicy(this.AdminContext(), &pb.UpdateHTTPCachePolicyRequest{ HttpCachePolicyId: params.CachePolicyId, IsOn: params.IsOn, @@ -120,8 +141,15 @@ func (this *UpdateAction) RunPost(params struct { return } - // 创建日志 - defer this.CreateLog(oplogs.LevelInfo, "修改缓存策略:%d", params.CachePolicyId) + // 修改缓存条件 + _, err = this.RPC().HTTPCachePolicyRPC().UpdateHTTPCachePolicyRefs(this.AdminContext(), &pb.UpdateHTTPCachePolicyRefsRequest{ + HttpCachePolicyId: params.CachePolicyId, + RefsJSON: params.RefsJSON, + }) + if err != nil { + this.ErrorPage(err) + return + } this.Success() } diff --git a/web/public/js/components/server/http-cache-refs-box.js b/web/public/js/components/server/http-cache-refs-box.js new file mode 100644 index 00000000..f5ed6b20 --- /dev/null +++ b/web/public/js/components/server/http-cache-refs-box.js @@ -0,0 +1,58 @@ +Vue.component("http-cache-refs-box", { + props: ["v-cache-refs"], + data: function () { + let refs = this.vCacheRefs + if (refs == null) { + refs = [] + } + return { + refs: refs + } + }, + methods: { + 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 + } + }, + template: `
+ + +

暂时还没有缓存条件。

+
+ + + + + + + + + + + + + +
缓存条件缓存时间操作
+ + {{cacheRef.life.count}} {{timeUnitName(cacheRef.life.unit)}} + 修改   + 删除 +
+
+
+
` +}) \ No newline at end of file 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 new file mode 100644 index 00000000..13e462d0 --- /dev/null +++ b/web/public/js/components/server/http-cache-refs-config-box.js @@ -0,0 +1,105 @@ +Vue.component("http-cache-refs-config-box", { + props: ["v-cache-refs"], + data: function () { + let refs = this.vCacheRefs + if (refs == null) { + refs = [] + } + return { + refs: refs + } + }, + methods: { + addRef: function () { + window.UPDATING_CACHE_REF = null + + let width = window.innerWidth + if (width > 1024) { + width = 1024 + } + let height = window.innerHeight + if (height > 500) { + height = 500 + } + let that = this + teaweb.popup("/servers/server/settings/cache/createPopup", { + width: width + "px", + height: height + "px", + callback: function (resp) { + that.refs.push(resp.data.cacheRef) + } + }) + }, + updateRef: function (index, cacheRef) { + window.UPDATING_CACHE_REF = cacheRef + + let width = window.innerWidth + if (width > 1024) { + width = 1024 + } + let height = window.innerHeight + if (height > 500) { + height = 500 + } + let that = this + teaweb.popup("/servers/server/settings/cache/createPopup", { + width: width + "px", + height: height + "px", + callback: function (resp) { + Vue.set(that.refs, index, resp.data.cacheRef) + } + }) + }, + removeRef: function (index) { + let that = this + teaweb.confirm("确定要删除此缓存设置吗?", function () { + that.refs.$remove(index) + }) + }, + 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 + } + }, + template: `
+ + +
+ + + + + + + + + + + + + +
缓存条件缓存时间操作
+ + {{cacheRef.life.count}} {{timeUnitName(cacheRef.life.unit)}} + 修改   + 删除 +
+ + +
+
+
` +}) \ No newline at end of file diff --git a/web/views/@default/servers/components/cache/policy.html b/web/views/@default/servers/components/cache/policy.html index 5a99575b..4720942d 100644 --- a/web/views/@default/servers/components/cache/policy.html +++ b/web/views/@default/servers/components/cache/policy.html @@ -80,6 +80,12 @@ + + +

默认缓存条件

+ + +

使用此策略的集群

暂时还没有集群使用此策略。

diff --git a/web/views/@default/servers/components/cache/update.html b/web/views/@default/servers/components/cache/update.html index 054ba761..752d76d3 100644 --- a/web/views/@default/servers/components/cache/update.html +++ b/web/views/@default/servers/components/cache/update.html @@ -94,5 +94,9 @@
+ +

默认缓存条件

+ + \ No newline at end of file