2021-06-11 23:00:33 +08:00
|
|
|
<template>
|
2021-06-22 21:19:04 +08:00
|
|
|
<div style="padding: 10px 0 20px 20px;">
|
2021-08-09 14:25:43 +08:00
|
|
|
<div v-if="typeName" class="entity-detail-tool">
|
2021-08-09 13:38:32 +08:00
|
|
|
<div>
|
2021-08-09 14:25:43 +08:00
|
|
|
<span @click="goBack" style="cursor: pointer;"><i class="cn-icon cn-icon-arrow-left-circle"></i></span>
|
2021-08-09 13:38:32 +08:00
|
|
|
</div>
|
2021-08-09 14:25:43 +08:00
|
|
|
<el-radio-group v-model="tab" size="mini" @change="changeTab">
|
2021-08-09 13:38:32 +08:00
|
|
|
<el-radio-button v-for="tab in tabs" :key="tab.key" :label="tab.label"></el-radio-button>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</div>
|
2021-07-06 16:34:10 +08:00
|
|
|
<div class="cn-panel" id="cn-panel">
|
2021-06-22 21:19:04 +08:00
|
|
|
<div class="panel__time">
|
2021-07-21 22:46:08 +08:00
|
|
|
<DateTimeRange class="date-time-range" :start-time="timeFilter.startTime" :end-time="timeFilter.endTime" ref="dateTimeRange" @change="reload"/>
|
|
|
|
|
<TimeRefresh class="date-time-range" @change="timeRefreshChange" :end-time="timeFilter.endTime"/>
|
2021-06-22 21:19:04 +08:00
|
|
|
</div>
|
2021-08-06 15:03:30 +08:00
|
|
|
<chart v-for="chart in chartList" :key="chart.id" :chart="chart" :time-filter="timeFilter" :ref="`chart-${chart.id}`" :entity="entity"></chart>
|
2021-06-21 11:29:26 +08:00
|
|
|
<!-- <grid-layout v-model:layout="chartList"
|
|
|
|
|
:col-num="12"
|
|
|
|
|
:row-height="30"
|
|
|
|
|
:is-draggable="draggable"
|
|
|
|
|
:is-resizable="resizable"
|
|
|
|
|
:vertical-compact="compact"
|
|
|
|
|
:use-css-transforms="true"
|
|
|
|
|
>
|
|
|
|
|
<grid-item v-for="item in chartList" :key="item.i"
|
|
|
|
|
:x="item.x"
|
|
|
|
|
:y="item.y"
|
|
|
|
|
:w="item.w"
|
|
|
|
|
:h="item.h"
|
|
|
|
|
:i="item.i"
|
|
|
|
|
>
|
|
|
|
|
<span class="text">{{ item.i }}</span>
|
|
|
|
|
</grid-item>
|
|
|
|
|
</grid-layout>-->
|
|
|
|
|
</div>
|
2021-06-20 13:31:55 +08:00
|
|
|
</div>
|
2021-06-11 23:00:33 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { useRoute } from 'vue-router'
|
2021-07-21 22:46:08 +08:00
|
|
|
import { ref } from 'vue'
|
2021-06-11 23:00:33 +08:00
|
|
|
import { panelTypeAndRouteMapping } from '@/utils/constants'
|
2021-06-20 13:31:55 +08:00
|
|
|
import { api, getPanelList, getChartList } from '@/utils/api'
|
2021-06-21 18:41:17 +08:00
|
|
|
import { getNowTime } from '@/utils/date-util'
|
2021-06-20 13:31:55 +08:00
|
|
|
import Chart from './Chart'
|
2021-06-21 11:29:26 +08:00
|
|
|
import DateTimeRange from '@/components/common/TimeRange/DateTimeRange'
|
2021-06-22 17:07:46 +08:00
|
|
|
import TimeRefresh from '@/components/common/TimeRange/TimeRefresh'
|
2021-08-09 13:38:32 +08:00
|
|
|
import _ from 'lodash'
|
2021-06-11 23:00:33 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'Panel',
|
2021-08-02 13:22:15 +08:00
|
|
|
props: {
|
|
|
|
|
typeName: String,
|
2021-08-09 13:38:32 +08:00
|
|
|
entity: Object,
|
|
|
|
|
tabs: Array
|
2021-08-02 13:22:15 +08:00
|
|
|
},
|
2021-06-20 13:31:55 +08:00
|
|
|
components: {
|
2021-06-21 11:29:26 +08:00
|
|
|
Chart,
|
2021-06-22 17:07:46 +08:00
|
|
|
DateTimeRange,
|
|
|
|
|
TimeRefresh
|
2021-06-20 13:31:55 +08:00
|
|
|
},
|
2021-06-11 23:00:33 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
2021-07-21 22:46:08 +08:00
|
|
|
chartList: []
|
2021-06-11 23:00:33 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async mounted () {
|
2021-06-29 19:45:44 +08:00
|
|
|
await this.init()
|
2021-06-11 23:00:33 +08:00
|
|
|
},
|
2021-06-21 18:41:17 +08:00
|
|
|
setup (props, ctx) {
|
2021-08-09 13:38:32 +08:00
|
|
|
let tab = ''
|
|
|
|
|
if (!_.isEmpty(props.tabs)) {
|
2021-08-09 14:25:43 +08:00
|
|
|
tab = ref(props.tabs[0].label)
|
2021-08-09 13:38:32 +08:00
|
|
|
}
|
2021-06-21 18:41:17 +08:00
|
|
|
// data
|
2021-07-21 22:46:08 +08:00
|
|
|
const dateRangeValue = 60
|
|
|
|
|
const { startTime, endTime } = getNowTime(dateRangeValue)
|
2021-07-22 18:30:45 +08:00
|
|
|
const timeFilter = ref({ startTime, endTime, dateRangeValue })
|
2021-06-20 13:31:55 +08:00
|
|
|
const panel = ref({})
|
|
|
|
|
let panelType = 1 // 取得panel的type
|
2021-06-11 23:00:33 +08:00
|
|
|
const { params } = useRoute()
|
2021-08-02 13:22:15 +08:00
|
|
|
panelType = props.typeName ? panelTypeAndRouteMapping[props.typeName] : panelTypeAndRouteMapping[params.typeName]
|
2021-06-11 23:00:33 +08:00
|
|
|
return {
|
|
|
|
|
panelType,
|
2021-06-20 13:31:55 +08:00
|
|
|
panel,
|
2021-07-21 22:46:08 +08:00
|
|
|
timeFilter,
|
2021-08-09 13:38:32 +08:00
|
|
|
api,
|
|
|
|
|
tab
|
2021-06-11 23:00:33 +08:00
|
|
|
}
|
2021-06-22 17:07:46 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2021-08-09 14:25:43 +08:00
|
|
|
goBack () {
|
|
|
|
|
this.$emit('goBack')
|
|
|
|
|
},
|
|
|
|
|
changeTab (label) {
|
|
|
|
|
},
|
2021-06-22 17:07:46 +08:00
|
|
|
async init () {
|
2021-06-29 19:45:44 +08:00
|
|
|
const panels = await getPanelList({ type: this.panelType })
|
|
|
|
|
if (panels && panels.length > 0) {
|
|
|
|
|
this.panel = panels[0]
|
|
|
|
|
}
|
|
|
|
|
if (this.panel.id) {
|
|
|
|
|
this.chartList = (await getChartList({ panelId: this.panel.id, pageSize: -1 })).map(chart => {
|
|
|
|
|
chart.i = chart.id
|
2021-08-02 13:22:15 +08:00
|
|
|
this.recursionParamsConvert(chart)
|
2021-06-29 19:45:44 +08:00
|
|
|
return chart
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-06-22 17:07:46 +08:00
|
|
|
},
|
2021-08-02 13:22:15 +08:00
|
|
|
recursionParamsConvert (chart) {
|
|
|
|
|
chart.params = chart.params ? JSON.parse(chart.params) : null
|
|
|
|
|
if (!this.$_.isEmpty(chart.children)) {
|
|
|
|
|
chart.children.forEach(c => {
|
|
|
|
|
this.recursionParamsConvert(c)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-21 22:46:08 +08:00
|
|
|
timeRefreshChange () {
|
2021-07-22 18:30:45 +08:00
|
|
|
if (!this.$refs.dateTimeRange.isCustom) {
|
|
|
|
|
const value = this.timeFilter.dateRangeValue
|
|
|
|
|
this.$refs.dateTimeRange.quickChange(value)
|
|
|
|
|
}
|
|
|
|
|
/* if (!this.$refs.dateTimeRange) {
|
2021-07-21 22:46:08 +08:00
|
|
|
this.reloadCharts()
|
2021-06-22 17:07:46 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.$refs.dateTimeRange.isCustom) {
|
2021-07-21 22:46:08 +08:00
|
|
|
this.reloadCharts()
|
2021-06-22 17:07:46 +08:00
|
|
|
} else {
|
2021-07-21 22:46:08 +08:00
|
|
|
const value = this.timeFilter.dateRangeValue
|
2021-06-22 17:07:46 +08:00
|
|
|
this.$refs.dateTimeRange.quickChange(value)
|
2021-07-22 18:30:45 +08:00
|
|
|
} */
|
2021-06-22 17:07:46 +08:00
|
|
|
},
|
2021-07-21 22:46:08 +08:00
|
|
|
reload (s, e, v) {
|
2021-06-22 17:07:46 +08:00
|
|
|
this.dateTimeRangeChange(s, e, v)
|
2021-07-22 18:30:45 +08:00
|
|
|
/* this.$nextTick(() => {
|
|
|
|
|
this.reloadCharts()
|
|
|
|
|
}) */
|
2021-07-21 22:46:08 +08:00
|
|
|
},
|
|
|
|
|
// methods
|
|
|
|
|
dateTimeRangeChange (s, e, v) {
|
|
|
|
|
this.timeFilter = { startTime: s, endTime: e, dateRangeValue: v }
|
|
|
|
|
},
|
|
|
|
|
reloadCharts () {
|
|
|
|
|
this.chartList.forEach(chart => {
|
|
|
|
|
this.$refs[`chart-${chart.id}`] && this.$refs[`chart-${chart.id}`].reloadChart()
|
|
|
|
|
})
|
2021-06-22 17:07:46 +08:00
|
|
|
}
|
2021-06-11 23:00:33 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2021-06-20 13:31:55 +08:00
|
|
|
<style lang="scss">
|
|
|
|
|
@import '~@/components/charts/panel.scss';
|
2021-06-11 23:00:33 +08:00
|
|
|
</style>
|