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

117 lines
3.6 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="[20, 20]"
:row-height="40"
: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"
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, storageKey, 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-09-07 21:32:43 +08:00
layout: []
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)) {
if (this.panelType === panelTypeAndRouteMapping.networkAppPerformance) {
this.layout = n.filter(c => c.type === typeMapping.npm.npmTabs || c.params.tabIndex === this.npmTabIndex)
} else if (Object.values(drillDownPanelTypeMapping).indexOf(this.panelType) >= -1) {
this.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-07-26 13:54:09 +08:00
this.layout = [...n]
}
2022-08-04 12:03:15 +08:00
const overviewAppChart = n.find(c => c.type === typeMapping.networkOverview.appList)
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-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()
}
2022-07-06 21:08:12 +08:00
}
}
</script>
<style scoped>
</style>