2021-06-11 23:00:33 +08:00
|
|
|
<template>
|
2022-01-16 23:16:00 +08:00
|
|
|
<div style="padding: 10px 10px 20px 10px; overflow: auto" v-if="!isEntityDetail">
|
|
|
|
|
<div id="cn-panel" class="cn-panel2">
|
2021-06-22 21:19:04 +08:00
|
|
|
<div class="panel__time">
|
2022-01-18 23:12:03 +08:00
|
|
|
<date-time-range class="date-time-range" :start-time="timeFilter.startTime" :end-time="timeFilter.endTime" ref="dateTimeRange" @change="reload"/>
|
|
|
|
|
<time-refresh class="date-time-range" @change="timeRefreshChange" :end-time="timeFilter.endTime"/>
|
2021-06-22 21:19:04 +08:00
|
|
|
</div>
|
2022-01-16 23:16:00 +08:00
|
|
|
<panel-chart-list
|
|
|
|
|
:time-filter="timeFilter"
|
|
|
|
|
:data-list="chartList"
|
|
|
|
|
:panel-lock="panelLock"
|
|
|
|
|
>
|
|
|
|
|
</panel-chart-list>
|
2021-06-21 11:29:26 +08:00
|
|
|
</div>
|
2021-06-20 13:31:55 +08:00
|
|
|
</div>
|
2021-09-15 12:19:13 +08:00
|
|
|
<div class="cn-entity-detail" id="cn-entity-detail" v-else>
|
|
|
|
|
<div class="entity-detail__body">
|
2022-01-18 23:12:03 +08:00
|
|
|
<div class="cn-panel2" id="cn-panel">
|
|
|
|
|
<panel-chart-list
|
|
|
|
|
:time-filter="timeFilter"
|
|
|
|
|
:data-list="chartList"
|
|
|
|
|
:panel-lock="panelLock"
|
|
|
|
|
:entity="entity"
|
|
|
|
|
>
|
|
|
|
|
</panel-chart-list>
|
|
|
|
|
<!-- <template v-for="chart in chartList" :key="chart.id">
|
|
|
|
|
<chart
|
2022-01-03 22:46:22 +08:00
|
|
|
:chart="chart"
|
|
|
|
|
:ref="`chart-${chart.id}`"
|
|
|
|
|
:entity="entity"
|
|
|
|
|
@getCurrentTimeRange="getCurrentTimeRange"
|
2022-01-18 23:12:03 +08:00
|
|
|
></chart>
|
|
|
|
|
</template>-->
|
2021-09-15 12:19:13 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</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-11 23:00:33 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'Panel',
|
2021-08-02 13:22:15 +08:00
|
|
|
props: {
|
2021-08-09 13:38:32 +08:00
|
|
|
entity: Object,
|
2022-01-03 22:46:22 +08:00
|
|
|
isEntityDetail: Boolean,
|
|
|
|
|
typeName: String
|
2021-08-02 13:22:15 +08:00
|
|
|
},
|
2021-06-11 23:00:33 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
2021-09-15 12:19:13 +08:00
|
|
|
chartList: [], // 普通panel的chart
|
2022-01-16 23:16:00 +08:00
|
|
|
panelLock: true,
|
2021-09-15 12:19:13 +08:00
|
|
|
// entity详情的chart
|
|
|
|
|
detailTabs: [],
|
|
|
|
|
detailChartList: [],
|
2021-12-14 17:21:37 +08:00
|
|
|
currentTab: '',
|
|
|
|
|
isCryptocurrency: false// 是否为挖矿列表
|
2021-08-13 09:39:02 +08:00
|
|
|
}
|
|
|
|
|
},
|
2021-06-11 23:00:33 +08:00
|
|
|
async mounted () {
|
2021-12-14 17:21:37 +08:00
|
|
|
this.isCryptocurrency = this.$route.path.indexOf('cryptocurrency') > -1
|
2021-06-29 19:45:44 +08:00
|
|
|
await this.init()
|
2021-09-16 21:19:48 +08:00
|
|
|
if (!this.$_.isEmpty(this.detailTabs)) {
|
|
|
|
|
this.currentTab = this.detailTabs[0].id + ''
|
|
|
|
|
}
|
2021-06-11 23:00:33 +08:00
|
|
|
},
|
2021-06-21 18:41:17 +08:00
|
|
|
setup (props, ctx) {
|
|
|
|
|
// 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-09-15 12:19:13 +08:00
|
|
|
panelType = props.entity ? props.entity.type : 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-09-15 12:19:13 +08:00
|
|
|
api
|
2021-06-11 23:00:33 +08:00
|
|
|
}
|
2021-06-22 17:07:46 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
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) {
|
2021-09-15 12:19:13 +08:00
|
|
|
const allCharts = (await getChartList({ panelId: this.panel.id, pageSize: -1 })).map(chart => {
|
2021-06-29 19:45:44 +08:00
|
|
|
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
|
|
|
|
|
})
|
2022-01-19 17:42:41 +08:00
|
|
|
// allCharts = allCharts.filter(chart => chart.type === 24)
|
2022-01-03 22:46:22 +08:00
|
|
|
this.chartList = allCharts
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.$emit('chartLoaded', allCharts)
|
2022-01-18 23:12:03 +08:00
|
|
|
}, 1000)
|
2021-06-29 19:45:44 +08:00
|
|
|
}
|
2021-06-22 17:07:46 +08:00
|
|
|
},
|
2021-09-15 20:11:07 +08:00
|
|
|
changeTab ({ index }) {
|
|
|
|
|
this.currentTab = this.detailTabs[index].id + ''
|
|
|
|
|
this.detailChartList = this.detailTabs[index].children
|
2021-09-15 12:19:13 +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-10-13 20:01:29 +08:00
|
|
|
getCurrentTimeRange (callback) {
|
|
|
|
|
const myEndTime = window.$dayJs.tz().valueOf()
|
|
|
|
|
const myStartTime = myEndTime - this.timeFilter.dateRangeValue * 60 * 1000
|
|
|
|
|
callback({ startTime: myStartTime, endTime: myEndTime })
|
|
|
|
|
},
|
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)
|
|
|
|
|
}
|
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-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>
|