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/Panel.vue

128 lines
3.6 KiB
Vue
Raw Normal View History

2021-06-11 23:00:33 +08:00
<template>
<div style="padding: 10px 0 20px 20px;">
<div class="cn-panel">
<div class="panel__time">
<DateTimeRange class="date-time-range" :start-time="startTime" :end-time="endTime" ref="dateTimeRange" @change="reload"/>
2021-06-25 19:11:00 +08:00
<TimeRefresh class="date-time-range" @change="timeRefreshChange" :end-time="endTime"/>
</div>
2021-06-23 15:57:34 +08:00
<chart v-for="(chart, index) in chartList" :key="index" :chart="chart" :start-time="startTime" :end-time="endTime"></chart>
<!-- <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>
</div>
2021-06-11 23:00:33 +08:00
</template>
<script>
import { useRoute } from 'vue-router'
import { ref, onMounted } from 'vue'
2021-06-11 23:00:33 +08:00
import { panelTypeAndRouteMapping } from '@/utils/constants'
import { api, getPanelList, getChartList } from '@/utils/api'
import { getNowTime } from '@/utils/date-util'
import Chart from './Chart'
import DateTimeRange from '@/components/common/TimeRange/DateTimeRange'
import TimeRefresh from '@/components/common/TimeRange/TimeRefresh'
2021-06-11 23:00:33 +08:00
export default {
name: 'Panel',
components: {
Chart,
DateTimeRange,
TimeRefresh
},
2021-06-11 23:00:33 +08:00
data () {
return {
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
},
setup (props, ctx) {
// data
const chartList = ref([])
const dateRangeValue = ref(60)
const now = getNowTime(dateRangeValue.value)
const startTime = ref(now.startTime)
const endTime = ref(now.endTime)
const panel = ref({})
let panelType = 1 // 取得panel的type
2021-06-11 23:00:33 +08:00
const { params } = useRoute()
// refs
const dateTimeRange = ref(null)
2021-06-11 23:00:33 +08:00
panelTypeAndRouteMapping[params.typeName] && (panelType = panelTypeAndRouteMapping[params.typeName])
// onMounted
onMounted(() => {
dateTimeRange.value.isCustom = false
dateTimeRange.value.dateRangeValue = dateRangeValue
})
// methods
const dateTimeRangeChange = (s, e, v) => {
startTime.value = s
endTime.value = e
dateRangeValue.value = v
}
2021-06-11 23:00:33 +08:00
return {
panelType,
chartList,
panel,
startTime,
endTime,
dateRangeValue,
dateTimeRange,
api,
dateTimeRangeChange
2021-06-11 23:00:33 +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) {
this.chartList = (await getChartList({ panelId: this.panel.id, pageSize: -1 })).map(chart => {
chart.i = chart.id
return chart
})
}
},
timeRefreshChange () {
if (!this.$refs.dateTimeRange) {
this.init()
return
}
if (this.$refs.dateTimeRange.isCustom) {
this.init()
} else {
const value = this.dateRangeValue.value || this.dateRangeValue
this.$refs.dateTimeRange.quickChange(value)
}
},
reload (s, e, v) {
this.dateTimeRangeChange(s, e, v)
this.init()
}
2021-06-11 23:00:33 +08:00
}
}
</script>
<style lang="scss">
@import '~@/components/charts/panel.scss';
2021-06-11 23:00:33 +08:00
</style>