带阿里标识的版本
This commit is contained in:
161
EdgeUser/web/views/@default/httpdns/sandbox/index.js
Normal file
161
EdgeUser/web/views/@default/httpdns/sandbox/index.js
Normal file
@@ -0,0 +1,161 @@
|
||||
Tea.context(function () {
|
||||
this.newRequest = function () {
|
||||
return {
|
||||
appId: "",
|
||||
clusterId: "",
|
||||
domain: "",
|
||||
clientIp: "",
|
||||
qtype: "A"
|
||||
}
|
||||
}
|
||||
|
||||
this.request = this.newRequest()
|
||||
|
||||
this.response = {
|
||||
hasResult: false,
|
||||
code: -1,
|
||||
message: "",
|
||||
data: null,
|
||||
requestId: "",
|
||||
resultRows: []
|
||||
}
|
||||
|
||||
this.isRequesting = false
|
||||
this.currentDomains = []
|
||||
this.currentClusters = []
|
||||
|
||||
if (typeof this.apps === "undefined" || this.apps == null) {
|
||||
this.apps = []
|
||||
}
|
||||
if (typeof this.clusters === "undefined" || this.clusters == null) {
|
||||
this.clusters = []
|
||||
}
|
||||
|
||||
this.onAppChanged = function () {
|
||||
let selectedApp = null
|
||||
for (let i = 0; i < this.apps.length; i++) {
|
||||
if (this.apps[i].appId === this.request.appId) {
|
||||
selectedApp = this.apps[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedApp == null) {
|
||||
this.currentDomains = []
|
||||
this.currentClusters = []
|
||||
this.request.domain = ""
|
||||
this.request.clusterId = ""
|
||||
return
|
||||
}
|
||||
|
||||
this.currentDomains = Array.isArray(selectedApp.domains) ? selectedApp.domains : []
|
||||
|
||||
if (this.currentDomains.length > 0) {
|
||||
if (this.currentDomains.indexOf(this.request.domain) < 0) {
|
||||
this.request.domain = this.currentDomains[0]
|
||||
}
|
||||
} else {
|
||||
this.request.domain = ""
|
||||
}
|
||||
|
||||
let primaryClusterId = (typeof selectedApp.primaryClusterId !== "undefined" && selectedApp.primaryClusterId !== null) ? Number(selectedApp.primaryClusterId) : 0
|
||||
let backupClusterId = (typeof selectedApp.backupClusterId !== "undefined" && selectedApp.backupClusterId !== null) ? Number(selectedApp.backupClusterId) : 0
|
||||
|
||||
let allowed = []
|
||||
for (let i = 0; i < this.clusters.length; i++) {
|
||||
let cluster = this.clusters[i]
|
||||
let clusterId = Number(cluster.id)
|
||||
if (clusterId <= 0) {
|
||||
continue
|
||||
}
|
||||
if (clusterId === primaryClusterId || clusterId === backupClusterId) {
|
||||
allowed.push(cluster)
|
||||
}
|
||||
}
|
||||
this.currentClusters = allowed
|
||||
|
||||
if (allowed.length > 0) {
|
||||
if (!allowed.some((c) => String(c.id) === String(this.request.clusterId))) {
|
||||
this.request.clusterId = String(allowed[0].id)
|
||||
}
|
||||
} else {
|
||||
this.request.clusterId = ""
|
||||
}
|
||||
}
|
||||
|
||||
this.normalizeResultRows = function (data) {
|
||||
if (typeof data === "undefined" || data == null) {
|
||||
return []
|
||||
}
|
||||
|
||||
if (Array.isArray(data.records) && data.records.length > 0) {
|
||||
return data.records
|
||||
}
|
||||
|
||||
let rows = []
|
||||
let ips = Array.isArray(data.ips) ? data.ips : []
|
||||
let domain = this.request.domain
|
||||
let qtype = this.request.qtype
|
||||
let ttl = data.ttl || 0
|
||||
let region = data.client_region || "-"
|
||||
let line = data.line_name || "-"
|
||||
|
||||
ips.forEach(function (ip) {
|
||||
rows.push({
|
||||
domain: domain,
|
||||
type: qtype,
|
||||
ip: ip,
|
||||
ttl: ttl,
|
||||
region: region,
|
||||
line: line
|
||||
})
|
||||
})
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
this.sendTestRequest = function () {
|
||||
if (this.request.appId.length === 0) {
|
||||
teaweb.warn("请选择目标应用")
|
||||
return
|
||||
}
|
||||
if (this.request.clusterId.length === 0) {
|
||||
teaweb.warn("当前应用未绑定可用的 HTTPDNS 服务域名,请先在应用设置中配置主/备集群")
|
||||
return
|
||||
}
|
||||
if (this.request.domain.length === 0) {
|
||||
teaweb.warn("请选择要解析的域名")
|
||||
return
|
||||
}
|
||||
|
||||
this.isRequesting = true
|
||||
this.response.hasResult = false
|
||||
|
||||
let payload = Object.assign({}, this.request)
|
||||
|
||||
this.$post("/httpdns/sandbox/test")
|
||||
.params(payload)
|
||||
.success(function (resp) {
|
||||
this.response = resp.data.result
|
||||
this.response.hasResult = true
|
||||
this.response.resultRows = this.normalizeResultRows(this.response.data)
|
||||
})
|
||||
.done(function () {
|
||||
this.isRequesting = false
|
||||
})
|
||||
}
|
||||
|
||||
this.resetForm = function () {
|
||||
this.request = this.newRequest()
|
||||
this.currentDomains = []
|
||||
this.currentClusters = []
|
||||
this.response = {
|
||||
hasResult: false,
|
||||
code: -1,
|
||||
message: "",
|
||||
data: null,
|
||||
requestId: "",
|
||||
resultRows: []
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user