缓存策略里的默认缓存条件增加、修改或者删除后自动保存

This commit is contained in:
GoEdgeLab
2021-08-29 09:40:21 +08:00
parent e95cbdb707
commit 160bdc2451
5 changed files with 56 additions and 4 deletions

View File

@@ -28,7 +28,7 @@ func init() {
Post("/testWrite", new(TestWriteAction)).
Get("/selectPopup", new(SelectPopupAction)).
Post("/count", new(CountAction)).
Post("/updateRefs", new(UpdateRefsAction)).
EndAll()
})
}

View File

@@ -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()
}

View File

@@ -56,7 +56,7 @@ Vue.component("http-cache-config-box", {
<div v-show="isOn()">
<h4>缓存条件</h4>
<http-cache-refs-config-box :v-cache-config="cacheConfig" :v-cache-refs="cacheConfig.cacheRefs"></http-cache-refs-config-box>
<http-cache-refs-config-box :v-cache-config="cacheConfig" :v-cache-refs="cacheConfig.cacheRefs" ></http-cache-refs-config-box>
</div>
<div class="margin"></div>
</div>`

View File

@@ -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: `<div>

View File

@@ -96,7 +96,7 @@
</table>
<h4>默认缓存条件</h4>
<http-cache-refs-config-box :v-cache-refs="cachePolicy.cacheRefs"></http-cache-refs-config-box>
<http-cache-refs-config-box :v-cache-refs="cachePolicy.cacheRefs" :v-cache-policy-id="cachePolicy.id"></http-cache-refs-config-box>
<submit-btn></submit-btn>
</form>