diff --git a/internal/web/actions/default/servers/components/cache/init.go b/internal/web/actions/default/servers/components/cache/init.go index 4326ef57..79b33b9a 100644 --- a/internal/web/actions/default/servers/components/cache/init.go +++ b/internal/web/actions/default/servers/components/cache/init.go @@ -28,7 +28,7 @@ func init() { Post("/testWrite", new(TestWriteAction)). Get("/selectPopup", new(SelectPopupAction)). Post("/count", new(CountAction)). - + Post("/updateRefs", new(UpdateRefsAction)). EndAll() }) } diff --git a/internal/web/actions/default/servers/components/cache/updateRefs.go b/internal/web/actions/default/servers/components/cache/updateRefs.go new file mode 100644 index 00000000..c28ed145 --- /dev/null +++ b/internal/web/actions/default/servers/components/cache/updateRefs.go @@ -0,0 +1,35 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package cache + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" +) + +type UpdateRefsAction struct { + actionutils.ParentAction +} + +func (this *UpdateRefsAction) Init() { + this.Nav("", "", "") +} + +func (this *UpdateRefsAction) RunPost(params struct { + CachePolicyId int64 + RefsJSON []byte +}) { + // 修改缓存条件 + if params.CachePolicyId > 0 && len(params.RefsJSON) > 0 { + _, 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-config-box.js b/web/public/js/components/server/http-cache-config-box.js index 19d05519..1db206b9 100644 --- a/web/public/js/components/server/http-cache-config-box.js +++ b/web/public/js/components/server/http-cache-config-box.js @@ -56,7 +56,7 @@ Vue.component("http-cache-config-box", {

缓存条件

- +
` 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 d74233b1..42233c3d 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,5 +1,5 @@ Vue.component("http-cache-refs-config-box", { - props: ["v-cache-refs", "v-cache-config"], + props: ["v-cache-refs", "v-cache-config", "v-cache-policy-id"], mounted: function () { let that = this sortTable(function (ids) { @@ -12,6 +12,7 @@ Vue.component("http-cache-refs-config-box", { }) }) that.updateRefs(newRefs) + that.change() }) }, data: function () { @@ -73,6 +74,8 @@ Vue.component("http-cache-refs-config-box", { } else { that.refs.push(newRef) } + + that.change() } }) }, @@ -97,6 +100,8 @@ Vue.component("http-cache-refs-config-box", { // 通知子组件更新 that.$refs.cacheRef[index].notifyChange() + + that.change() } }) }, @@ -104,6 +109,7 @@ Vue.component("http-cache-refs-config-box", { let that = this teaweb.confirm("确定要删除此缓存设置吗?", function () { that.refs.$remove(index) + that.change() }) }, updateRefs: function (newRefs) { @@ -128,6 +134,17 @@ Vue.component("http-cache-refs-config-box", { return "周 " } return unit + }, + change: function () { + // 自动保存 + if (this.vCachePolicyId != null && this.vCachePolicyId > 0) { + Tea.action("/servers/components/cache/updateRefs") + .params({ + cachePolicyId: this.vCachePolicyId, + refsJSON: JSON.stringify(this.refs) + }) + .post() + } } }, template: `
diff --git a/web/views/@default/servers/components/cache/update.html b/web/views/@default/servers/components/cache/update.html index 752d76d3..45346c43 100644 --- a/web/views/@default/servers/components/cache/update.html +++ b/web/views/@default/servers/components/cache/update.html @@ -96,7 +96,7 @@

默认缓存条件

- + \ No newline at end of file