This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/views/charts2/ChartList.vue

171 lines
5.4 KiB
Vue
Raw Normal View History

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"
: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"
: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"
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'
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,
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,
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)) {
let layout = []
2022-07-26 16:44:35 +08:00
if (this.panelType === panelTypeAndRouteMapping.networkAppPerformance) {
layout = n.filter(c => c.type === typeMapping.npm.npmTabs || c.params.tabIndex === this.npmTabIndex)
} else if (Object.values(drillDownPanelTypeMapping).indexOf(this.panelType) >= -1) {
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 {
layout = [...n]
2022-07-26 13:54:09 +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
} */
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-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) {
if (this.panelType === panelTypeAndRouteMapping.networkAppPerformance ||
Object.values(drillDownPanelTypeMapping).indexOf(this.panelType) >= -1) {
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
}
},
methods: {
npmTabChange (index) {
this.npmTabIndex = parseInt(index)
},
resizeLine () {
this.$refs.chartGrid.resizeLine()
},
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
}
}
2023-05-08 18:46:13 +08:00
})
}
},
mounted () {
2023-05-08 18:46:13 +08:00
this.timeoutFunc = setTimeout(() => {
this.handleDynamicChartHeight()
}, 500)
2023-05-08 18:46:13 +08:00
this.handleDynamicChartHeight()
this.debounceFunc = _.debounce(this.handleDynamicChartHeight, 500)
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>