feat:添加 chart-group
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
:panel-lock="panelLock"
|
:panel-lock="panelLock"
|
||||||
:isGroup="true"
|
:isGroup="true"
|
||||||
:time-range="searchTime"
|
:time-range="searchTime"
|
||||||
|
:groupInfo="chartInfo"
|
||||||
@on-refresh-time="refreshTime"
|
@on-refresh-time="refreshTime"
|
||||||
:loading="chartListLoading"
|
:loading="chartListLoading"
|
||||||
></chartList>
|
></chartList>
|
||||||
@@ -23,7 +24,7 @@ import chartFormat from '@/components/chart/chartFormat'
|
|||||||
export default {
|
export default {
|
||||||
name: 'chart-group',
|
name: 'chart-group',
|
||||||
props: {
|
props: {
|
||||||
panelLock: Boolean
|
panelLock: Boolean,
|
||||||
},
|
},
|
||||||
mixins: [chartMixin, chartFormat],
|
mixins: [chartMixin, chartFormat],
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ export default {
|
|||||||
option.tooltip[0].formatter = self.tooltipFormatter(self.isStack)
|
option.tooltip[0].formatter = self.tooltipFormatter(self.isStack)
|
||||||
myChart.setOption(option)
|
myChart.setOption(option)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
resize () {
|
||||||
|
getChart(this.chartId).resize()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const chartTreemapOption = {
|
|||||||
type: 'treemap',
|
type: 'treemap',
|
||||||
visibleMin: 40,
|
visibleMin: 40,
|
||||||
childrenVisibleMin: 40,
|
childrenVisibleMin: 40,
|
||||||
|
nodeClick: false,
|
||||||
label: {
|
label: {
|
||||||
show: true,
|
show: true,
|
||||||
position: 'inside',
|
position: 'inside',
|
||||||
|
|||||||
@@ -83,6 +83,30 @@ export function isGroup (type) {
|
|||||||
return type === chartType.group
|
return type === chartType.group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getGroupHeight (arr) {
|
||||||
|
if (arr.length) {
|
||||||
|
let lastItem = []
|
||||||
|
let maxY = 0
|
||||||
|
arr.forEach((children, index) => {
|
||||||
|
if (maxY == children.y) {
|
||||||
|
lastItem.push(children)
|
||||||
|
} else {
|
||||||
|
maxY = children.y
|
||||||
|
lastItem = [children]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
let maxHeight = 0
|
||||||
|
lastItem.forEach(last => {
|
||||||
|
if (maxHeight < last.height) {
|
||||||
|
maxHeight = last.height
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return maxHeight + maxY
|
||||||
|
} else {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function initColor (colorNum = 20) {
|
export function initColor (colorNum = 20) {
|
||||||
const colorList = [
|
const colorList = [
|
||||||
'#FF5200', '#3685FF', '#FF8D00', '#00DCA2',
|
'#FF5200', '#3685FF', '#FF8D00', '#00DCA2',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="{'chart-header--float': !chartInfo.param.showHeader}" class="chart-header">
|
<div :class="{'chart-header--float': !chartInfo.param.showHeader}" class="chart-header">
|
||||||
<div class="chart-header__title">{{chartInfo.name}}</div>
|
<div class="chart-header__title" v-if="!isGroup">{{chartInfo.name}}</div>
|
||||||
|
<div class="chart-header__title" v-else @click="groupShow"> > {{chartInfo.name}}</div>
|
||||||
<div class="chart-header__tools">
|
<div class="chart-header__tools">
|
||||||
<span v-if="chartInfo.remark" class="chart-header__tool">
|
<span v-if="chartInfo.remark" class="chart-header__tool">
|
||||||
<el-tooltip :content="chartInfo.remark" effect="light" placement="top">
|
<el-tooltip :content="chartInfo.remark" effect="light" placement="top">
|
||||||
@@ -51,6 +52,10 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
chartInfo: Object,
|
chartInfo: Object,
|
||||||
from: String,
|
from: String,
|
||||||
|
isGroup: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
error: {
|
error: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
@@ -90,6 +95,9 @@ export default {
|
|||||||
},
|
},
|
||||||
clickos () {
|
clickos () {
|
||||||
this.dropdownMenuShow = false
|
this.dropdownMenuShow = false
|
||||||
|
},
|
||||||
|
groupShow () {
|
||||||
|
this.$emit('groupShow', !this.chartInfo.param.collapse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :id='`chartList${(isGroup ? "Group" : "") + timestamp}`' class="chart-list" :loading="gridLayoutLoading">
|
<div :id='`chartList${(isGroup ? "Group" : "") + timestamp}`' class="chart-list" :loading="gridLayoutLoading">
|
||||||
<grid-layout
|
<grid-layout
|
||||||
v-if="gridLayoutShow"
|
ref="layout"
|
||||||
:col-num="12"
|
:col-num="12"
|
||||||
:is-draggable="!panelLock"
|
:is-draggable="!panelLock"
|
||||||
:is-resizable="!panelLock"
|
:is-resizable="!panelLock"
|
||||||
@@ -19,10 +19,13 @@
|
|||||||
:w="item.w"
|
:w="item.w"
|
||||||
:x="item.x"
|
:x="item.x"
|
||||||
:y="item.y"
|
:y="item.y"
|
||||||
|
:minH="headerH"
|
||||||
dragAllowFrom=".chart-header"
|
dragAllowFrom=".chart-header"
|
||||||
dragIgnoreFrom=".chart-header__tools"
|
dragIgnoreFrom=".chart-header__tools"
|
||||||
@resize="resizeEvent"
|
@resize="resizeEvent"
|
||||||
@resized="resizedEvent"
|
@resized="resizedEvent"
|
||||||
|
@moveEvent="moveEvent"
|
||||||
|
@movedEvent="movedEvent"
|
||||||
@container-resized="containerResizedEvent"
|
@container-resized="containerResizedEvent"
|
||||||
>
|
>
|
||||||
<panel-chart
|
<panel-chart
|
||||||
@@ -66,7 +69,9 @@
|
|||||||
<script>
|
<script>
|
||||||
import VueGridLayout from 'vue-grid-layout'
|
import VueGridLayout from 'vue-grid-layout'
|
||||||
import { fromRoute } from '@/components/common/js/constants'
|
import { fromRoute } from '@/components/common/js/constants'
|
||||||
|
import { getGroupHeight } from './chart/tools'
|
||||||
import panelChart from '@/components/chart/panelChart'
|
import panelChart from '@/components/chart/panelChart'
|
||||||
|
import bus from '@/libs/bus'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'chartList',
|
name: 'chartList',
|
||||||
@@ -77,6 +82,7 @@ export default {
|
|||||||
timeRange: Array, // 时间范围
|
timeRange: Array, // 时间范围
|
||||||
panelLock: { type: Boolean, default: true },
|
panelLock: { type: Boolean, default: true },
|
||||||
isGroup: { type: Boolean, default: false },
|
isGroup: { type: Boolean, default: false },
|
||||||
|
groupInfo: {},
|
||||||
dataList: Array // 看板中所有图表信息
|
dataList: Array // 看板中所有图表信息
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
@@ -84,6 +90,14 @@ export default {
|
|||||||
GridItem: VueGridLayout.GridItem,
|
GridItem: VueGridLayout.GridItem,
|
||||||
panelChart
|
panelChart
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
headerH () {
|
||||||
|
return this.$store.getters.getHeaderH
|
||||||
|
},
|
||||||
|
headerHPadding () {
|
||||||
|
return this.$store.getters.getHeaderHPadding
|
||||||
|
}
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
fromRoute,
|
fromRoute,
|
||||||
@@ -112,6 +126,11 @@ export default {
|
|||||||
}
|
}
|
||||||
if (dom) {
|
if (dom) {
|
||||||
this.stepWidth = Math.floor(dom.offsetWidth / 12)
|
this.stepWidth = Math.floor(dom.offsetWidth / 12)
|
||||||
|
if (!this.isGroup) {
|
||||||
|
const headerH = 40 / this.stepWidth
|
||||||
|
const headerHPadding = 50 / this.stepWidth
|
||||||
|
this.$store.commit('setHeaderH', { headerH, headerHPadding })
|
||||||
|
}
|
||||||
const span = document.querySelector('.temp-dom')
|
const span = document.querySelector('.temp-dom')
|
||||||
this.tempDom.width = span.offsetWidth
|
this.tempDom.width = span.offsetWidth
|
||||||
}
|
}
|
||||||
@@ -128,6 +147,17 @@ export default {
|
|||||||
this.$refs['chart' + i][0].resize()
|
this.$refs['chart' + i][0].resize()
|
||||||
}, 100)
|
}, 100)
|
||||||
},
|
},
|
||||||
|
moveEvent (i, newX, newY) {
|
||||||
|
console.log(i)
|
||||||
|
if (this.isGroup) {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
movedEvent (i, newX, newY) {
|
||||||
|
if (this.isGroup) {
|
||||||
|
bus.$emit('groupMove', this.copyDataList)
|
||||||
|
}
|
||||||
|
},
|
||||||
containerResizedEvent (i, newH, newW, newHPx, newWPx) {
|
containerResizedEvent (i, newH, newW, newHPx, newWPx) {
|
||||||
// TODO 重新渲染图表
|
// TODO 重新渲染图表
|
||||||
// this.$refs['chart' + i].resize()
|
// this.$refs['chart' + i].resize()
|
||||||
@@ -137,12 +167,31 @@ export default {
|
|||||||
this.fullscreen.chartInfo = chartInfo
|
this.fullscreen.chartInfo = chartInfo
|
||||||
this.fullscreen.visible = show
|
this.fullscreen.visible = show
|
||||||
},
|
},
|
||||||
|
changeGroupHeight (copyList, group, flag) {
|
||||||
|
const height = getGroupHeight(copyList)
|
||||||
|
console.log(this.$refs.layout)
|
||||||
|
const groupFind = this.copyDataList.find(item => item.id === group.id)
|
||||||
|
if (group) {
|
||||||
|
groupFind.height = groupFind.h = height + this.headerHPadding
|
||||||
|
this.copyDataList = [...this.copyDataList]
|
||||||
|
}
|
||||||
|
if (flag) {
|
||||||
|
this.copyDataList = [...this.copyDataList]
|
||||||
|
this.$refs.layout.layoutUpdate()
|
||||||
|
}
|
||||||
|
},
|
||||||
cleanData () {
|
cleanData () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.init()
|
this.init()
|
||||||
|
if (!this.isGroup) {
|
||||||
|
bus.$on('groupMove', this.changeGroupHeight)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
dataList: {
|
dataList: {
|
||||||
@@ -176,6 +225,15 @@ export default {
|
|||||||
this.gridLayoutLoading = false
|
this.gridLayoutLoading = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
copyDataList: {
|
||||||
|
deep: true,
|
||||||
|
handler (n) {
|
||||||
|
console.log(n)
|
||||||
|
if (this.isGroup) {
|
||||||
|
bus.$emit('groupMove', n, this.groupInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,5 +242,6 @@ export default {
|
|||||||
<style scoped>
|
<style scoped>
|
||||||
.chart-list {
|
.chart-list {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ export default {
|
|||||||
this.chartId = `${this.chartInfo.id}${this.isFullscreen ? '-fullscreen' : ''}`
|
this.chartId = `${this.chartInfo.id}${this.isFullscreen ? '-fullscreen' : ''}`
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
|
getChart(this.chartId) && getChart(this.chartId).dispose()
|
||||||
setChart(this.chartId, null)
|
setChart(this.chartId, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
<!-- title和工具栏,支持浮动 -->
|
<!-- title和工具栏,支持浮动 -->
|
||||||
<chart-header
|
<chart-header
|
||||||
v-if="!isFullscreen"
|
v-if="!isFullscreen"
|
||||||
|
:is-group="isGroup(chartInfo.type)"
|
||||||
:chart-info="chartInfo"
|
:chart-info="chartInfo"
|
||||||
@edit-chart="$emit('edit-chart', chartInfo)"
|
@edit-chart="$emit('edit-chart', chartInfo)"
|
||||||
@refresh="refresh"
|
@refresh="refresh"
|
||||||
|
@groupShow="groupShow"
|
||||||
@showFullscreen="showFullscreen"
|
@showFullscreen="showFullscreen"
|
||||||
></chart-header>
|
></chart-header>
|
||||||
<!-- chart -->
|
<!-- chart -->
|
||||||
@@ -18,6 +20,7 @@
|
|||||||
:panelLock="panelLock"
|
:panelLock="panelLock"
|
||||||
:is-fullscreen="isFullscreen"
|
:is-fullscreen="isFullscreen"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
v-if="!isGroup(chartInfo.type) || chartInfo.param.collapse"
|
||||||
></chart>
|
></chart>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -25,7 +28,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import chartHeader from '@/components/chart/chartHeader'
|
import chartHeader from '@/components/chart/chartHeader'
|
||||||
import chart from '@/components/chart/chart'
|
import chart from '@/components/chart/chart'
|
||||||
import { isChartPie, isTimeSeries } from './chart/tools'
|
import { isChartPie, isTimeSeries, getGroupHeight, isGroup } from './chart/tools'
|
||||||
import { chartType, fromRoute } from '@/components/common/js/constants'
|
import { chartType, fromRoute } from '@/components/common/js/constants'
|
||||||
import bus from '@/libs/bus'
|
import bus from '@/libs/bus'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
@@ -50,7 +53,16 @@ export default {
|
|||||||
loading: true
|
loading: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
headerH () {
|
||||||
|
return this.$store.getters.getHeaderH
|
||||||
|
},
|
||||||
|
headerHPadding () {
|
||||||
|
return this.$store.getters.getHeaderHPadding
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
isGroup,
|
||||||
// 参数 isRefresh 标识是否是刷新操作
|
// 参数 isRefresh 标识是否是刷新操作
|
||||||
getChartData (isRefresh) {
|
getChartData (isRefresh) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
@@ -144,6 +156,7 @@ export default {
|
|||||||
this.chartData = [this.chartInfo.param.topo]
|
this.chartData = [this.chartInfo.param.topo]
|
||||||
}
|
}
|
||||||
if (this.chartInfo.type === 'group') {
|
if (this.chartInfo.type === 'group') {
|
||||||
|
this.groupInit()
|
||||||
this.chartData = [...this.chartInfo.children]
|
this.chartData = [...this.chartInfo.children]
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -193,8 +206,29 @@ export default {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
groupInit () {
|
||||||
|
const height = getGroupHeight(this.chartInfo.children)
|
||||||
|
if (!this.chartInfo.param.collapse) {
|
||||||
|
this.chartInfo.height = this.headerH
|
||||||
|
this.chartInfo.h = this.headerH
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.chartInfo.children.length) {
|
||||||
|
this.chartInfo.height = height + this.headerHPadding
|
||||||
|
this.chartInfo.h = height + this.headerHPadding
|
||||||
|
} else {
|
||||||
|
console.log(this.headerH)
|
||||||
|
this.chartInfo.height = this.headerH + height
|
||||||
|
this.chartInfo.h = this.headerH + height
|
||||||
|
}
|
||||||
|
},
|
||||||
showFullscreen (show) {
|
showFullscreen (show) {
|
||||||
this.$emit('showFullscreen', show, this.chartInfo)
|
this.$emit('showFullscreen', show, this.chartInfo)
|
||||||
|
},
|
||||||
|
groupShow (flag) {
|
||||||
|
this.chartInfo.param.collapse = flag
|
||||||
|
this.groupInit()
|
||||||
|
bus.$emit('groupMove', '', '', true)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|||||||
@@ -163,6 +163,9 @@ export default {
|
|||||||
Promise.all(arr).then(res => {
|
Promise.all(arr).then(res => {
|
||||||
this.editChart.panelId = this.panelId
|
this.editChart.panelId = this.panelId
|
||||||
const params = JSON.parse(JSON.stringify(this.editChart))
|
const params = JSON.parse(JSON.stringify(this.editChart))
|
||||||
|
if (params.type === 'group') {
|
||||||
|
params.height = 1
|
||||||
|
}
|
||||||
if (!params.groupId) {
|
if (!params.groupId) {
|
||||||
params.groupId = 0
|
params.groupId = 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
v-model="chartConfig.param.collapse"
|
v-model="chartConfig.param.collapse"
|
||||||
:active-value="true"
|
:active-value="true"
|
||||||
:inactive-value="false"
|
:inactive-value="false"
|
||||||
|
@change="change"
|
||||||
size="small"/>
|
size="small"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
@@ -177,7 +178,7 @@ export default {
|
|||||||
case 'group':
|
case 'group':
|
||||||
this.chartConfig.span = 12
|
this.chartConfig.span = 12
|
||||||
this.chartConfig.param = {
|
this.chartConfig.param = {
|
||||||
collapse: false
|
collapse: true
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ const panel = {
|
|||||||
groupId: '',
|
groupId: '',
|
||||||
type: '',
|
type: '',
|
||||||
timeRange: [],
|
timeRange: [],
|
||||||
nowTimeType: {}
|
nowTimeType: {},
|
||||||
|
headerH: 0.5,
|
||||||
|
headerHPadding: 0.5
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setShowRightBox (state, flag) {
|
setShowRightBox (state, flag) {
|
||||||
@@ -30,6 +32,11 @@ const panel = {
|
|||||||
setPanelNowTimeType (state, nowTimeType) {
|
setPanelNowTimeType (state, nowTimeType) {
|
||||||
state.nowTimeType = nowTimeType
|
state.nowTimeType = nowTimeType
|
||||||
},
|
},
|
||||||
|
setHeaderH (state, h) {
|
||||||
|
console.log(h)
|
||||||
|
state.headerH = h.headerH
|
||||||
|
state.headerHPadding = h.headerHPadding
|
||||||
|
},
|
||||||
cleanPanel (state) {
|
cleanPanel (state) {
|
||||||
state.showRightBox = false
|
state.showRightBox = false
|
||||||
state.chart = ''
|
state.chart = ''
|
||||||
@@ -59,6 +66,12 @@ const panel = {
|
|||||||
},
|
},
|
||||||
getDelChart (state) {
|
getDelChart (state) {
|
||||||
return state.delChart
|
return state.delChart
|
||||||
|
},
|
||||||
|
getHeaderH (state) {
|
||||||
|
return state.headerH
|
||||||
|
},
|
||||||
|
getHeaderHPadding (state) {
|
||||||
|
return state.headerHPadding
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@@ -82,6 +95,9 @@ const panel = {
|
|||||||
store.commit('setChart', playload.chart)
|
store.commit('setChart', playload.chart)
|
||||||
store.commit('setType', playload.type)
|
store.commit('setType', playload.type)
|
||||||
},
|
},
|
||||||
|
dispatchHeaderH (store, playload) {
|
||||||
|
store.commit('setHeaderH', playload.headerH)
|
||||||
|
},
|
||||||
clearPanel (store) {
|
clearPanel (store) {
|
||||||
store.commit('cleanPanel')
|
store.commit('cleanPanel')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user