2022-07-06 21:08:12 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="chart-list" ref="layoutBox">
|
|
|
|
|
<grid-layout
|
|
|
|
|
id="gridLayout"
|
|
|
|
|
ref="layout"
|
|
|
|
|
v-model:layout="layout"
|
|
|
|
|
:col-num="24"
|
|
|
|
|
:is-draggable="!panelLock"
|
|
|
|
|
:is-resizable="!panelLock"
|
2022-10-25 18:41:27 +08:00
|
|
|
:margin="[rowMargin, colMargin]"
|
|
|
|
|
:row-height="rowHeight"
|
2022-07-06 21:08:12 +08:00
|
|
|
:vertical-compact="true"
|
|
|
|
|
:use-css-transforms="false"
|
|
|
|
|
>
|
|
|
|
|
<grid-item v-for="item in layout"
|
|
|
|
|
:x="item.x"
|
|
|
|
|
:y="item.y"
|
|
|
|
|
:w="item.w"
|
|
|
|
|
:h="item.h"
|
|
|
|
|
:i="item.i"
|
|
|
|
|
:key="item.i">
|
|
|
|
|
<chart
|
2022-07-22 18:09:18 +08:00
|
|
|
:time-filter="timeFilter"
|
2022-11-01 16:46:11 +08:00
|
|
|
:metric="metric"
|
2022-07-22 18:09:18 +08:00
|
|
|
:extra-params="extraParams"
|
2022-07-18 15:04:32 +08:00
|
|
|
:id="item.id"
|
2023-04-25 16:04:20 +08:00
|
|
|
:entity="entity"
|
2022-08-05 15:46:31 +08:00
|
|
|
ref="chartGrid"
|
2022-07-26 16:44:35 +08:00
|
|
|
@npmTabChange="npmTabChange"
|
2022-07-18 15:04:32 +08:00
|
|
|
:chart="item"
|
2022-07-06 21:08:12 +08:00
|
|
|
></chart>
|
|
|
|
|
</grid-item>
|
|
|
|
|
</grid-layout>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import VueGridLayout from 'vue-grid-layout'
|
|
|
|
|
import _ from 'lodash'
|
|
|
|
|
import Chart from '@/views/charts2/Chart'
|
2022-10-25 18:41:27 +08:00
|
|
|
import { panelTypeAndRouteMapping, drillDownPanelTypeMapping } from '@/utils/constants'
|
2022-07-18 15:04:32 +08:00
|
|
|
import { typeMapping } from '@/views/charts2/chart-tools'
|
2022-09-07 21:32:43 +08:00
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
import { ref } from 'vue'
|
2022-07-06 21:08:12 +08:00
|
|
|
export default {
|
|
|
|
|
name: 'ChartList',
|
|
|
|
|
props: {
|
|
|
|
|
timeFilter: Object,
|
2022-11-01 16:46:11 +08:00
|
|
|
metric: String,
|
2022-07-18 15:04:32 +08:00
|
|
|
panelType: Number,
|
2022-07-06 21:08:12 +08:00
|
|
|
chartList: Array,
|
|
|
|
|
panelLock: Boolean,
|
2022-07-22 18:09:18 +08:00
|
|
|
entity: Object,
|
|
|
|
|
extraParams: Object
|
2022-07-06 21:08:12 +08:00
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2022-07-18 15:04:32 +08:00
|
|
|
panelTypeAndRouteMapping,
|
|
|
|
|
typeMapping,
|
2022-10-25 18:41:27 +08:00
|
|
|
layout: [],
|
|
|
|
|
rowHeight: 40,
|
|
|
|
|
rowMargin: 20,
|
|
|
|
|
colMargin: 20,
|
2023-05-08 18:46:13 +08:00
|
|
|
debounceFunc: null,
|
|
|
|
|
timeoutFunc: null,
|
|
|
|
|
// 需要动态处理高度的chart
|
|
|
|
|
dynamicHeightCharts: [
|
|
|
|
|
{
|
|
|
|
|
selector: '.app-cards',
|
|
|
|
|
// 需要额外修正的值
|
|
|
|
|
correctionHeight: 24,
|
|
|
|
|
chartType: typeMapping.networkOverview.appList
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
selector: '.entity-detail-info',
|
2023-05-09 15:14:57 +08:00
|
|
|
correctionHeight: 161,
|
2023-05-08 18:46:13 +08:00
|
|
|
chartType: typeMapping.entityDetail.basicInfo
|
|
|
|
|
}
|
|
|
|
|
]
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
components: {
|
|
|
|
|
GridLayout: VueGridLayout.GridLayout,
|
|
|
|
|
GridItem: VueGridLayout.GridItem,
|
|
|
|
|
Chart
|
|
|
|
|
},
|
2022-09-07 21:32:43 +08:00
|
|
|
setup () {
|
|
|
|
|
const { query } = useRoute()
|
|
|
|
|
const tabIndexParam = query.tabIndex
|
|
|
|
|
const npmTabIndex = ref(tabIndexParam ? parseInt(tabIndexParam) : 0)
|
|
|
|
|
return {
|
|
|
|
|
npmTabIndex
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-07-06 21:08:12 +08:00
|
|
|
watch: {
|
2022-07-26 16:44:35 +08:00
|
|
|
chartList (n) {
|
|
|
|
|
if (!_.isEmpty(n)) {
|
2022-10-25 18:41:27 +08:00
|
|
|
let layout = []
|
2022-07-26 16:44:35 +08:00
|
|
|
if (this.panelType === panelTypeAndRouteMapping.networkAppPerformance) {
|
2022-10-25 18:41:27 +08:00
|
|
|
layout = n.filter(c => c.type === typeMapping.npm.npmTabs || c.params.tabIndex === this.npmTabIndex)
|
2022-08-24 07:29:40 +08:00
|
|
|
} else if (Object.values(drillDownPanelTypeMapping).indexOf(this.panelType) >= -1) {
|
2022-10-25 18:41:27 +08:00
|
|
|
layout = n.filter(c => c.type === typeMapping.npm.npmTabs || c.params.tabIndex === this.npmTabIndex || !c.params.hasOwnProperty('tabIndex'))
|
2022-07-26 16:44:35 +08:00
|
|
|
} else {
|
2022-10-25 18:41:27 +08:00
|
|
|
layout = [...n]
|
2022-07-26 13:54:09 +08:00
|
|
|
}
|
2022-10-25 18:41:27 +08:00
|
|
|
|
2022-12-08 16:09:46 +08:00
|
|
|
/* const overviewAppChart = layout.find(c => c.type === typeMapping.networkOverview.appList)
|
2022-08-04 12:03:15 +08:00
|
|
|
let actuallyLength = 0
|
|
|
|
|
if (overviewAppChart) {
|
|
|
|
|
const params = overviewAppChart.params.app ? overviewAppChart.params : { app: [] }
|
|
|
|
|
if (params.app.some(p => p.user === parseInt(localStorage.getItem(storageKey.userId)))) {
|
|
|
|
|
actuallyLength = params.app.find(p => p.user === parseInt(localStorage.getItem(storageKey.userId))).list.length + 1
|
|
|
|
|
} else {
|
|
|
|
|
actuallyLength = params.app.find(p => p.user === 'default').list.length + 1
|
|
|
|
|
}
|
|
|
|
|
overviewAppChart.h = actuallyLength % 3 > 0 ? (Math.floor(actuallyLength / 3) + 1) * 2 + 2 : Math.floor(actuallyLength / 3) * 2 + 2
|
2022-12-08 16:09:46 +08:00
|
|
|
} */
|
2022-10-25 18:41:27 +08:00
|
|
|
this.layout = layout
|
|
|
|
|
const overviewAppChart = layout.find(c => c.type === typeMapping.networkOverview.appList)
|
|
|
|
|
if (overviewAppChart) {
|
|
|
|
|
this.$nextTick(() => {
|
2023-05-10 11:20:31 +08:00
|
|
|
this.handleDynamicChartHeight()
|
2022-10-25 18:41:27 +08:00
|
|
|
})
|
2022-08-04 12:03:15 +08:00
|
|
|
}
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
2022-07-26 16:44:35 +08:00
|
|
|
},
|
|
|
|
|
npmTabIndex (n) {
|
2022-08-19 10:46:24 +08:00
|
|
|
if (this.panelType === panelTypeAndRouteMapping.networkAppPerformance ||
|
2022-08-24 07:29:40 +08:00
|
|
|
Object.values(drillDownPanelTypeMapping).indexOf(this.panelType) >= -1) {
|
2022-08-19 10:46:24 +08:00
|
|
|
this.layout = this.chartList.filter(c => c.type === typeMapping.npm.npmTabs || c.params.tabIndex === this.npmTabIndex || !c.params.hasOwnProperty('tabIndex'))
|
2022-07-26 16:44:35 +08:00
|
|
|
}
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
2022-07-18 16:09:13 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
npmTabChange (index) {
|
|
|
|
|
this.npmTabIndex = parseInt(index)
|
2022-08-05 15:46:31 +08:00
|
|
|
},
|
|
|
|
|
resizeLine () {
|
|
|
|
|
this.$refs.chartGrid.resizeLine()
|
2022-10-25 18:41:27 +08:00
|
|
|
},
|
2023-05-08 18:46:13 +08:00
|
|
|
// 动态处理chart高度
|
|
|
|
|
handleDynamicChartHeight () {
|
|
|
|
|
this.dynamicHeightCharts.forEach(chart => {
|
|
|
|
|
const dom = document.querySelector(chart.selector)
|
|
|
|
|
if (dom) {
|
|
|
|
|
const layout = _.cloneDeep(this.layout)
|
|
|
|
|
const destinationChart = layout.find(c => c.type === chart.chartType)
|
|
|
|
|
const domHeight = dom.offsetHeight
|
|
|
|
|
if (domHeight) {
|
|
|
|
|
destinationChart.h = (domHeight + chart.correctionHeight + this.rowMargin) / (this.rowHeight + this.rowMargin)
|
|
|
|
|
this.layout = layout
|
|
|
|
|
}
|
2022-10-25 18:41:27 +08:00
|
|
|
}
|
2023-05-08 18:46:13 +08:00
|
|
|
})
|
2022-07-18 16:09:13 +08:00
|
|
|
}
|
2022-10-25 18:41:27 +08:00
|
|
|
},
|
|
|
|
|
mounted () {
|
2023-05-08 18:46:13 +08:00
|
|
|
this.timeoutFunc = setTimeout(() => {
|
|
|
|
|
this.handleDynamicChartHeight()
|
|
|
|
|
}, 400)
|
|
|
|
|
this.handleDynamicChartHeight()
|
|
|
|
|
this.debounceFunc = _.debounce(this.handleDynamicChartHeight, 400)
|
2022-10-25 18:41:27 +08:00
|
|
|
window.addEventListener('resize', this.debounceFunc)
|
|
|
|
|
},
|
|
|
|
|
beforeUnmount () {
|
|
|
|
|
window.removeEventListener('resize', this.debounceFunc)
|
2023-05-08 18:46:13 +08:00
|
|
|
clearTimeout(this.timeoutFunc)
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|