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/charts/PanelChartList.vue

197 lines
5.5 KiB
Vue
Raw Normal View History

2022-01-16 23:16:00 +08:00
<template>
<div :id='`chartList${(isGroup ? "Group" : "") + timestamp}`' class="chart-list" ref="layoutBox">
<grid-layout
ref="layout"
v-if="gridLayoutShow"
v-model:layout="copyDataList"
:col-num="30"
:is-draggable="!panelLock"
:is-resizable="!panelLock"
:margin="[10, 10]"
2022-01-21 10:54:21 +08:00
:row-height="rowHeight"
2022-01-16 23:16:00 +08:00
:vertical-compact="true"
:use-css-transforms="false"
>
<grid-item
v-for="item in copyDataList"
:key="item.id"
:h="item.h"
:i="item.i"
:w="item.w"
:x="item.x"
:y="item.y"
:static="item.static"
:ref="'grid-item' + item.id"
:isResizable = "item.type === 'group' ? false: null"
dragAllowFrom=".chart-header"
dragIgnoreFrom=".chart-header__tools"
v-bind="anchorPoint(item)"
2022-01-16 23:16:00 +08:00
>
<panel-chart
:ref="'chart' + item.id"
:chart-info="item"
:show-header="true"
:time-filter="timeFilter"
:entity="entity"
2022-01-21 15:35:09 +08:00
@groupShow="groupShow"
2022-01-16 23:16:00 +08:00
@showFullscreen="showFullscreen"
></panel-chart>
</grid-item>
</grid-layout>
<!-- noData -->
<div v-if="noData" class="no-data">
<div class="no-data-div">No data</div>
</div>
<!-- 全屏查看 -->
<el-dialog
v-model="fullscreen.visible"
:show-close="false"
class="chart-fullscreen"
destroy-on-close
fullscreen
:modal-append-to-body="false"
>
<panel-chart
:ref="'chart-fullscreen' + fullscreen.chartInfo.id"
:chart-info="fullscreen.chartInfo"
:is-fullscreen="true"
:panelLock="panelLock"
:time-filter="timeFilter"
@showFullscreen="showFullscreen"
></panel-chart>
</el-dialog>
</div>
</template>
<script>
import PanelChart from '@/views/charts/PanelChart'
import VueGridLayout from 'vue-grid-layout'
2022-01-21 15:35:09 +08:00
import { getGroupHeight, getTypeCategory } from './charts/tools'
import _ from 'lodash'
2022-01-16 23:16:00 +08:00
export default {
name: 'PanelChartList',
components: {
PanelChart,
GridLayout: VueGridLayout.GridLayout,
GridItem: VueGridLayout.GridItem
},
props: {
timeFilter: Object, // 时间范围
panelLock: { type: Boolean, default: true },
isGroup: Boolean,
entity: Object,
2022-01-16 23:16:00 +08:00
dataList: Array // 看板中所有图表信息
},
data () {
return {
gridLayoutLoading: false,
gridLayoutShow: false,
2022-01-21 10:54:21 +08:00
rowHeight: 40,
2022-01-16 23:16:00 +08:00
copyDataList: [],
noData: false, // no data
tempDom: { height: '', width: '' },
stepWidth: null,
timer: null,
timestamp: new Date().getTime(),
fullscreen: {
visible: false,
chartData: [],
chartInfo: {}
},
scrollTop: 0,
scrollTopTimer: null
}
},
methods: {
init () {
const dom = document.getElementById(this.isGroup ? `chartListGroup${this.timestamp}` : `chartList${this.timestamp}`)
if (dom) {
this.stepWidth = Math.floor(dom.offsetWidth / 12)
}
},
showFullscreen (show, chartInfo) {
this.fullscreen.chartInfo = chartInfo
this.fullscreen.visible = show
2022-01-21 10:54:21 +08:00
},
groupShow (chart) {
this.copyDataList.forEach((item, index) => {
if (item.id === chart.id) {
item.params.collpase = !item.params.collpase
if (item.params.collpase) {
item.h = 1
} else {
item.h = getGroupHeight(item.children) + 1.5
2022-01-21 10:54:21 +08:00
}
}
})
this.copyDataList = [...this.copyDataList]
2022-01-21 15:35:09 +08:00
this.emitter.emit('groupParentCalcHeight', { chart, childrenList: this.copyDataList })
},
groupParentCalcHeight (chart, childrenList) {
console.log(chart, childrenList)
2022-01-21 15:35:09 +08:00
setTimeout(() => {
const parent = this.copyDataList.find(chartitem => chartitem.id === chart.parent.id)
const children = parent.children.find(item => item.id === chart.id)
children.h = chart.h
children.params = chart.params
let sumGroup = 0
childrenList.forEach(item => {
if (item.type === 94) {
sumGroup++
}
})
parent.h = getGroupHeight(childrenList) + sumGroup * 0.5
2022-01-21 15:35:09 +08:00
this.copyDataList = [...this.copyDataList]
}, 100)
2022-01-16 23:16:00 +08:00
}
},
computed: {
anchorPoint () {
return function (chart) {
if (!_.isEmpty(chart.params && chart.params.anchorPoint)) {
return { 'anchor-point': chart.params.anchorPoint }
} else {
return ''
}
}
}
},
2022-01-16 23:16:00 +08:00
watch: {
dataList: {
deep: true,
immediate: true,
2022-01-16 23:16:00 +08:00
handler (n, o) {
this.gridLayoutShow = false
this.gridLayoutLoading = true
2022-01-21 15:35:09 +08:00
// const arr = this.$_.cloneDeep(n)
2022-01-16 23:16:00 +08:00
this.noData = !n || n.length < 1
const tempList = n.map(item => {
if (item.params) {
2022-01-17 16:00:12 +08:00
item.params.showHeader = true
2022-01-16 23:16:00 +08:00
}
2022-01-21 10:54:21 +08:00
const height = item.h
2022-01-16 23:16:00 +08:00
return {
...item,
i: item.id,
w: item.w,
h: height,
x: item.x || 0,
y: item.y || 0,
2022-01-17 16:00:12 +08:00
params: item.params,
2022-01-16 23:16:00 +08:00
category: getTypeCategory(item.type) // 类别是echarts还是map等等
}
})
this.$nextTick(() => {
this.copyDataList = JSON.parse(JSON.stringify(tempList))
setTimeout(() => {
this.gridLayoutShow = true
})
this.gridLayoutLoading = false
})
}
}
}
}
</script>