前端页面
This commit is contained in:
135
EdgeAdmin/web/views/@default/httpdns/sandbox/index.js
Normal file
135
EdgeAdmin/web/views/@default/httpdns/sandbox/index.js
Normal file
@@ -0,0 +1,135 @@
|
||||
Tea.context(function () {
|
||||
this.newRequest = function () {
|
||||
return {
|
||||
appId: "",
|
||||
domain: "",
|
||||
clientIp: "",
|
||||
qtype: "A"
|
||||
}
|
||||
}
|
||||
|
||||
this.request = this.newRequest()
|
||||
this.sdnsParams = [{name: "", value: ""}]
|
||||
|
||||
this.response = {
|
||||
hasResult: false,
|
||||
code: -1,
|
||||
message: "",
|
||||
data: null,
|
||||
requestId: "",
|
||||
resultRows: []
|
||||
}
|
||||
|
||||
this.isRequesting = false
|
||||
|
||||
if (typeof this.apps == "undefined") {
|
||||
this.apps = []
|
||||
}
|
||||
|
||||
this.addSDNSParam = function () {
|
||||
if (this.sdnsParams.length >= 10) {
|
||||
return
|
||||
}
|
||||
this.sdnsParams.push({name: "", value: ""})
|
||||
}
|
||||
|
||||
this.removeSDNSParam = function (index) {
|
||||
if (index < 0 || index >= this.sdnsParams.length) {
|
||||
return
|
||||
}
|
||||
this.sdnsParams.splice(index, 1)
|
||||
if (this.sdnsParams.length == 0) {
|
||||
this.sdnsParams.push({name: "", value: ""})
|
||||
}
|
||||
}
|
||||
|
||||
this.cleanSDNSParams = function () {
|
||||
let list = []
|
||||
this.sdnsParams.forEach(function (item) {
|
||||
let name = (item.name || "").trim()
|
||||
let value = (item.value || "").trim()
|
||||
if (name.length == 0 && value.length == 0) {
|
||||
return
|
||||
}
|
||||
list.push({
|
||||
name: name,
|
||||
value: value
|
||||
})
|
||||
})
|
||||
return list
|
||||
}
|
||||
|
||||
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 = []
|
||||
if (Array.isArray(data.ips)) {
|
||||
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.domain.length == 0) {
|
||||
teaweb.warn("请填写解析域名")
|
||||
return
|
||||
}
|
||||
|
||||
this.isRequesting = true
|
||||
this.response.hasResult = false
|
||||
|
||||
let payload = Object.assign({}, this.request)
|
||||
payload.sdnsParamsJSON = JSON.stringify(this.cleanSDNSParams())
|
||||
|
||||
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.sdnsParams = [{name: "", value: ""}]
|
||||
this.response = {
|
||||
hasResult: false,
|
||||
code: -1,
|
||||
message: "",
|
||||
data: null,
|
||||
requestId: "",
|
||||
resultRows: []
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user