feat: 单测 Npm - Overview 概况信息统计

This commit is contained in:
@changcode
2023-02-01 11:32:47 +08:00
parent c8af5fd5a1
commit 1f130a6ac8
2 changed files with 287 additions and 36 deletions

View File

@@ -27,7 +27,7 @@
</span> </span>
<span v-else :test-id="`singleValueTrendValue${index}`">>500.00%</span> <span v-else :test-id="`singleValueTrendValue${index}`">>500.00%</span>
</div> </div>
<div v-else-if="npm.value === 0" class="single-value__content-trend single-value__content-trend-black" > <div v-else-if="npm.value === 0" class="single-value__content-trend single-value__content-trend-black">
<i class="cn-icon-constant cn-icon" :test-id="`singleValueTrendIcon${index}`"></i> <i class="cn-icon-constant cn-icon" :test-id="`singleValueTrendIcon${index}`"></i>
</div> </div>
<div v-else></div> <div v-else></div>
@@ -55,7 +55,6 @@
</template> </template>
<script> <script>
import { get } from '@/utils/http'
import { getSecond } from '@/utils/date-util' import { getSecond } from '@/utils/date-util'
import { api } from '@/utils/api' import { api } from '@/utils/api'
import chartMixin from '@/views/charts2/chart-mixin' import chartMixin from '@/views/charts2/chart-mixin'
@@ -65,6 +64,7 @@ import { useRoute } from 'vue-router'
import { ref } from 'vue' import { ref } from 'vue'
import { unitTypes } from '@/utils/constants' import { unitTypes } from '@/utils/constants'
import unitConvert from '@/utils/unit-convert' import unitConvert from '@/utils/unit-convert'
import axios from 'axios'
export default { export default {
name: 'NpmNetworkQuantity', name: 'NpmNetworkQuantity',
mixins: [chartMixin], mixins: [chartMixin],
@@ -117,7 +117,7 @@ export default {
npmNetworkCycleQuery () { npmNetworkCycleQuery () {
let condition = '' let condition = ''
let url = '' let url = ''
if (this.queryCondition.indexOf(' OR ') > -1) { if (this.queryCondition && this.queryCondition.indexOf(' OR ') > -1) {
condition = this.queryCondition.split(/["|'](.*?)["|']/) condition = this.queryCondition.split(/["|'](.*?)["|']/)
} else { } else {
condition = this.queryCondition condition = this.queryCondition
@@ -133,37 +133,38 @@ export default {
} else if (parseFloat(this.tabIndex) === 1) { } else if (parseFloat(this.tabIndex) === 1) {
this.side = 'server' this.side = 'server'
} }
if (condition && (typeof condition !== 'object') && type) { if (condition && (typeof condition !== 'object') && type) { // 判断 condition 不为空并且不为对象 type 不为空
if (type === 'clientIp' || type === 'serverIp') { if (type === 'clientIp' || type === 'serverIp') { // type = clientIp || serverIp
if (parseFloat(this.tabIndex) === 0) { if (parseFloat(this.tabIndex) === 0) { // npm 下钻 tabIndex 为 0
type = 'clientIp' type = 'clientIp'
} else if (parseFloat(this.tabIndex) === 1) { } else if (parseFloat(this.tabIndex) === 1) { // npm 下钻 tabIndex 为 1
type = 'serverIp' type = 'serverIp'
} }
params.q = `ip='${condition.split(/'(.*?)'/)[1]}'` params.q = `ip='${condition.split(/'(.*?)'/)[1]}'` // 拼接字段作为参数
} else if (type === 'clientCity') { } else if (type === 'clientCity') {
params.q = `client_city='${condition.split(/'(.*?)'/)[1]}'` params.q = `client_city='${condition.split(/'(.*?)'/)[1]}'` // 拼接字段作为参数
} else if (type === 'serverCity') { } else if (type === 'serverCity') {
params.q = `server_city='${condition.split(/'(.*?)'/)[1]}'` params.q = `server_city='${condition.split(/'(.*?)'/)[1]}'` // 拼接字段作为参数
} else { } else {
params.q = condition params.q = condition // 默认参数
} }
params.type = type params.type = type
} else if (condition.length > 1 && type && type === 'ip') { } else if (condition.length > 1 && type && type === 'ip') { // condition 为数组时数组长度不为 0 | type 不为空 | type为ip
params.q = `${type}='${condition[1]}' and side='${this.side}'` params.q = `${type}='${condition[1]}' and side='${this.side}'` // 拼接字段作为参数
params.type = type params.type = type
} else if (condition.length > 1 && type && type !== 'ip') { } else if (condition.length > 1 && type && type !== 'ip') { // condition 为数组时数组长度不为 0 | type 不为空 | type不为ip
if (type === 'country' || type === 'asn' || type === 'province' || type === 'city' || type === 'isp') { if (type === 'country' || type === 'asn' || type === 'province' || type === 'city' || type === 'isp') { // 根据接口所需,调整参数
params.q = `${type}='${condition[1]}'` params.q = `${type}='${condition[1]}'` // 拼接字段作为参数
params.type = type params.type = type
} else if (type === 'idcRenter') { } else if (type === 'idcRenter') {
params.q = `idc_renter='${condition[1]}'` params.q = `idc_renter='${condition[1]}'` // 拼接字段作为参数
params.type = type params.type = type
} else { } else {
params.q = `${condition[0]}'${condition[1]}'` params.q = `${condition[0]}'${condition[1]}'` // 拼接字段作为参数
params.type = type params.type = type
} }
} }
// 区分 3 级菜单和 2 级菜单使用不同的 url
if (parseFloat(this.tabOperationType) === 3) { if (parseFloat(this.tabOperationType) === 3) {
url = api.npm.overview.allNetworkAnalysis url = api.npm.overview.allNetworkAnalysis
} else { } else {
@@ -172,7 +173,8 @@ export default {
if ((type && condition) || type) { if ((type && condition) || type) {
params.type = params.type || type params.type = params.type || type
this.toggleLoading(true) this.toggleLoading(true)
get(url, params).then(res => { axios.get(url, { params: params }).then(res => {
res = res.data
if (res.code === 200) { if (res.code === 200) {
this.npmNetworkCycleData = res.data.result this.npmNetworkCycleData = res.data.result
} }
@@ -182,21 +184,21 @@ export default {
this.toggleLoading(false) this.toggleLoading(false)
}) })
} else { } else {
const tcp = get(api.npm.overview.tcpSessionDelay, params) const tcp = axios.get(api.npm.overview.tcpSessionDelay, { params: params })
const http = get(api.npm.overview.httpResponseDelay, params) const http = axios.get(api.npm.overview.httpResponseDelay, { params: params })
const ssl = get(api.npm.overview.sslConDelay, params) const ssl = axios.get(api.npm.overview.sslConDelay, { params: params })
const tcpPercent = get(api.npm.overview.tcpLostlenPercent, params) const tcpPercent = axios.get(api.npm.overview.tcpLostlenPercent, { params: params })
const packetPercent = get(api.npm.overview.packetRetransPercent, params) const packetPercent = axios.get(api.npm.overview.packetRetransPercent, { params: params })
this.toggleLoading(true) this.toggleLoading(true)
Promise.all([tcp, http, ssl, tcpPercent, packetPercent]).then(res => { Promise.all([tcp, http, ssl, tcpPercent, packetPercent]).then(res => {
// 状态为200的赋值接口数据不为200的传入报错提示message // 状态为200的赋值接口数据不为200的传入报错提示message
// 传给子组件SingleValue再进行error处理error处理不在此处处理 // 传给子组件SingleValue再进行error处理error处理不在此处处理
this.npmNetworkCycleData = [] this.npmNetworkCycleData = []
res.forEach(t => { res.forEach(t => {
if (t.code === 200) { if (t.data.code === 200) {
this.npmNetworkCycleData.push(t.data.result) this.npmNetworkCycleData.push(t.data.data.result)
} else { } else {
this.npmNetworkCycleData.push(t) this.npmNetworkCycleData.push(t.data)
} }
}) })
this.npmNetworkLastCycleQuery() this.npmNetworkLastCycleQuery()
@@ -226,7 +228,8 @@ export default {
if ((params.type && params.q) || (param && param.type)) { if ((params.type && params.q) || (param && param.type)) {
params.type = params.type || param.type params.type = params.type || param.type
this.toggleLoading(true) this.toggleLoading(true)
get(url, params).then(res => { axios.get(url, { params: params }).then(res => {
res = res.data
if (res.code === 200) { if (res.code === 200) {
this.npmNetworkLastCycleData = res.data.result this.npmNetworkLastCycleData = res.data.result
} else { } else {
@@ -244,20 +247,20 @@ export default {
this.toggleLoading(false) this.toggleLoading(false)
}) })
} else { } else {
const tcp = get(api.npm.overview.tcpSessionDelay, params) const tcp = axios.get(api.npm.overview.tcpSessionDelay, { params: params })
const http = get(api.npm.overview.httpResponseDelay, params) const http = axios.get(api.npm.overview.httpResponseDelay, { params: params })
const ssl = get(api.npm.overview.sslConDelay, params) const ssl = axios.get(api.npm.overview.sslConDelay, { params: params })
const tcpPercent = get(api.npm.overview.tcpLostlenPercent, params) const tcpPercent = axios.get(api.npm.overview.tcpLostlenPercent, { params: params })
const packetPercent = get(api.npm.overview.packetRetransPercent, params) const packetPercent = axios.get(api.npm.overview.packetRetransPercent, { params: params })
this.toggleLoading(true) this.toggleLoading(true)
Promise.all([tcp, http, ssl, tcpPercent, packetPercent]).then(res => { Promise.all([tcp, http, ssl, tcpPercent, packetPercent]).then(res => {
// 状态为200的赋值接口数据不为200的保留报错提示message // 状态为200的赋值接口数据不为200的保留报错提示message
// 传给子组件SingleValue再进行error处理error处理不在此处处理 // 传给子组件SingleValue再进行error处理error处理不在此处处理
res.forEach(t => { res.forEach(t => {
if (t.code === 200) { if (t.data.code === 200) {
this.npmNetworkLastCycleData.push(t.data.result) this.npmNetworkLastCycleData.push(t.data.data.result)
} else { } else {
this.npmNetworkLastCycleData.push(t) this.npmNetworkLastCycleData.push(t.data)
} }
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 1) this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 1)
}) })

File diff suppressed because one or more lines are too long