fix: 修复时间切换后会重复执行查询的问题

This commit is contained in:
chenjinsong
2022-10-12 21:52:07 +08:00
parent e0c42c8b4c
commit 6391bfd98d
27 changed files with 6451 additions and 66 deletions

File diff suppressed because one or more lines are too long

View File

@@ -102,7 +102,6 @@ export default {
mixins: [chartMixin], mixins: [chartMixin],
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.initData() this.initData()
} }

View File

@@ -47,7 +47,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.initData() this.initData()
} }

View File

@@ -43,7 +43,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.eventsByTypeData() this.eventsByTypeData()
} }

View File

@@ -64,7 +64,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.eventsByTypeData() this.eventsByTypeData()
} }

View File

@@ -172,7 +172,6 @@ export default {
mixins: [chartMixin], mixins: [chartMixin],
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.dnsRecentEventData() this.dnsRecentEventData()
} }

View File

@@ -167,7 +167,6 @@ export default {
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
if (this.lineTab) { if (this.lineTab) {
this.init(this.lineMetric, this.showMarkLine, 'active') this.init(this.lineMetric, this.showMarkLine, 'active')

View File

@@ -138,7 +138,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -31,7 +31,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -35,7 +35,7 @@ import { get } from '@/utils/http'
import { api } from '@/utils/api' import { api } from '@/utils/api'
import { getSecond } from '@/utils/date-util' import { getSecond } from '@/utils/date-util'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { overwriteUrl, urlParamsHandler } from '@/utils/tools' import { overwriteUrl, urlParamsHandler, ingress, egress } from '@/utils/tools'
import unitConvert from '@/utils/unit-convert' import unitConvert from '@/utils/unit-convert'
import { storageKey, unitTypes } from '@/utils/constants' import { storageKey, unitTypes } from '@/utils/constants'
@@ -79,7 +79,6 @@ export default {
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.linkTrafficSankeyDataRequest(this.tab) this.linkTrafficSankeyDataRequest(this.tab)
} }
@@ -92,22 +91,24 @@ export default {
endTime: getSecond(this.timeFilter.endTime) endTime: getSecond(this.timeFilter.endTime)
} }
let condition = '' let condition = ''
if (this.queryCondition.indexOf(' AND ') > -1) { if (this.queryCondition) {
condition = this.queryCondition.split(/["'= ](.*?)["'= ]/) if (this.queryCondition.indexOf(' AND ') > -1) {
} else { condition = this.queryCondition.split(/["'= ](.*?)["'= ]/)
condition = this.queryCondition
}
if (condition.length > 1 && condition[0] === 'common_egress_link_id') {
if (n == 0) {
params.q = `${condition[0]}=${condition[3]}`
} else { } else {
params.q = `${condition[5]}=${condition[8]}` condition = this.queryCondition
} }
} else { if (condition.length > 1 && condition[0] === 'common_egress_link_id') {
if (n == 0) { if (n == 0) {
params.q = `${condition[0]}=${condition[4]}` params.q = `${condition[0]}=${condition[3]}`
} else {
params.q = `${condition[5]}=${condition[8]}`
}
} else { } else {
params.q = `${condition[7]}=${condition[11]}` if (n == 0) {
params.q = `${condition[0]}=${condition[4]}`
} else {
params.q = `${condition[7]}=${condition[11]}`
}
} }
} }
let url = '' let url = ''
@@ -133,7 +134,76 @@ export default {
}) })
}, },
dataProcessing (result, tab) { dataProcessing (result, tab) {
let data = [] result = ingress.data.result
const datas = []
const links = []
if (tab == 0) {
result.forEach(t => {
this.cnLinkInfo.forEach(e => {
if (t.commonIngressLinkId == e.originalLinkId) {
t.linkId = e.linkId
t.linkDirection = e.nextHop
t.bandWidth = e.bandwidth
t.value = parseInt(t.ingressBytes)
t.client = `c_${t.clientProvince}`
t.server = `s_${t.serverProvince}`
}
})
})
} else {
result.forEach(t => {
this.cnLinkInfo.forEach(e => {
if (t.commonEgressLinkId == e.originalLinkId) {
t.linkId = e.linkId
t.linkDirection = e.nextHop
t.bandWidth = e.bandwidth
t.value = parseInt(t.egressBytes)
t.client = `c_${t.clientProvince}`
t.server = `s_${t.serverProvince}`
}
})
})
}
result = result.sort((a, b) => b.value - a.value).filter(r => r.clientProvince && r.serverProvince)
if (tab == 0) {
result.forEach(r => {
if (!datas.some(d => d.name === r.client)) {
datas.push({ name: r.client, originalName: r.clientProvince, depth: 0 })
}
const existLink0 = links.find(l => l.source === r.client && l.target === r.linkId)
if (existLink0) {
existLink0.value += r.value
} else {
links.push({ source: r.client, target: r.linkId, value: r.value, depth: 0 })
}
if (!datas.some(d => d.name === r.linkId)) {
datas.push({ name: r.linkId, depth: 1 })
}
const existLink1 = links.find(l => l.source === r.linkId && l.target === r.linkDirection)
if (existLink1) {
existLink1.value += r.value
} else {
links.push({ source: r.linkId, target: r.linkDirection, value: r.value, depth: 1 })
}
if (!datas.some(d => d.name === r.linkDirection)) {
datas.push({ name: r.linkDirection, depth: 2 })
}
const existLink2 = links.find(l => l.source === r.linkDirection && l.target === r.server)
if (existLink2) {
existLink2.value += r.value
} else {
links.push({ source: r.linkDirection, target: r.server, value: r.value, depth: 2 })
}
if (!datas.some(d => d.name === r.server)) {
datas.push({ name: r.server, originalName: r.serverProvince, depth: 3 })
}
})
} else {
}
this.echartsInit(tab, datas, links)
/*let data = []
let links = [] let links = []
result.forEach(t => { result.forEach(t => {
this.cnLinkInfo.forEach(e => { this.cnLinkInfo.forEach(e => {
@@ -145,13 +215,13 @@ export default {
} }
}) })
data.push( data.push(
{ name: t.serverCity }, { name: t.serverProvince },
{ name: t.commonEgressLinkId }, { name: t.commonEgressLinkId },
{ name: tab == 0 ? t.ingressLinkDirection : t.egressLinkDirection }, { name: tab == 0 ? t.ingressLinkDirection : t.egressLinkDirection },
{ name: t.clientCity } { name: t.clientProvince }
) )
}) })
const clientCity = [] const clientProvince = []
const linkDirection = [] const linkDirection = []
const commonEgressLinkId = [] const commonEgressLinkId = []
let link = [] let link = []
@@ -159,64 +229,64 @@ export default {
const LinkDirectionShow = tab == 0 ? t.ingressLinkDirection : t.egressLinkDirection const LinkDirectionShow = tab == 0 ? t.ingressLinkDirection : t.egressLinkDirection
const bytes = tab == 0 ? t.ingressBytes : t.egressBytes const bytes = tab == 0 ? t.ingressBytes : t.egressBytes
if (tab == 0) { if (tab == 0) {
clientCity.push({ clientProvince.push({
source: t.clientCity, source: t.clientProvince,
target: LinkDirectionShow, target: LinkDirectionShow,
commonEgressLinkId: t.commonEgressLinkId, commonEgressLinkId: t.commonEgressLinkId,
serverCity: t.serverCity, serverProvince: t.serverProvince,
value: bytes, value: bytes,
bandWidth: t.bandWidth, bandWidth: t.bandWidth,
depth: 0 depth: 0
}) })
linkDirection.push({ linkDirection.push({
clientCity: t.clientCity, clientProvince: t.clientProvince,
source: LinkDirectionShow, source: LinkDirectionShow,
target: t.commonEgressLinkId, target: t.commonEgressLinkId,
serverCity: t.serverCity, serverProvince: t.serverProvince,
value: bytes, value: bytes,
bandWidth: t.bandWidth, bandWidth: t.bandWidth,
depth: 1 depth: 1
}) })
commonEgressLinkId.push({ commonEgressLinkId.push({
clientCity: t.clientCity, clientProvince: t.clientProvince,
LinkDirectionShow: LinkDirectionShow, LinkDirectionShow: LinkDirectionShow,
source: t.commonEgressLinkId, source: t.commonEgressLinkId,
target: t.serverCity, target: t.serverProvince,
value: bytes, value: bytes,
bandWidth: t.bandWidth, bandWidth: t.bandWidth,
depth: 2 depth: 2
}) })
} else { } else {
clientCity.push({ clientProvince.push({
source: t.clientCity, source: t.clientProvince,
target: t.commonEgressLinkId, target: t.commonEgressLinkId,
LinkDirectionShow: LinkDirectionShow, LinkDirectionShow: LinkDirectionShow,
serverCity: t.serverCity, serverProvince: t.serverProvince,
value: bytes, value: bytes,
bandWidth: t.bandWidth, bandWidth: t.bandWidth,
depth: 0 depth: 0
}) })
linkDirection.push({ linkDirection.push({
clientCity: t.clientCity, clientProvince: t.clientProvince,
source: t.commonEgressLinkId, source: t.commonEgressLinkId,
target: LinkDirectionShow, target: LinkDirectionShow,
serverCity: t.serverCity, serverProvince: t.serverProvince,
value: bytes, value: bytes,
bandWidth: t.bandWidth, bandWidth: t.bandWidth,
depth: 1 depth: 1
}) })
commonEgressLinkId.push({ commonEgressLinkId.push({
clientCity: t.clientCity, clientProvince: t.clientProvince,
commonEgressLinkId: t.commonEgressLinkId, commonEgressLinkId: t.commonEgressLinkId,
source: LinkDirectionShow, source: LinkDirectionShow,
target: t.serverCity, target: t.serverProvince,
value: bytes, value: bytes,
bandWidth: t.bandWidth, bandWidth: t.bandWidth,
depth: 2 depth: 2
}) })
} }
}) })
link = [...clientCity, ...linkDirection, ...commonEgressLinkId] link = [...clientProvince, ...linkDirection, ...commonEgressLinkId]
for (let i = 0; i < link.length; i++) { for (let i = 0; i < link.length; i++) {
for (let j = i + 1; j < link.length; j++) { for (let j = i + 1; j < link.length; j++) {
if (link[i].source === link[j].source && link[i].target === link[j].target) { if (link[i].source === link[j].source && link[i].target === link[j].target) {
@@ -233,7 +303,7 @@ export default {
} }
data = [...map.values()] data = [...map.values()]
links = link links = link
this.echartsInit(tab, data, links) this.echartsInit(tab, data, links)*/
}, },
echartsInit (tab, data, links) { echartsInit (tab, data, links) {
const _this = this const _this = this
@@ -252,23 +322,23 @@ export default {
let value = 0 let value = 0
if (param.data.depth === 0) { if (param.data.depth === 0) {
if (tab == 0) { if (tab == 0) {
data = ` ${param.data.source} > ${param.data.target} > ${param.data.commonEgressLinkId} > ${param.data.serverCity}` data = ` ${param.data.source} > ${param.data.target} > ${param.data.commonEgressLinkId} > ${param.data.serverProvince}`
} else { } else {
data = `${param.data.source} > ${param.data.target} > ${param.data.LinkDirectionShow} > ${param.data.serverCity}` data = `${param.data.source} > ${param.data.target} > ${param.data.LinkDirectionShow} > ${param.data.serverProvince}`
} }
value = unitConvert((param.data.value / param.data.bandWidth), unitTypes.percent).join(' ') value = unitConvert((param.data.value / param.data.bandWidth), unitTypes.percent).join(' ')
} else if (param.data.depth === 1) { } else if (param.data.depth === 1) {
if (tab == 0) { if (tab == 0) {
data = `${param.data.clientCity} > ${param.data.source} > ${param.data.target} > ${param.data.serverCity}` data = `${param.data.clientProvince} > ${param.data.source} > ${param.data.target} > ${param.data.serverProvince}`
} else { } else {
data = `${param.data.clientCity} > ${param.data.source} > ${param.data.target} > ${param.data.serverCity}` data = `${param.data.clientProvince} > ${param.data.source} > ${param.data.target} > ${param.data.serverProvince}`
} }
value = unitConvert((param.data.value / param.data.bandWidth), unitTypes.percent).join(' ') value = unitConvert((param.data.value / param.data.bandWidth), unitTypes.percent).join(' ')
} else if (param.data.depth === 2) { } else if (param.data.depth === 2) {
if (tab == 0) { if (tab == 0) {
data = `${param.data.clientCity} > ${param.data.LinkDirectionShow} > ${param.data.source} > ${param.data.target}` data = `${param.data.clientProvince} > ${param.data.LinkDirectionShow} > ${param.data.source} > ${param.data.target}`
} else { } else {
data = ` ${param.data.clientCity} > ${param.data.commonEgressLinkId} > ${param.data.source} > ${param.data.target}` data = ` ${param.data.clientProvince} > ${param.data.commonEgressLinkId} > ${param.data.source} > ${param.data.target}`
} }
value = unitConvert((param.data.value / param.data.bandWidth), unitTypes.percent).join(' ') value = unitConvert((param.data.value / param.data.bandWidth), unitTypes.percent).join(' ')
} }

View File

@@ -134,7 +134,6 @@ export default {
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
if (this.lineTab) { if (this.lineTab) {
this.init(this.lineMetric, this.showMarkLine, 'active') this.init(this.lineMetric, this.showMarkLine, 'active')

View File

@@ -219,7 +219,6 @@ export default {
} }
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -42,7 +42,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.ddosDetectDataRequests() this.ddosDetectDataRequests()
} }

View File

@@ -174,7 +174,6 @@ export default {
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
if (this.lineTab) { if (this.lineTab) {
this.init(this.lineMetric, this.showMarkLine, 'active') this.init(this.lineMetric, this.showMarkLine, 'active')

View File

@@ -140,7 +140,6 @@ export default {
this.toggleLoading(n) this.toggleLoading(n)
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -273,7 +273,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
console.log('watch') console.log('watch')
const curTab = this.getCurTab() const curTab = this.getCurTab()

View File

@@ -126,7 +126,6 @@ export default {
mixins: [chartMixin], mixins: [chartMixin],
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -59,7 +59,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.eventsByTypeData() this.eventsByTypeData()
} }

View File

@@ -52,7 +52,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.recentEventsListData() this.recentEventsListData()
} }

View File

@@ -41,7 +41,6 @@ export default {
mixins: [chartMixin], mixins: [chartMixin],
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.loadAm4ChartMap(this.polygonSeries, this.worldImageSeries) this.loadAm4ChartMap(this.polygonSeries, this.worldImageSeries)
} }

View File

@@ -95,7 +95,6 @@ export default {
} }
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -304,7 +304,6 @@ export default {
} }
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
if (this.location) { if (this.location) {
this.loadAm4ChartMap(this.countrySeries, this.countryImageSeries) this.loadAm4ChartMap(this.countrySeries, this.countryImageSeries)

View File

@@ -48,7 +48,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.npmNetworkCycleData = [] this.npmNetworkCycleData = []
this.npmNetworkLastCycleData = [] this.npmNetworkLastCycleData = []

View File

@@ -76,7 +76,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.recentEventsListData() this.recentEventsListData()
} }

View File

@@ -124,7 +124,6 @@ export default {
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.init() this.init()
} }

View File

@@ -51,7 +51,6 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
deep: true,
handler (n) { handler (n) {
this.relatedSessionsData() this.relatedSessionsData()
} }

View File

@@ -455,7 +455,10 @@ export const linksTrafficSankeyOption = {
bottom: '23%', bottom: '23%',
label: { label: {
color: 'rgba(0,0,0,0.7)', color: 'rgba(0,0,0,0.7)',
fontSize: 12 fontSize: 12,
formatter (params) {
return params.data.originalName || params.data.name
}
}, },
draggable: false draggable: false
} }