IP {{$t('ping.total')}}:{{total}}
- {{$t('ping.done')}}:{{tableData.length}}
- {{$t('ping.progress')}}:{{parseInt(tableData.length/total*100)}}%
+ {{$t('ping.done')}}:{{done}}
+ {{$t('ping.progress')}}:{{process}}%
{
- // this.tid = response.data
- this.tid = 111
- this.total = 30
+ // 清空上一次任务的数据
+ this.done = 0
+ this.total = 0
+ this.process = 0
+ this.tableData = []
+ this.tid = response.data.tid
+ this.isStart = true // 标记正在请求数据中
+ this.flag = true
this.timer = setInterval(() => {
- if (this.tableData.length < this.total) {
+ if (parseInt(this.process) < 100) {
this.getData()
} else {
this.clearTask()
}
- }, 1000)
+ }, 300)
})
},
// 请求表格数据
getData () {
+ const currentId = this.tid
this.$get('/tool/ping/result/' + this.tid).then(response => {
- this.tableData.push({
- dataCenter: '数据中心',
- source: '192.168.40.1',
- ip: '192.168.40.2',
- state: 1,
- rate: 20.0,
- avg: 30,
- min: 23,
- max: 44,
- raw: '正在 Ping 127.0.0.1 具有 32 字节的数据:\r\n来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=64\r\n来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=64\r\n来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=64\r\n来自 127.0.0.1 的回复: 字节=32 时间<1ms TTL=64\r\n\r\n127.0.0.1 的 Ping 统计信息:\r\n 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),\r\n往返行程的估计时间(以毫秒为单位):\r\n 最短 = 0ms,最长 = 0ms,平均 = 0ms'
- })
+ if (currentId === this.tid && parseInt(this.process) < 100) {
+ this.done = response.data.task.done
+ this.total = response.data.task.total
+ this.process = response.data.task.process
+ this.tableData.push(...response.data.list)
+ }
})
},
// 清除任务
async clearTask () {
+ if (!this.flag) {
+ return false
+ }
+ this.flag = false
if (this.timer) {
clearInterval(this.timer)
this.timer = null
}
await this.$get('/tool/ping/cancel/' + this.tid)
- this.flag = false
- }
+ this.isStart = false
+ this.flag = true
+ },
+ // 空函数 防止mixins中的函数执行
+ getTableData () { }
},
// 离开页面的时候触发
async beforeRouteLeave (to, from, next) {
- await this.clearTask()
+ if (this.tid) {
+ await this.clearTask()
+ }
next()
}
}
diff --git a/nezha-fronted/static/config.json b/nezha-fronted/static/config.json
index abcddc473..5f74f5d01 100644
--- a/nezha-fronted/static/config.json
+++ b/nezha-fronted/static/config.json
@@ -1 +1 @@
-{"baseUrl":"http://192.168.40.42:8080/", "version": "21.04"}
+{"baseUrl":"/", "version": "21.04"}