Vue.component("health-check-config-box", { props: ["v-health-check-config"], data: function () { let healthCheckConfig = this.vHealthCheckConfig let urlProtocol = "http" let urlPort = "" let urlRequestURI = "/" if (healthCheckConfig == null) { healthCheckConfig = { isOn: false, url: "", interval: {count: 60, unit: "second"}, statusCodes: [200], timeout: {count: 10, unit: "second"}, countTries: 3, tryDelay: {count: 100, unit: "ms"} } let that = this setTimeout(function () { that.changeURL() }, 500) } else { try { let url = new URL(healthCheckConfig.url) urlProtocol = url.protocol.substring(0, url.protocol.length - 1) urlPort = url.port urlRequestURI = url.pathname if (url.search.length > 0) { urlRequestURI += url.search } } catch (e) { } if (healthCheckConfig.statusCodes == null) { healthCheckConfig.statusCodes = [200] } if (healthCheckConfig.interval == null) { healthCheckConfig.interval = {count: 60, unit: "second"} } if (healthCheckConfig.timeout == null) { healthCheckConfig.timeout = {count: 10, unit: "second"} } if (healthCheckConfig.tryDelay == null) { healthCheckConfig.tryDelay = {count: 100, unit: "ms"} } } return { healthCheck: healthCheckConfig, advancedVisible: false, urlProtocol: urlProtocol, urlPort: urlPort, urlRequestURI: urlRequestURI } }, watch: { urlRequestURI: function () { if (this.urlRequestURI.length > 0 && this.urlRequestURI[0] != "/") { this.urlRequestURI = "/" + this.urlRequestURI } this.changeURL() }, urlPort: function (v) { let port = parseInt(v) if (!isNaN(port)) { this.urlPort = port.toString() } else { this.urlPort = "" } this.changeURL() }, urlProtocol: function () { this.changeURL() }, "healthCheck.countTries": function (v) { let count = parseInt(v) if (!isNaN(count)) { this.healthCheck.countTries = count } else { this.healthCheck.countTries = 0 } } }, methods: { showAdvanced: function () { this.advancedVisible = !this.advancedVisible }, changeURL: function () { this.healthCheck.url = this.urlProtocol + "://${host}" + ((this.urlPort.length > 0) ? ":" + this.urlPort : "") + this.urlRequestURI }, changeStatus: function (values) { this.healthCheck.statusCodes = values.$map(function (k, v) { let status = parseInt(v) if (isNaN(status)) { return 0 } else { return status } }) } }, template: `
| 是否启用 |
|
| URL * |
\${host}
:
拼接后的URL: |
| 检测时间间隔 |
|
| 允许的状态码 |
|
| 超时时间 |
|
| 连续尝试次数 | |
| 每次尝试间隔 |
|