2022-07-06 21:08:12 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="panel-box">
|
|
|
|
|
<div class="panel__header">
|
2022-08-24 07:29:40 +08:00
|
|
|
<div class="panel__title">{{panelName?panelName:(panel.i18n ? $t(panel.i18n) : panel.name)}}
|
|
|
|
|
<div v-if="score" class="score">
|
|
|
|
|
<div class="circle-icon" v-if="score <= 2" :class="{'data-score-red': score <= 2}" ></div>
|
|
|
|
|
<div class="circle-icon" v-else-if="score <= 4" :class="{'data-score-yellow': score <= 4}" ></div>
|
|
|
|
|
<div class="circle-icon" v-else-if="score <= 6" :class="{'data-score-green': score <= 6}" ></div>
|
|
|
|
|
Score:{{score}}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-07-06 21:08:12 +08:00
|
|
|
<div class="panel__time">
|
|
|
|
|
<date-time-range
|
|
|
|
|
class="date-time-range"
|
|
|
|
|
:start-time="timeFilter.startTime"
|
|
|
|
|
:end-time="timeFilter.endTime"
|
|
|
|
|
:date-range="timeFilter.dateRangeValue"
|
|
|
|
|
ref="dateTimeRange"
|
|
|
|
|
@change="reload"
|
|
|
|
|
/>
|
|
|
|
|
<time-refresh
|
|
|
|
|
class="date-time-range"
|
|
|
|
|
@change="timeRefreshChange"
|
|
|
|
|
:end-time="timeFilter.endTime"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<chart-list
|
|
|
|
|
ref="chartList"
|
|
|
|
|
:time-filter="timeFilter"
|
|
|
|
|
:chart-list="chartList"
|
2022-07-18 15:04:32 +08:00
|
|
|
:panel-type="panelType"
|
2022-07-06 21:08:12 +08:00
|
|
|
:panel-lock="panelLock"
|
2022-07-22 18:09:18 +08:00
|
|
|
:extra-params="extraParams"
|
2022-07-06 21:08:12 +08:00
|
|
|
:entity="entity"
|
|
|
|
|
></chart-list>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-08-23 21:42:42 +08:00
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
2022-07-06 21:08:12 +08:00
|
|
|
import { ref } from 'vue'
|
2022-08-24 07:29:40 +08:00
|
|
|
import { panelTypeAndRouteMapping, bytesColumnNameGroupForNpm, scoreUrl, customTableTitlesForAppPerformance } from '@/utils/constants'
|
2022-07-06 21:08:12 +08:00
|
|
|
import { getPanelList, getChartList } from '@/utils/api'
|
2022-08-24 07:29:40 +08:00
|
|
|
import { getNowTime, getSecond } from '@/utils/date-util'
|
2022-07-06 21:08:12 +08:00
|
|
|
import { getTypeCategory } from '@/views/charts/charts/tools'
|
2022-08-24 07:29:40 +08:00
|
|
|
import { computeScore } from '@/utils/tools'
|
2022-07-06 21:08:12 +08:00
|
|
|
import ChartList from '@/views/charts2/ChartList'
|
2022-08-24 07:29:40 +08:00
|
|
|
import { get } from '@/utils/http'
|
2022-07-06 21:08:12 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'Panel',
|
|
|
|
|
props: {
|
|
|
|
|
entity: Object,
|
|
|
|
|
typeName: String
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
ChartList
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
chartList: [], // 普通panel的chart
|
2022-07-22 18:09:18 +08:00
|
|
|
panelLock: true,
|
2022-08-05 15:46:31 +08:00
|
|
|
extraParams: {},
|
2022-08-24 07:29:40 +08:00
|
|
|
panelName: '',
|
|
|
|
|
score: null
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async mounted () {
|
2022-08-05 15:46:31 +08:00
|
|
|
this.panelName = this.$store.getters.getPanelName
|
2022-08-24 07:29:40 +08:00
|
|
|
if (this.panelName && this.$route.path === '/panel/networkAppPerformance') {
|
|
|
|
|
// let columnName = this.$store.getters.getBreadcrumbColumnName
|
|
|
|
|
const columnValue = this.$store.getters.getBreadcrumbColumnValue
|
|
|
|
|
const queryParams = {
|
|
|
|
|
startTime: getSecond(this.timeFilter.startTime),
|
|
|
|
|
endTime: getSecond(this.timeFilter.endTime),
|
|
|
|
|
type: this.$store.getters.getDimensionType,
|
|
|
|
|
params: columnValue || ''
|
|
|
|
|
}
|
|
|
|
|
const requestGroup = []
|
|
|
|
|
scoreUrl.forEach(url => {
|
|
|
|
|
if (url) {
|
|
|
|
|
const request = get(url, queryParams, true)
|
|
|
|
|
requestGroup.push(request)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
const scoreGroup = []
|
|
|
|
|
let score = 0
|
|
|
|
|
Promise.all(requestGroup).then(res => {
|
|
|
|
|
res.forEach(t => {
|
|
|
|
|
if (t.code === 200) {
|
|
|
|
|
const data = t.data.result ? t.data.result[0] : null
|
|
|
|
|
if (data) {
|
|
|
|
|
customTableTitlesForAppPerformance.forEach(item => {
|
|
|
|
|
if (data[bytesColumnNameGroupForNpm[item.prop]]) {
|
|
|
|
|
score = computeScore(data, item.scoreType)
|
|
|
|
|
scoreGroup.push(score)
|
|
|
|
|
} else {
|
|
|
|
|
scoreGroup.push(0)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
scoreGroup.forEach(i => {
|
|
|
|
|
score = Number(score) + Number(i)
|
|
|
|
|
})
|
|
|
|
|
score = Math.ceil(score * 6)
|
|
|
|
|
if (score > 6) {
|
|
|
|
|
score = 6
|
|
|
|
|
}
|
|
|
|
|
this.score = score || 0
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 21:08:12 +08:00
|
|
|
await this.init()
|
2022-07-26 13:54:09 +08:00
|
|
|
const vm = this
|
|
|
|
|
this.emitter.on('reloadChartList', async function () {
|
2022-08-04 12:03:15 +08:00
|
|
|
vm.chartList = []
|
2022-07-26 13:54:09 +08:00
|
|
|
vm.chartList = (await getChartList({ panelId: vm.panel.id, pageSize: -1 })).map(chart => {
|
|
|
|
|
chart.i = chart.id
|
|
|
|
|
// 递归初始化各属性
|
|
|
|
|
vm.initChartAttr(chart)
|
|
|
|
|
return chart
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-07-06 21:08:12 +08:00
|
|
|
},
|
|
|
|
|
setup (props, ctx) {
|
|
|
|
|
const panel = ref({})
|
|
|
|
|
let panelType = 1 // 取得panel的type
|
|
|
|
|
const { params } = useRoute()
|
2022-08-24 07:29:40 +08:00
|
|
|
const router = useRouter()
|
|
|
|
|
const thirdPanel = router.currentRoute.value.params.thirdPanel
|
|
|
|
|
const fourthPanel = router.currentRoute.value.params.fourthPanel
|
|
|
|
|
if (fourthPanel) {
|
2022-08-19 10:46:24 +08:00
|
|
|
panelType = Number(fourthPanel)
|
2022-08-24 07:29:40 +08:00
|
|
|
} else if (thirdPanel) {
|
2022-08-19 10:46:24 +08:00
|
|
|
panelType = Number(thirdPanel)
|
2022-08-24 07:29:40 +08:00
|
|
|
} else {
|
2022-08-19 10:46:24 +08:00
|
|
|
panelType = props.entity ? props.entity.type : panelTypeAndRouteMapping[params.typeName]
|
|
|
|
|
}
|
2022-07-06 21:08:12 +08:00
|
|
|
|
|
|
|
|
function isEntityDetail (t) {
|
|
|
|
|
return [4, 5, 6].indexOf(t) > -1
|
|
|
|
|
}
|
|
|
|
|
// date
|
|
|
|
|
const dateRangeValue = isEntityDetail(panelType) ? 60 * 24 : 60
|
|
|
|
|
const { startTime, endTime } = getNowTime(dateRangeValue)
|
|
|
|
|
const timeFilter = ref({ startTime, endTime, dateRangeValue })
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
panelType,
|
|
|
|
|
panel,
|
|
|
|
|
timeFilter
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async init () {
|
|
|
|
|
const panels = await getPanelList({ type: this.panelType })
|
|
|
|
|
if (panels && panels.length > 0) {
|
|
|
|
|
this.panel = panels[0]
|
|
|
|
|
}
|
|
|
|
|
if (this.panel.id) {
|
|
|
|
|
if (this.panel.params) {
|
|
|
|
|
this.panel.params = JSON.parse(this.panel.params)
|
|
|
|
|
} else {
|
|
|
|
|
this.panel.params = {}
|
|
|
|
|
}
|
|
|
|
|
this.chartList = (await getChartList({ panelId: this.panel.id, pageSize: -1 })).map(chart => {
|
|
|
|
|
chart.i = chart.id
|
|
|
|
|
// 递归初始化各属性
|
|
|
|
|
this.initChartAttr(chart)
|
|
|
|
|
return chart
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
initChartAttr (chart) {
|
|
|
|
|
chart.i = chart.id
|
|
|
|
|
chart.category = getTypeCategory(chart.type)
|
|
|
|
|
// 初始化params
|
|
|
|
|
chart.params = chart.params ? JSON.parse(chart.params) : {}
|
|
|
|
|
chart.firstShow = false
|
|
|
|
|
if (!this.$_.isEmpty(chart.children)) {
|
|
|
|
|
chart.children.forEach(c => {
|
|
|
|
|
this.initChartAttr(c)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-23 21:42:42 +08:00
|
|
|
reload (startTime, endTime, dateRangeValue) {
|
|
|
|
|
this.timeFilter = { startTime: startTime, endTime: endTime, dateRangeValue: dateRangeValue }
|
2022-07-06 21:08:12 +08:00
|
|
|
},
|
2022-08-23 21:42:42 +08:00
|
|
|
timeRefreshChange () {
|
|
|
|
|
// 不是自选时间
|
|
|
|
|
if (!this.$refs.dateTimeRange.isCustom) {
|
|
|
|
|
const value = this.timeFilter.dateRangeValue
|
|
|
|
|
this.$refs.dateTimeRange.quickChange(value)
|
|
|
|
|
} else {
|
|
|
|
|
this.timeFilter = JSON.parse(JSON.stringify(this.timeFilter))
|
|
|
|
|
}
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|