From ebf1228c68441bf93b1f1406d10210d66e9c138e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B4=AA=E6=B4=AA?= <2498601771@qq.com> Date: Fri, 18 Nov 2022 16:25:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BD=93=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=94=E5=9B=9E=E4=B8=BA-=E6=97=B6=EF=BC=8CRelated?= =?UTF-8?q?=20sessions=E7=81=B0=E6=9D=A1=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BB=A5=E5=8F=8A=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=97=B6=E9=97=B4=EF=BC=8Cdom=E6=9C=AA=E5=81=9A?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../charts2/charts/npm/RelatedSessions.vue | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/views/charts2/charts/npm/RelatedSessions.vue b/src/views/charts2/charts/npm/RelatedSessions.vue index cc0f0fb0..bc53f4f1 100644 --- a/src/views/charts2/charts/npm/RelatedSessions.vue +++ b/src/views/charts2/charts/npm/RelatedSessions.vue @@ -84,23 +84,37 @@ export default { this.isNoData = false this.sessionData = res.data.result - // * 1 是将其转为number,避免相加变成字符串拼接 - this.clientSessions = this.sessionData.clientSessions / (this.sessionData.clientSessions * 1 + this.sessionData.serverSessions * 1) - this.serverSessions = this.sessionData.serverSessions / (this.sessionData.clientSessions * 1 + this.sessionData.serverSessions * 1) - this.sessionData.clientSessions = unitConvert(this.clientSessions, unitTypes.percent).join('') - this.sessionData.serverSessions = unitConvert(this.serverSessions, unitTypes.percent).join('') - if (this.clientSessions === 1) { - divGreen.style.borderRadius = 4 + 'px' - } else if (this.serverSessions === 1) { - divRed.style.borderRadius = 4 + 'px' - } else if (this.clientSessions === 0 && this.serverSessions === 0) { + const client = this.sessionData.clientSessions + const server = this.sessionData.serverSessions + + // 如果返回数据为-,则不必计算比例 + if (!isNaN(client) && !isNaN(server)) { + this.clientSessions = client / (client + server) + this.serverSessions = server / (client + server) + this.sessionData.clientSessions = unitConvert(this.clientSessions, unitTypes.percent).join('') + this.sessionData.serverSessions = unitConvert(this.serverSessions, unitTypes.percent).join('') + + if (this.clientSessions === 1) { + divGreen.style.borderRadius = 4 + 'px' + } else if (this.serverSessions === 1) { + divRed.style.borderRadius = 4 + 'px' + } else if (this.clientSessions === 0 && this.serverSessions === 0) { + this.isNoData = true + divGray.style.borderRadius = 4 + 'px' + divGray.style.width = '100%' + } + + divGreen.style.width = this.sessionData.clientSessions + divRed.style.width = this.sessionData.serverSessions + } else { this.isNoData = true divGray.style.borderRadius = 4 + 'px' divGray.style.width = '100%' + this.sessionData.clientSessions = '—' + this.sessionData.serverSessions = '—' + this.clientSessions = 0 + this.serverSessions = 0 } - - divGreen.style.width = this.sessionData.clientSessions - divRed.style.width = this.sessionData.serverSessions } else { this.showError = true this.errorMsg = res.message @@ -108,6 +122,8 @@ export default { divGray.style.width = '100%' this.sessionData.clientSessions = '—' this.sessionData.serverSessions = '—' + this.clientSessions = 0 + this.serverSessions = 0 } }).catch(error => { this.showError = true @@ -116,6 +132,8 @@ export default { divGray.style.width = '100%' this.sessionData.clientSessions = '—' this.sessionData.serverSessions = '—' + this.clientSessions = 0 + this.serverSessions = 0 }).finally(() => { this.toggleLoading(false) })