feat:group 添加折叠

This commit is contained in:
zhangyu
2022-01-21 15:35:09 +08:00
parent 4b74f3de5a
commit f5abbaeef9
6 changed files with 48 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="cn-chart"> <div class="cn-chart">
<loading :loading="loading && !isTabs && !isBlock"></loading> <loading :loading="loading && !isTabs && !isBlock && !isGroup"></loading>
<chart-no-data v-if="isNoData"></chart-no-data> <chart-no-data v-if="isNoData"></chart-no-data>
<template v-else> <template v-else>
@@ -35,6 +35,13 @@
:entity="entity" :entity="entity"
></chart-block> ></chart-block>
<chart-block
v-else-if="isGroup"
:chart-info="chartInfo"
:chart-data="chartData"
:entity="entity"
></chart-block>
<ip-basic-info <ip-basic-info
v-else-if="isIpBasicInfo" v-else-if="isIpBasicInfo"
:chart-info="chartInfo" :chart-info="chartInfo"

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="chart-header" :class="{'chart-header--title-chart': isTitle}"> <div class="chart-header" :class="{'chart-header--title-chart': isTitle}">
<div class="chart-header__title" v-if="!isCurrentTable&&(isGroup||isBlock)" :class="{'chart-header__title--block': isBlock}"> <div class="chart-header__title" v-if="!isCurrentTable&&(isGroup)" :class="{'chart-header__title--block': isBlock}">
<span @click="groupShow"> <i class="cn-icon" :class="chartInfo.params&&chartInfo.params.collapse ? 'cn-icon-arrow-right': 'cn-icon-arrow-down'"></i></span> <span @click="groupShow"> <i class="cn-icon" :class="chartInfo.params&&chartInfo.params.collpase ? 'cn-icon-arrow-right': 'cn-icon-arrow-down'"></i></span>
{{chartInfo.name}} {{chartInfo.name}}
</div> </div>
<div class="chart-header__title" v-else-if="!isCurrentTable" :class="{'chart-header__title--block': isBlock}">{{chartInfo.name}}</div> <div class="chart-header__title" v-else-if="!isCurrentTable" :class="{'chart-header__title--block': isBlock}">{{chartInfo.name}}</div>
@@ -161,8 +161,7 @@ export default {
this.dateTimeRangeChange(s, e, v) this.dateTimeRangeChange(s, e, v)
}, },
groupShow () { groupShow () {
console.log(123) this.$emit('groupShow', this.chartInfo)
this.emitter.emit('groupShow', this.chartInfo)
}, },
dateTimeRangeChange (s, e, v) { dateTimeRangeChange (s, e, v) {
this.chartTimeFilter = { startTime: s, endTime: e, dateRangeValue: v } this.chartTimeFilter = { startTime: s, endTime: e, dateRangeValue: v }

View File

@@ -45,6 +45,7 @@ import { ref } from 'vue'
import { panelTypeAndRouteMapping } from '@/utils/constants' import { panelTypeAndRouteMapping } from '@/utils/constants'
import { api, getPanelList, getChartList } from '@/utils/api' import { api, getPanelList, getChartList } from '@/utils/api'
import { getNowTime } from '@/utils/date-util' import { getNowTime } from '@/utils/date-util'
import {getGroupHeight, getTypeCategory} from "@/views/charts/charts/tools";
export default { export default {
name: 'Panel', name: 'Panel',
@@ -65,7 +66,7 @@ export default {
} }
}, },
async mounted () { async mounted () {
this.emitter.on('groupShow', this.groupShow) this.emitter.on('groupParentCalcHeight', this.groupParentCalcHeight)
this.isCryptocurrency = this.$route.path.indexOf('cryptocurrency') > -1 this.isCryptocurrency = this.$route.path.indexOf('cryptocurrency') > -1
await this.init() await this.init()
if (!this.$_.isEmpty(this.detailTabs)) { if (!this.$_.isEmpty(this.detailTabs)) {
@@ -113,6 +114,16 @@ export default {
}, },
recursionParamsConvert (chart) { recursionParamsConvert (chart) {
chart.params = chart.params ? JSON.parse(chart.params) : null chart.params = chart.params ? JSON.parse(chart.params) : null
if (chart.type === 94) {
chart.oldH = chart.h
chart.params = {
collpase: false
}
chart.h = getGroupHeight(chart.children) + 2
if (chart.params.collpase) {
chart.h = 1
}
}
if (!this.$_.isEmpty(chart.children)) { if (!this.$_.isEmpty(chart.children)) {
chart.children.forEach(c => { chart.children.forEach(c => {
this.recursionParamsConvert(c) this.recursionParamsConvert(c)
@@ -142,9 +153,8 @@ export default {
this.$refs[`chart-${chart.id}`] && this.$refs[`chart-${chart.id}`].reloadChart() this.$refs[`chart-${chart.id}`] && this.$refs[`chart-${chart.id}`].reloadChart()
}) })
}, },
groupShow (chart) { groupParentCalcHeight (params) {
console.log( this.$refs.panelChartList,chart) this.$refs.panelChartList.groupParentCalcHeight(params.chart, params.childrenList)
this.$refs.panelChartList.groupShow(chart)
} }
} }
} }

View File

@@ -15,6 +15,7 @@
:table="table" :table="table"
@loadMore="loadMore" @loadMore="loadMore"
@refresh="refresh" @refresh="refresh"
@groupShow="groupShow"
@showFullscreen="showFullscreen" @showFullscreen="showFullscreen"
@tableChange="tableChange" @tableChange="tableChange"
></chart-header> ></chart-header>
@@ -22,7 +23,7 @@
<!-- 数据查询后传入chart组件chart组件内不查询只根据接传递的数据来渲染 --> <!-- 数据查询后传入chart组件chart组件内不查询只根据接传递的数据来渲染 -->
<chart <chart
ref="chart" ref="chart"
v-if="((!isBlock) || !(chartInfo.params && chartInfo.params.collapse)) && !isTitle" v-if="(!isGroup) || !(chartInfo.params && chartInfo.params.collpase) && !isTitle"
:chart-data="chartData" :chart-data="chartData"
:result-type="resultType" :result-type="resultType"
:chart-info="chartInfo" :chart-info="chartInfo"
@@ -306,7 +307,10 @@ export default {
}, },
getTargetPageData (pageNum, pageSize, tableData) { getTargetPageData (pageNum, pageSize, tableData) {
return this.$_.slice(tableData, (pageNum - 1) * pageSize, pageNum * pageSize) return this.$_.slice(tableData, (pageNum - 1) * pageSize, pageNum * pageSize)
} },
groupShow (chartInfo) {
this.$emit('groupShow',chartInfo)
},
}, },
mounted () { mounted () {
this.showLoading(true) this.showLoading(true)

View File

@@ -33,6 +33,7 @@
:show-header="true" :show-header="true"
:time-filter="timeFilter" :time-filter="timeFilter"
:entity="entity" :entity="entity"
@groupShow="groupShow"
@showFullscreen="showFullscreen" @showFullscreen="showFullscreen"
></panel-chart> ></panel-chart>
</grid-item> </grid-item>
@@ -65,7 +66,7 @@
<script> <script>
import PanelChart from '@/views/charts/PanelChart' import PanelChart from '@/views/charts/PanelChart'
import VueGridLayout from 'vue-grid-layout' import VueGridLayout from 'vue-grid-layout'
import { getTypeCategory } from './charts/tools' import { getGroupHeight, getTypeCategory } from './charts/tools'
import _ from 'lodash' import _ from 'lodash'
export default { export default {
@@ -114,18 +115,28 @@ export default {
this.fullscreen.visible = show this.fullscreen.visible = show
}, },
groupShow (chart) { groupShow (chart) {
console.log(chart, this.copyDataList)
this.copyDataList.forEach((item, index) => { this.copyDataList.forEach((item, index) => {
if (item.id === chart.id) { if (item.id === chart.id) {
item.params.collpase = !item.params.collpase item.params.collpase = !item.params.collpase
if (item.params.collpase) { if (item.params.collpase) {
item.h = 1 item.h = 1
} else { } else {
item.h = item.oldH item.h = getGroupHeight(item.children) + 2
} }
} }
}) })
this.copyDataList = [...this.copyDataList] this.copyDataList = [...this.copyDataList]
this.emitter.emit('groupParentCalcHeight', { chart, childrenList: this.copyDataList })
},
groupParentCalcHeight (chart, childrenList) {
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
parent.h = getGroupHeight(childrenList) + 2
this.copyDataList = [...this.copyDataList]
}, 100)
} }
}, },
computed: { computed: {
@@ -146,17 +157,11 @@ export default {
handler (n, o) { handler (n, o) {
this.gridLayoutShow = false this.gridLayoutShow = false
this.gridLayoutLoading = true this.gridLayoutLoading = true
// const arr = this.$_.cloneDeep(n)
this.noData = !n || n.length < 1 this.noData = !n || n.length < 1
const tempList = n.map(item => { const tempList = n.map(item => {
if (item.params) { if (item.params) {
item.params.showHeader = true item.params.showHeader = true
if (item.type === 95 || item.type === 94) {
item.oldH = item.h
item.params.collpase = false
}
if (item.params.collpase) {
item.h = this.rowHeight
}
} }
const height = item.h const height = item.h
return { return {

View File

@@ -213,8 +213,8 @@ export function getGroupHeight (arr) {
}) })
let maxHeight = 0 let maxHeight = 0
lastItem.forEach(last => { lastItem.forEach(last => {
if (maxHeight < last.height) { if (maxHeight < last.h) {
maxHeight = last.height maxHeight = last.h
} }
}) })
if (maxY < 0) { if (maxY < 0) {