2022-08-11 15:49:41 +08:00
|
|
|
|
<template>
|
2022-08-12 15:25:54 +08:00
|
|
|
|
<div class="npm-sessions">
|
2022-11-18 15:18:05 +08:00
|
|
|
|
<div class="npm-sessions-title">
|
|
|
|
|
|
{{$t('npm.relatedSessions')}}
|
|
|
|
|
|
<chart-error v-if="showError" small :content="errorMsg" />
|
|
|
|
|
|
</div>
|
2022-08-12 15:25:54 +08:00
|
|
|
|
<div class="npm-sessions-div">
|
|
|
|
|
|
<div class="npm-sessions-div-green" id="green" v-show="clientSessions > 0"></div>
|
|
|
|
|
|
<div class="npm-sessions-div-red" id="red" v-show="serverSessions > 0"></div>
|
2022-11-18 15:18:05 +08:00
|
|
|
|
<div class="npm-sessions-div-gray" id="gray" v-show="showError || isNoData"></div>
|
2022-08-12 15:25:54 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="npm-sessions-body">
|
|
|
|
|
|
<div class="npm-sessions-body-left">
|
|
|
|
|
|
<div class="npm-sessions-as-clients right">
|
|
|
|
|
|
<div class="npm-sessions-as-client">
|
|
|
|
|
|
<div class="npm-sessions-as-client-green"></div>
|
|
|
|
|
|
<div class="npm-sessions-as-client-i18n">{{$t('npm.asClient')}}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="npm-sessions-as-client-percent">{{sessionData.clientSessions}}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="npm-sessions-as-clients">
|
|
|
|
|
|
<div class="npm-sessions-as-client">
|
|
|
|
|
|
<div class="npm-sessions-as-client-red"></div>
|
2022-08-24 16:58:34 +08:00
|
|
|
|
<div class="npm-sessions-as-client-i18n">{{$t('npm.asServer')}}</div>
|
2022-08-12 15:25:54 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="npm-sessions-as-client-percent">{{sessionData.serverSessions}}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="npm-sessions-body-right">
|
|
|
|
|
|
<span class="npm-sessions-Progress-number">{{unitConvert(sessionData.sessionsRate, unitTypes.number)[0]}}</span> <span class="npm-sessions-Progress-unit">{{unitConvert(sessionData.sessionsRate, unitTypes.number)[1]}}Sessions/s</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2022-08-11 15:49:41 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-08-12 15:25:54 +08:00
|
|
|
|
import { get } from '@/utils/http'
|
|
|
|
|
|
import { api } from '@/utils/api'
|
|
|
|
|
|
import { getSecond } from '@/utils/date-util'
|
|
|
|
|
|
import unitConvert from '@/utils/unit-convert'
|
|
|
|
|
|
import { unitTypes } from '@/utils/constants'
|
2022-08-22 15:49:38 +08:00
|
|
|
|
import chartMixin from '@/views/charts2/chart-mixin'
|
2022-11-18 15:18:05 +08:00
|
|
|
|
import ChartError from '@/components/common/Error'
|
2022-08-12 15:25:54 +08:00
|
|
|
|
|
2022-08-11 15:49:41 +08:00
|
|
|
|
export default {
|
2022-08-12 15:25:54 +08:00
|
|
|
|
name: 'RelatedSessions',
|
2022-11-18 15:18:05 +08:00
|
|
|
|
components: { ChartError },
|
2022-08-22 15:49:38 +08:00
|
|
|
|
mixins: [chartMixin],
|
2022-08-12 15:25:54 +08:00
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
sessionData: {},
|
|
|
|
|
|
unitConvert,
|
|
|
|
|
|
unitTypes,
|
|
|
|
|
|
clientSessions: 0,
|
2022-11-18 15:18:05 +08:00
|
|
|
|
serverSessions: 0,
|
|
|
|
|
|
showError: false,
|
|
|
|
|
|
errorMsg: '',
|
|
|
|
|
|
noData: false,
|
|
|
|
|
|
isNoData: false
|
2022-08-12 15:25:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-24 17:09:42 +08:00
|
|
|
|
watch: {
|
|
|
|
|
|
timeFilter: {
|
2022-11-18 16:37:11 +08:00
|
|
|
|
handler () {
|
2022-08-24 17:09:42 +08:00
|
|
|
|
this.relatedSessionsData()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2022-08-12 15:25:54 +08:00
|
|
|
|
methods: {
|
|
|
|
|
|
relatedSessionsData () {
|
2022-09-20 09:33:49 +08:00
|
|
|
|
const conditionStr = this.$route.query.queryCondition ? this.$route.query.queryCondition : ''
|
|
|
|
|
|
const condition = conditionStr.split(/["|'](.*?)["|']/)
|
2022-08-12 15:25:54 +08:00
|
|
|
|
const params = {
|
|
|
|
|
|
startTime: getSecond(this.timeFilter.startTime),
|
|
|
|
|
|
endTime: getSecond(this.timeFilter.endTime),
|
2022-08-22 15:49:38 +08:00
|
|
|
|
ip: condition[1]
|
2022-08-12 15:25:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
const divGreen = document.getElementById('green')
|
2022-11-18 15:18:05 +08:00
|
|
|
|
const divRed = document.getElementById('red')
|
|
|
|
|
|
const divGray = document.getElementById('gray')
|
2022-08-12 15:25:54 +08:00
|
|
|
|
get(api.npm.overview.relatedSessions, params).then(res => {
|
|
|
|
|
|
if (res.code === 200) {
|
2022-11-18 15:18:05 +08:00
|
|
|
|
this.showError = false
|
|
|
|
|
|
this.isNoData = false
|
|
|
|
|
|
|
2022-08-12 15:25:54 +08:00
|
|
|
|
this.sessionData = res.data.result
|
2022-11-18 16:25:55 +08:00
|
|
|
|
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 {
|
2022-11-18 15:18:05 +08:00
|
|
|
|
this.isNoData = true
|
2022-11-18 16:39:10 +08:00
|
|
|
|
this.changeByErrorOrNodata()
|
2022-08-12 15:25:54 +08:00
|
|
|
|
}
|
2022-11-18 15:18:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.showError = true
|
|
|
|
|
|
this.errorMsg = res.message
|
2022-11-18 16:39:10 +08:00
|
|
|
|
this.changeByErrorOrNodata()
|
2022-08-12 15:25:54 +08:00
|
|
|
|
}
|
2022-11-18 15:18:05 +08:00
|
|
|
|
}).catch(error => {
|
|
|
|
|
|
this.showError = true
|
|
|
|
|
|
this.errorMsg = error.message
|
2022-11-18 16:39:10 +08:00
|
|
|
|
this.changeByErrorOrNodata()
|
2022-08-22 15:49:38 +08:00
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.toggleLoading(false)
|
2022-08-12 15:25:54 +08:00
|
|
|
|
})
|
2022-11-18 16:37:11 +08:00
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 当无数据或者报错时改变界面样式,出现灰条
|
|
|
|
|
|
*/
|
2022-11-18 16:39:10 +08:00
|
|
|
|
changeByErrorOrNodata () {
|
2022-11-18 16:37:11 +08:00
|
|
|
|
const divGray = document.getElementById('gray')
|
|
|
|
|
|
divGray.style.borderRadius = 4 + 'px'
|
|
|
|
|
|
divGray.style.width = '100%'
|
|
|
|
|
|
this.sessionData.clientSessions = '—'
|
|
|
|
|
|
this.sessionData.serverSessions = '—'
|
|
|
|
|
|
this.clientSessions = 0
|
|
|
|
|
|
this.serverSessions = 0
|
2022-08-12 15:25:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted () {
|
|
|
|
|
|
this.relatedSessionsData()
|
|
|
|
|
|
}
|
2022-08-11 15:49:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|