Files
EdgeAdmin/web/public/js/components/server/http-cache-config-box.js

233 lines
8.4 KiB
JavaScript
Raw Normal View History

2020-09-20 16:28:16 +08:00
Vue.component("http-cache-config-box", {
props: ["v-cache-config", "v-is-location", "v-is-group", "v-cache-policy", "v-web-id"],
2020-09-20 16:28:16 +08:00
data: function () {
let cacheConfig = this.vCacheConfig
if (cacheConfig == null) {
cacheConfig = {
2020-09-23 18:43:38 +08:00
isPrior: false,
2020-09-20 16:28:16 +08:00
isOn: false,
addStatusHeader: true,
2021-12-02 09:54:31 +08:00
addAgeHeader: false,
enableCacheControlMaxAge: false,
2021-10-17 20:22:57 +08:00
cacheRefs: [],
purgeIsOn: false,
purgeKey: "",
disablePolicyRefs: false
2020-09-20 16:28:16 +08:00
}
}
if (cacheConfig.cacheRefs == null) {
cacheConfig.cacheRefs = []
}
let maxBytes = null
if (this.vCachePolicy != null && this.vCachePolicy.maxBytes != null) {
maxBytes = this.vCachePolicy.maxBytes
}
// key
if (cacheConfig.key == null) {
// use Vue.set to activate vue events
Vue.set(cacheConfig, "key", {
isOn: false,
scheme: "https",
host: ""
})
}
2020-09-20 16:28:16 +08:00
return {
2021-11-14 16:21:04 +08:00
cacheConfig: cacheConfig,
moreOptionsVisible: false,
enablePolicyRefs: !cacheConfig.disablePolicyRefs,
maxBytes: maxBytes,
searchBoxVisible: false,
searchKeyword: "",
keyOptionsVisible: false
}
},
watch: {
enablePolicyRefs: function (v) {
this.cacheConfig.disablePolicyRefs = !v
},
searchKeyword: function (v) {
this.$refs.cacheRefsConfigBoxRef.search(v)
2020-09-20 16:28:16 +08:00
}
},
2020-09-20 20:12:43 +08:00
methods: {
2020-10-04 20:38:27 +08:00
isOn: function () {
return ((!this.vIsLocation && !this.vIsGroup) || this.cacheConfig.isPrior) && this.cacheConfig.isOn
2021-10-17 20:22:57 +08:00
},
2021-12-16 17:27:09 +08:00
isPlus: function () {
return Tea.Vue.teaIsPlus
},
2021-10-17 20:22:57 +08:00
generatePurgeKey: function () {
let r = Math.random().toString() + Math.random().toString()
let s = r.replace(/0\./g, "")
.replace(/\./g, "")
let result = ""
for (let i = 0; i < s.length; i++) {
result += String.fromCharCode(parseInt(s.substring(i, i + 1)) + ((Math.random() < 0.5) ? "a" : "A").charCodeAt(0))
}
this.cacheConfig.purgeKey = result
2021-11-14 16:21:04 +08:00
},
showMoreOptions: function () {
this.moreOptionsVisible = !this.moreOptionsVisible
2021-12-16 17:27:09 +08:00
},
changeStale: function (stale) {
this.cacheConfig.stale = stale
},
showSearchBox: function () {
this.searchBoxVisible = !this.searchBoxVisible
if (this.searchBoxVisible) {
let that = this
setTimeout(function () {
that.$refs.searchBox.focus()
})
} else {
this.searchKeyword = ""
}
2020-09-20 20:12:43 +08:00
}
},
2020-09-20 16:28:16 +08:00
template: `<div>
<input type="hidden" name="cacheJSON" :value="JSON.stringify(cacheConfig)"/>
2023-03-05 16:48:01 +08:00
<table class="ui table definition selectable" v-show="!vIsGroup">
<tr>
<td class="title">全局缓存策略</td>
<td>
<div v-if="vCachePolicy != null">{{vCachePolicy.name}} <link-icon :href="'/servers/components/cache/policy?cachePolicyId=' + vCachePolicy.id"></link-icon>
<p class="comment">使用当前网站所在集群的设置</p>
2023-03-05 16:48:01 +08:00
</div>
<span v-else class="red">当前集群没有设置缓存策略当前配置无法生效</span>
</td>
</tr>
</table>
2020-09-20 16:28:16 +08:00
<table class="ui table definition selectable">
<prior-checkbox :v-config="cacheConfig" v-if="vIsLocation || vIsGroup"></prior-checkbox>
<tbody v-show="(!vIsLocation && !vIsGroup) || cacheConfig.isPrior">
<tr>
2022-03-16 17:07:46 +08:00
<td class="title">启用缓存</td>
2020-09-23 18:43:38 +08:00
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="cacheConfig.isOn"/>
<label></label>
</div>
</td>
</tr>
2020-09-20 16:28:16 +08:00
</tbody>
<tbody v-show="isOn() && !vIsGroup">
<tr>
<td>缓存主域名</td>
<td>
<div v-show="!cacheConfig.key.isOn">默认 &nbsp; <a href="" @click.prevent="keyOptionsVisible = !keyOptionsVisible"><span class="small">[修改]</span></a></div>
<div v-show="cacheConfig.key.isOn">使用主域名{{cacheConfig.key.scheme}}://{{cacheConfig.key.host}} &nbsp; <a href="" @click.prevent="keyOptionsVisible = !keyOptionsVisible"><span class="small">[修改]</span></a></div>
<div v-show="keyOptionsVisible" style="margin-top: 1em">
<div class="ui divider"></div>
<table class="ui table definition">
<tr>
<td class="title">启用主域名</td>
<td><checkbox v-model="cacheConfig.key.isOn"></checkbox>
<p class="comment">启用主域名后所有缓存键值中的协议和域名部分都会修改为主域名用来实现缓存不区分域名</p>
</td>
</tr>
<tr v-show="cacheConfig.key.isOn">
<td>主域名 *</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<select class="ui dropdown" v-model="cacheConfig.key.scheme">
<option value="https">https://</option>
<option value="http">http://</option>
</select>
</div>
<div class="ui field">
<input type="text" v-model="cacheConfig.key.host" placeholder="example.com" @keyup.enter="keyOptionsVisible = false" @keypress.enter.prevent="1"/>
</div>
</div>
<p class="comment">此域名<strong>必须</strong>使</p>
</td>
</tr>
</table>
<button class="ui button tiny" type="button" @click.prevent="keyOptionsVisible = false">完成</button>
</div>
</td>
</tr>
</tbody>
<tbody v-show="isOn()">
2021-11-14 16:21:04 +08:00
<tr>
<td colspan="2">
<a href="" @click.prevent="showMoreOptions"><span v-if="moreOptionsVisible">收起选项</span><span v-else></span><i class="icon angle" :class="{up: moreOptionsVisible, down:!moreOptionsVisible}"></i></a>
</td>
</tr>
</tbody>
<tbody v-show="isOn() && moreOptionsVisible">
2022-02-27 21:20:49 +08:00
<tr>
<td>使用默认缓存条件</td>
<td>
<checkbox v-model="enablePolicyRefs"></checkbox>
2023-03-05 16:48:01 +08:00
<p class="comment">选中后使用系统全局缓存策略中已经定义的默认缓存条件</p>
2022-02-27 21:20:49 +08:00
</td>
</tr>
<tr>
2023-11-22 19:02:18 +08:00
<td>添加X-Cache报头</td>
<td>
<checkbox v-model="cacheConfig.addStatusHeader"></checkbox>
<p class="comment">选中后自动在响应报头中增加<code-label>X-Cache: BYPASS|MISS|HIT|PURGE</code-label>X-Cache</p>
2021-12-02 09:54:31 +08:00
</td>
</tr>
<tr>
<td>添加Age Header</td>
<td>
<checkbox v-model="cacheConfig.addAgeHeader"></checkbox>
<p class="comment">选中后自动在响应Header中增加<code-label>Age: [存活时间秒数]</code-label></p>
</td>
</tr>
<tr>
<td>支持源站控制有效时间</td>
<td>
<checkbox v-model="cacheConfig.enableCacheControlMaxAge"></checkbox>
<p class="comment">选中后表示支持源站在Header中设置的<code-label>Cache-Control: max-age=[有效时间秒数]</code-label></p>
</td>
</tr>
2021-10-17 20:22:57 +08:00
<tr>
2021-12-16 17:27:09 +08:00
<td class="color-border">允许PURGE</td>
2021-10-17 20:22:57 +08:00
<td>
<checkbox v-model="cacheConfig.purgeIsOn"></checkbox>
<p class="comment">允许使用PURGE方法清除某个URL缓存</p>
</td>
</tr>
<tr v-show="cacheConfig.purgeIsOn">
2021-12-16 17:27:09 +08:00
<td class="color-border">PURGE Key *</td>
2021-10-17 20:22:57 +08:00
<td>
<input type="text" maxlength="200" v-model="cacheConfig.purgeKey"/>
<p class="comment"><a href="" @click.prevent="generatePurgeKey">[随机生成]</a>PURGE<code-label>X-Edge-Purge-Key: {{cacheConfig.purgeKey}}</code-label> Header线</p>
2021-10-17 20:22:57 +08:00
</td>
</tr>
</tbody>
2020-09-20 16:28:16 +08:00
</table>
2020-10-04 20:38:27 +08:00
2021-12-16 17:27:09 +08:00
<div v-if="isOn() && moreOptionsVisible && isPlus()">
2021-12-17 14:17:48 +08:00
<h4>过时缓存策略</h4>
2021-12-16 17:27:09 +08:00
<http-cache-stale-config :v-cache-stale-config="cacheConfig.stale" @change="changeStale"></http-cache-stale-config>
</div>
<div v-show="isOn()">
<submit-btn></submit-btn>
<div class="ui divider"></div>
</div>
2021-12-16 17:27:09 +08:00
<div v-show="isOn()" style="margin-top: 1em">
<h4 style="position: relative">缓存条件 &nbsp; <a href="" style="font-size: 0.8em" @click.prevent="$refs.cacheRefsConfigBoxRef.addRef(false)">[添加]</a> &nbsp; <a href="" style="font-size: 0.8em" @click.prevent="showSearchBox" v-show="!searchBoxVisible">[]</a>
2023-08-07 17:16:55 +08:00
<div class="ui input small right labeled" style="position: absolute; top: -0.4em; margin-left: 0.5em; zoom: 0.9" v-show="searchBoxVisible">
<input type="text" placeholder="搜索..." ref="searchBox" @keypress.enter.prevent="1" @keydown.esc="showSearchBox" v-model="searchKeyword" size="20"/>
<a href="" class="ui label blue" @click.prevent="showSearchBox"><i class="icon remove small"></i></a>
</div>
</h4>
<http-cache-refs-config-box ref="cacheRefsConfigBoxRef" :v-cache-config="cacheConfig" :v-cache-refs="cacheConfig.cacheRefs" :v-web-id="vWebId" :v-max-bytes="maxBytes"></http-cache-refs-config-box>
2020-10-04 20:38:27 +08:00
</div>
2020-09-20 16:28:16 +08:00
<div class="margin"></div>
</div>`
})