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"
|
|
|
|
|
:extra-params="extraParams"
|
2022-07-18 15:04:32 +08:00
|
|
|
:id="item.id"
|
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-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,
|
|
|
|
|
debounceFunc: null
|
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
|
|
|
|
|
|
|
|
/*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-10-25 18:41:27 +08:00
|
|
|
}*/
|
|
|
|
|
this.layout = layout
|
|
|
|
|
const overviewAppChart = layout.find(c => c.type === typeMapping.networkOverview.appList)
|
|
|
|
|
if (overviewAppChart) {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.resizeAppChart()
|
|
|
|
|
})
|
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
|
|
|
},
|
|
|
|
|
resizeAppChart () {
|
|
|
|
|
const appCardsDom = document.querySelector('.app-cards')
|
|
|
|
|
const layout = _.cloneDeep(this.layout)
|
|
|
|
|
const overviewAppChart = layout.find(c => c.type === typeMapping.networkOverview.appList)
|
|
|
|
|
if (appCardsDom) {
|
|
|
|
|
const cardsHeight = appCardsDom.offsetHeight
|
|
|
|
|
if (cardsHeight) {
|
|
|
|
|
const headerHeight = 24
|
|
|
|
|
overviewAppChart.h = (cardsHeight + headerHeight + this.rowMargin) / (this.rowHeight + this.rowMargin)
|
|
|
|
|
this.layout = layout
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-18 16:09:13 +08:00
|
|
|
}
|
2022-10-25 18:41:27 +08:00
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
this.debounceFunc = _.debounce(this.resizeAppChart, 400)
|
|
|
|
|
window.addEventListener('resize', this.debounceFunc)
|
|
|
|
|
},
|
|
|
|
|
beforeUnmount () {
|
|
|
|
|
window.removeEventListener('resize', this.debounceFunc)
|
2022-07-06 21:08:12 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|