fix:CN-1518 Subscriber流量曲线图的交互逻辑优化(减少请求次数),及其他模块相关代码调整

This commit is contained in:
hanyuxia
2023-12-22 17:32:02 +08:00
parent 899b0e1e9d
commit 21eafd4087
7 changed files with 87 additions and 175 deletions

View File

@@ -175,8 +175,8 @@ export default {
const url = this.lineQueryCondition ? api.dnsInsight.drilldownTrafficAnalysis : api.dnsInsight.totalTrafficAnalysis const url = this.lineQueryCondition ? api.dnsInsight.drilldownTrafficAnalysis : api.dnsInsight.totalTrafficAnalysis
axios.get(url, { params }).then(res => { axios.get(url, { params }).then(res => {
this.chartDateObject = res
if (res.status === 200) { if (res.status === 200) {
this.chartDateObject = res.data.data.result
this.showError = false this.showError = false
this.isNoData = res.data.data.result.length === 0 this.isNoData = res.data.data.result.length === 0
if (!active) { if (!active) {
@@ -208,28 +208,9 @@ export default {
} }
this.toggleLoading(true) this.toggleLoading(true)
try { try {
const res = this.chartDateObject.data this.initData(this.chartDateObject, val, active, show)
if (this.chartDateObject.status === 200) {
this.isNoData = res.data.result.length === 0
if (!active) {
this.tabs = _.cloneDeep(dataForDnsTrafficLine.tabs)
}
if (this.isNoData) {
this.lineTab = ''
this.tabs = _.cloneDeep(dataForDnsTrafficLine.tabs)
} else {
this.initData(res.data.result, val, active, show)
}
} else {
this.isNoData = false
this.showError = true
this.errorMsg = this.errorMsgHandler(res)
}
} catch (e) { } catch (e) {
console.error(e) console.error(e)
this.isNoData = false
this.showError = true
this.errorMsg = this.errorMsgHandler(e)
} finally { } finally {
this.toggleLoading(false) this.toggleLoading(false)
} }

View File

@@ -228,8 +228,8 @@ export default {
this.toggleLoading(true) this.toggleLoading(true)
axios.get(`${api.entity.throughput}/${this.entity.entityType}`, { params: params }).then(response => { axios.get(`${api.entity.throughput}/${this.entity.entityType}`, { params: params }).then(response => {
const res = response.data const res = response.data
this.chartDateObject = response
if (response.status === 200) { if (response.status === 200) {
this.chartDateObject = res.data.result
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
this.showError = false this.showError = false
if (!active) { if (!active) {
@@ -255,25 +255,9 @@ export default {
const newVal = val ? _.clone(val) : this.metric const newVal = val ? _.clone(val) : this.metric
this.toggleLoading(true) this.toggleLoading(true)
try { try {
const res = this.chartDateObject.data this.initData(this.chartDateObject, newVal, active, show, n)
if (this.chartDateObject.status === 200) {
this.isNoData = res.data.result.length === 0
this.showError = false
if (!active) {
this.tabs = _.cloneDeep(this.tabsTemplate)
}
if (this.isNoData) {
this.lineTab = ''
this.tabs = _.cloneDeep(this.tabsTemplate)
} else {
this.initData(res.data.result, newVal, active, show, n)
}
} else {
this.httpError(res)
}
} catch (e) { } catch (e) {
console.error(e) console.error(e)
this.httpError(e)
} finally { } finally {
this.toggleLoading(false) this.toggleLoading(false)
} }

View File

@@ -167,7 +167,18 @@ export default {
if (n === metricType.Sessions) { if (n === metricType.Sessions) {
this.lineTab = 'total' this.lineTab = 'total'
} }
this.init(n, 'active') const { query } = this.$route
const rangeParam = query.range
const dateRangeValue = rangeParam ? parseInt(rangeParam) : (DEFAULT_TIME_FILTER_RANGE.entity.trafficLine || 60)
if (dateRangeValue !== -1) {
const { startTime, endTime } = getNowTime(dateRangeValue)
const timeFilter = { startTime: getSecond(startTime), endTime: getSecond(endTime), range: dateRangeValue }
const newUrl = urlParamsHandler(window.location.href, query, timeFilter)
overwriteUrl(newUrl)
this.init(n, 'active', timeFilter)
} else {
this.initTabData(n, 'active')
}
} }
}, },
methods: { methods: {
@@ -176,13 +187,13 @@ export default {
const newUrl = urlParamsHandler(window.location.href, query, newParam) const newUrl = urlParamsHandler(window.location.href, query, newParam)
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
init (val, active) { init (val, active, timeFilter) {
const newVal = val ? _.clone(val) : this.metric const newVal = val ? _.clone(val) : this.metric
const params = { const params = {
resource: this.entity.entityName, resource: this.entity.entityName,
startTime: getSecond(this.timeFilter.startTime), startTime: timeFilter ? timeFilter.startTime : getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime), endTime: timeFilter ? timeFilter.endTime : getSecond(this.timeFilter.endTime),
metric: newVal metric: newVal
} }
@@ -193,8 +204,8 @@ export default {
this.toggleLoading(true) this.toggleLoading(true)
axios.get(`${api.entity.throughput}/${this.entity.entityType}/relate/app`, { params: params }).then(response => { axios.get(`${api.entity.throughput}/${this.entity.entityType}/relate/app`, { params: params }).then(response => {
const res = response.data const res = response.data
if (response.status === 200) { if (response.status === 200) {
this.chartDateObject = res.data.result
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
this.showError = false this.showError = false
if (!active) { if (!active) {
@@ -216,6 +227,17 @@ export default {
this.toggleLoading(false) this.toggleLoading(false)
}) })
}, },
initTabData (val, active) {
const newVal = val ? _.clone(val) : this.metric
this.toggleLoading(true)
try {
this.initData(this.chartDateObject, newVal, active)
} catch (e) {
console.error(e)
} finally {
this.toggleLoading(false)
}
},
echartsInit (echartsData) { echartsInit (echartsData) {
// echarts内容在单元测试时不执行 // echarts内容在单元测试时不执行
if (!this.isUnitTesting) { if (!this.isUnitTesting) {
@@ -302,7 +324,11 @@ export default {
if (this.lineTab === item.class) return if (this.lineTab === item.class) return
this.lineTab = item.class this.lineTab = item.class
this.legendSelectChange(item, index, 'active') this.legendSelectChange(item, index, 'active')
this.init(this.metric, 'active') if (isClick) {
this.initTabData(this.metric, 'active')
} else {
this.init(this.metric, 'active')
}
}, },
mouseenter (item) { mouseenter (item) {
if (this.isNoData) return if (this.isNoData) return

View File

@@ -196,7 +196,19 @@ export default {
e.invertTab = true e.invertTab = true
} }
}) })
this.init(n, this.showMarkLine, '', n)
const { query } = this.$route
const rangeParam = query.range
const dateRangeValue = rangeParam ? parseInt(rangeParam) : (DEFAULT_TIME_FILTER_RANGE.entity.trafficLine || 60)
if (dateRangeValue !== -1) {
const { startTime, endTime } = getNowTime(dateRangeValue)
const timeFilter = { startTime: getSecond(startTime), endTime: getSecond(endTime), range: dateRangeValue }
const newUrl = urlParamsHandler(window.location.href, query, timeFilter)
overwriteUrl(newUrl)
this.init(n, this.showMarkLine, '', n, timeFilter)
} else {
this.initTabData(n, this.showMarkLine, '', n)
}
} }
}, },
methods: { methods: {
@@ -205,13 +217,13 @@ export default {
const newUrl = urlParamsHandler(window.location.href, query, newParam) const newUrl = urlParamsHandler(window.location.href, query, newParam)
overwriteUrl(newUrl) overwriteUrl(newUrl)
}, },
init (val, show, active, n) { init (val, show, active, n, timeFilter) {
const newVal = val ? _.clone(val) : this.metric const newVal = val ? _.clone(val) : this.metric
const params = { const params = {
resource: this.entity.entityName, resource: this.entity.entityName,
startTime: getSecond(this.timeFilter.startTime), startTime: timeFilter ? timeFilter.startTime : getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime), endTime: timeFilter ? timeFilter.endTime : getSecond(this.timeFilter.endTime),
metric: newVal metric: newVal
} }
@@ -222,8 +234,8 @@ export default {
this.toggleLoading(true) this.toggleLoading(true)
axios.get(`${api.entity.throughput}/${this.entity.entityType}`, { params: params }).then(response => { axios.get(`${api.entity.throughput}/${this.entity.entityType}`, { params: params }).then(response => {
const res = response.data const res = response.data
if (response.status === 200) { if (response.status === 200) {
this.chartDateObject = res.data.result
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
this.showError = false this.showError = false
if (!active) { if (!active) {
@@ -245,6 +257,17 @@ export default {
this.toggleLoading(false) this.toggleLoading(false)
}) })
}, },
initTabData (val, show, active, n) {
const newVal = val ? _.clone(val) : this.metric
this.toggleLoading(true)
try {
this.initData(this.chartDateObject, newVal, active, show, n)
} catch (e) {
console.error(e)
} finally {
this.toggleLoading(false)
}
},
echartsInit (echartsData, show) { echartsInit (echartsData, show) {
// echarts内容在单元测试时不执行 // echarts内容在单元测试时不执行
if (!this.isUnitTesting) { if (!this.isUnitTesting) {
@@ -389,7 +412,11 @@ export default {
this.legendSelectChange(item, index, 'active') this.legendSelectChange(item, index, 'active')
this.showMarkLine = !item.invertTab this.showMarkLine = !item.invertTab
} }
this.init(this.metric, this.showMarkLine, 'active') if (isClick) {
this.initTabData(this.metric, this.showMarkLine, 'active')
} else {
this.init(this.metric, this.showMarkLine, 'active')
}
}, },
mouseenter (item) { mouseenter (item) {
if (this.isNoData) return if (this.isNoData) return

View File

@@ -152,15 +152,9 @@ export default {
if (!val) { if (!val) {
val = this.lineMetric val = this.lineMetric
} }
let params = { const params = {
startTime: getSecond(this.timeFilter.startTime), startTime: timeFilter ? timeFilter.startTime : getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime) endTime: timeFilter ? timeFilter.endTime : getSecond(this.timeFilter.endTime)
}
if (timeFilter) {
params = {
startTime: timeFilter.startTime,
endTime: timeFilter.endTime
}
} }
if (this.queryCondition) { if (this.queryCondition) {
const condition = this.queryCondition.split(' or ') const condition = this.queryCondition.split(' or ')
@@ -172,9 +166,9 @@ export default {
this.loading = true this.loading = true
axios.get(api.linkMonitor.totalTrafficAnalysis, { params: params }).then(response => { axios.get(api.linkMonitor.totalTrafficAnalysis, { params: params }).then(response => {
const res = response.data const res = response.data
this.chartDateObject = response
if (response.status === 200) { if (response.status === 200) {
this.showError = false this.showError = false
this.chartDateObject = res.data.result
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
if (!active) { if (!active) {
this.tabs = dataForLinkTrafficLine.tabs this.tabs = dataForLinkTrafficLine.tabs
@@ -204,28 +198,9 @@ export default {
} }
this.loading = true this.loading = true
try { try {
const res = this.chartDateObject.data this.initData(this.chartDateObject, val, active, show)
if (this.chartDateObject.status === 200) {
this.showError = false
this.isNoData = res.data.result.length === 0
if (!active) {
this.tabs = dataForLinkTrafficLine.tabs
}
if (this.isNoData) {
this.lineTab = ''
this.tabs = dataForLinkTrafficLine.tabs
} else {
this.initData(res.data.result, val, active, show)
}
} else {
this.showError = true
this.errorMsg = this.errorMsgHandler(res)
}
} catch (e) { } catch (e) {
console.error(e) console.error(e)
this.showError = true
this.errorMsg = this.errorMsgHandler(e)
this.isNoData = false
} finally { } finally {
this.loading = false this.loading = false
} }

View File

@@ -180,17 +180,10 @@ export default {
init (val, show, active, n, timeFilter) { init (val, show, active, n, timeFilter) {
const newVal = val ? _.clone(val) : this.metric const newVal = val ? _.clone(val) : this.metric
let params = { const params = {
startTime: getSecond(this.timeFilter.startTime), startTime: timeFilter ? timeFilter.startTime : getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime) endTime: timeFilter ? timeFilter.endTime : getSecond(this.timeFilter.endTime)
} }
if (timeFilter) {
params = {
startTime: timeFilter.startTime,
endTime: timeFilter.endTime
}
}
let url let url
if (this.lineQueryCondition && this.fourthMenu) { if (this.lineQueryCondition && this.fourthMenu) {
params.q = this.lineQueryCondition params.q = this.lineQueryCondition
@@ -209,8 +202,8 @@ export default {
this.toggleLoading(true) this.toggleLoading(true)
axios.get(url, { params: params }).then(response => { axios.get(url, { params: params }).then(response => {
const res = response.data const res = response.data
this.chartDateObject = response
if (response.status === 200) { if (response.status === 200) {
this.chartDateObject = res.data.result
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
this.showError = false this.showError = false
if (!active) { if (!active) {
@@ -236,25 +229,9 @@ export default {
const newVal = val ? _.clone(val) : this.metric const newVal = val ? _.clone(val) : this.metric
this.toggleLoading(true) this.toggleLoading(true)
try { try {
const res = this.chartDateObject.data this.initData(this.chartDateObject, newVal, active, show, n)
if (this.chartDateObject.status === 200) {
this.isNoData = res.data.result.length === 0
this.showError = false
if (!active) {
this.tabs = _.cloneDeep(this.tabsTemplate)
}
if (this.isNoData) {
this.lineTab = ''
this.tabs = _.cloneDeep(this.tabsTemplate)
} else {
this.initData(res.data.result, newVal, active, show, n)
}
} else {
this.httpError(res)
}
} catch (e) { } catch (e) {
console.error(e) console.error(e)
this.httpError(e)
} finally { } finally {
this.toggleLoading(false) this.toggleLoading(false)
} }

View File

@@ -143,10 +143,10 @@ export default {
this.toggleLoading(true) this.toggleLoading(true)
if (params.type && params.q) { if (params.type && params.q) {
axios.get(api.npm.overview.trafficGraph, { params: params }).then(response => { axios.get(api.npm.overview.trafficGraph, { params: params }).then(response => {
this.chartDateObject = response
const res = response.data const res = response.data
if (response.status === 200) { if (response.status === 200) {
this.showError = false this.showError = false
this.chartDateObject = res.data.result
this.isNoData = res.data.result.length === 0 this.isNoData = res.data.result.length === 0
if (this.isNoData) { if (this.isNoData) {
this.tabs = dataForNpmTrafficLine.tabs this.tabs = dataForNpmTrafficLine.tabs
@@ -198,72 +198,13 @@ export default {
if (!val) { if (!val) {
val = this.metricFilter val = this.metricFilter
} }
let condition = ''
const type = this.dimensionType
if (this.lineQueryCondition.indexOf(' OR ') > -1) {
condition = this.lineQueryCondition.split(/["|'](.*?)["|']/)
} else if (this.lineQueryCondition.indexOf('+OR+') > -1) {
condition = this.lineQueryCondition.replace(/\+/g, ' ').split(/["|'](.*?)["|']/)
} else {
condition = this.lineQueryCondition
}
if (parseFloat(this.tabIndex) === 0) {
this.side = 'client'
} else if (parseFloat(this.tabIndex) === 1) {
this.side = 'server'
}
const params = {
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime),
type: type
}
if (type === 'ip' || type === 'clientIp' || type === 'serverIp') {
params.q = `${condition} and side='${this.side}'`
} else {
params.q = condition
}
this.toggleLoading(true) this.toggleLoading(true)
if (params.type && params.q) { try {
try { this.initLineData(this.chartDateObject, val)
const res = this.chartDateObject.data } catch (e) {
if (this.chartDateObject.status === 200) { console.error(e)
this.showError = false } finally {
this.isNoData = res.data.result.length === 0 this.toggleLoading(false)
if (this.isNoData) {
this.tabs = dataForNpmTrafficLine.tabs
this.npmQuantity = dataForNpmTrafficLine.npmQuantity
} else {
this.initLineData(res.data.result, val)
}
} else {
this.httpError(res)
}
} catch (e) {
this.httpError(e)
console.error(e)
} finally {
this.toggleLoading(false)
}
} else {
this.toggleLoading(true)
try {
this.showError = false
this.isNoData = this.chartDateObject.length === 0
if (this.isNoData) {
this.tabs = dataForNpmTrafficLine.tabs
this.npmQuantity = dataForNpmTrafficLine.npmQuantity
} else {
this.initLineData(this.chartDateObject, val)
}
} catch (e) {
this.httpError(e)
} finally {
this.toggleLoading(false)
}
} }
}, },
/** /**
@@ -417,6 +358,7 @@ export default {
}) })
}, },
metricChange (value) { metricChange (value) {
if (this.isNoData) return
this.initDataByCache(value) this.initDataByCache(value)
}, },
resize () { resize () {