72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
Tea.context(function () {
|
||
this.ip = ""
|
||
this.result = {
|
||
isDone: false
|
||
}
|
||
// 如果数据还没有从后端传入(window.TEA.ACTION.data),则设置默认值
|
||
if (typeof this.maxMindCityExists === "undefined") {
|
||
this.maxMindCityExists = false
|
||
}
|
||
if (typeof this.maxMindASNExists === "undefined") {
|
||
this.maxMindASNExists = false
|
||
}
|
||
if (typeof this.usingMaxMind === "undefined") {
|
||
this.usingMaxMind = false
|
||
}
|
||
if (typeof this.usingEmbeddedMaxMind === "undefined") {
|
||
this.usingEmbeddedMaxMind = false
|
||
}
|
||
|
||
this.$delay(function () {
|
||
if (this.$refs.focus) {
|
||
this.$refs.focus.focus()
|
||
}
|
||
|
||
// 确保表单使用AJAX提交
|
||
var form = this.$el.querySelector('form')
|
||
if (form) {
|
||
form.addEventListener('submit', function (e) {
|
||
e.preventDefault()
|
||
e.stopPropagation()
|
||
|
||
// 使用TeaGo的AJAX提交
|
||
Tea.runActionOn(form)
|
||
})
|
||
}
|
||
})
|
||
|
||
// 如果数据还没有从后端传入,则通过 AJAX 获取(作为后备方案)
|
||
if (this.maxMindCityExists === false && this.maxMindASNExists === false && this.usingMaxMind === false) {
|
||
this.$get("/settings/ip-library/library/test")
|
||
.success(function (resp) {
|
||
this.maxMindCityExists = resp.data.maxMindCityExists || false
|
||
this.maxMindASNExists = resp.data.maxMindASNExists || false
|
||
this.usingMaxMind = resp.data.usingMaxMind || false
|
||
this.usingEmbeddedMaxMind = resp.data.usingEmbeddedMaxMind || false
|
||
})
|
||
}
|
||
|
||
this.success = function (resp) {
|
||
if (!resp || !resp.data) {
|
||
return
|
||
}
|
||
|
||
this.result = resp.data.result || {
|
||
isDone: true,
|
||
isOk: false
|
||
}
|
||
this.maxMindCityExists = resp.data.maxMindCityExists || false
|
||
this.maxMindASNExists = resp.data.maxMindASNExists || false
|
||
this.usingMaxMind = resp.data.usingMaxMind || false
|
||
this.usingEmbeddedMaxMind = resp.data.usingEmbeddedMaxMind || false
|
||
|
||
// 滚动到结果区域
|
||
this.$nextTick(function () {
|
||
if (this.$refs.resultBox) {
|
||
this.$refs.resultBox.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||
}
|
||
})
|
||
}
|
||
})
|
||
|