Files
EdgeAdmin/web/public/js/components/server/http-request-limit-config-box.js
2021-12-19 18:56:09 +08:00

104 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 请求限制
Vue.component("http-request-limit-config-box", {
props: ["v-request-limit-config", "v-is-group", "v-is-location"],
data: function () {
let config = this.vRequestLimitConfig
if (config == null) {
config = {
isPrior: false,
isOn: false,
maxConns: 0,
maxConnsPerIP: 0,
maxBodySize: {
count: -1,
unit: "kb"
},
outBandwidthPerConn: {
count: -1,
unit: "kb"
}
}
}
return {
config: config,
maxConns: config.maxConns,
maxConnsPerIP: config.maxConnsPerIP
}
},
watch: {
maxConns: function (v) {
let conns = parseInt(v, 10)
if (isNaN(conns)) {
this.config.maxConns = 0
return
}
if (conns < 0) {
this.config.maxConns = 0
} else {
this.config.maxConns = conns
}
},
maxConnsPerIP: function (v) {
let conns = parseInt(v, 10)
if (isNaN(conns)) {
this.config.maxConnsPerIP = 0
return
}
if (conns < 0) {
this.config.maxConnsPerIP = 0
} else {
this.config.maxConnsPerIP = conns
}
}
},
methods: {
isOn: function () {
return ((!this.vIsLocation && !this.vIsGroup) || this.config.isPrior) && this.config.isOn
}
},
template: `<div>
<input type="hidden" name="requestLimitJSON" :value="JSON.stringify(config)"/>
<table class="ui table selectable definition">
<prior-checkbox :v-config="config" v-if="vIsLocation || vIsGroup"></prior-checkbox>
<tbody v-show="(!vIsLocation && !vIsGroup) || config.isPrior">
<tr>
<td class="title">是否启用</td>
<td>
<checkbox v-model="config.isOn"></checkbox>
</td>
</tr>
</tbody>
<tbody v-show="isOn()">
<tr>
<td>最大并发连接数</td>
<td>
<input type="text" maxlength="6" v-model="maxConns"/>
<p class="comment">当前服务最大并发连接数。为0表示不限制。</p>
</td>
</tr>
<tr>
<td>单IP最大并发连接数</td>
<td>
<input type="text" maxlength="6" v-model="maxConnsPerIP"/>
<p class="comment">单IP最大连接数统计单个IP总连接数时不区分服务。为0表示不限制。</p>
</td>
</tr>
<tr>
<td>单连接带宽限制</td>
<td>
<size-capacity-box :v-value="config.outBandwidthPerConn" :v-supported-units="['byte', 'kb', 'mb']"></size-capacity-box>
<p class="comment">客户端单个请求每秒可以读取的下行流量。</p>
</td>
</tr>
<tr>
<td>单请求最大尺寸</td>
<td>
<size-capacity-box :v-value="config.maxBodySize" :v-supported-units="['byte', 'kb', 'mb', 'gb']"></size-capacity-box>
<p class="comment">单个请求能发送的最大内容尺寸。</p>
</td>
</tr>
</tbody>
</table>
<div class="margin"></div>
</div>`
})