Files
waf-platform/EdgeAdmin/web/views/@default/db/clickHouse.js
2026-02-13 22:36:17 +08:00

77 lines
2.0 KiB
JavaScript

Tea.context(function () {
var config = this.config || {}
this.form = {
host: config.host || "",
scheme: config.scheme || "https",
port: config.port > 0 ? config.port : 8443,
user: config.user || "",
password: "",
database: config.database || "default",
}
this.isTesting = false
this.testResult = ""
this.testOk = false
// 页面加载时的连接状态(后端自动检测)
this.connStatus = this.connStatus || "unconfigured"
this.connError = this.connError || ""
this.success = function () {
teaweb.success("保存成功")
}
this.onSubmit = function (e) {
e.preventDefault()
e.stopPropagation()
Tea.action("$").post().form(e.target).success(function () {
Tea.Vue.success()
})
}
this.testConnection = function () {
var that = Tea.Vue
that.isTesting = true
that.testResult = ""
var form = document.querySelector("form")
var fd = new FormData(form)
fd.set("host", that.form.host || "")
fd.set("scheme", that.form.scheme || "https")
fd.set("port", String(that.form.port > 0 ? that.form.port : 8443))
fd.set("user", that.form.user || "")
fd.set("password", that.form.password || "")
fd.set("database", that.form.database || "default")
var xhr = new XMLHttpRequest()
xhr.open("POST", Tea.url("/db/testClickhouse"), true)
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest")
xhr.timeout = 10000
xhr.onload = function () {
that.isTesting = false
try {
var resp = JSON.parse(xhr.responseText)
if (resp.code === 200) {
that.testOk = true
that.testResult = "✅ 连接成功"
} else {
that.testOk = false
that.testResult = "❌ " + (resp.message || "连接失败")
}
} catch (e) {
that.testOk = false
that.testResult = "❌ 响应解析失败"
}
}
xhr.onerror = function () {
that.isTesting = false
that.testOk = false
that.testResult = "❌ 网络请求失败"
}
xhr.ontimeout = function () {
that.isTesting = false
that.testOk = false
that.testResult = "❌ 请求超时"
}
xhr.send(fd)
}
})