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

192 lines
5.7 KiB
Vue
Raw Normal View History

2021-06-11 23:00:33 +08:00
<template>
<div style="padding: 10px 0 20px 20px;">
<div v-if="typeName" class="entity-detail-tool">
<div>
<span @click="goBack" style="cursor: pointer;"><i class="cn-icon cn-icon-arrow-left-circle"></i></span>
<span style="padding-left: 15px; color: #333;">{{tabTitle}}</span>
</div>
<el-radio-group v-model="tab" size="mini" @change="changeTab">
<el-radio-button v-for="tabTmp in tabs" :label="tabTmp.key" >{{tabTmp.label}}</el-radio-button>
</el-radio-group>
</div>
2021-08-13 18:57:49 +08:00
<div class="cn-panel" id="cn-panel" :style="{height: typeName ? 'calc(100% - 80px)' : ''}">
<div class="panel__time">
<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"/>
</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>
<!-- <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 } 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'
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,
entity: Object,
tabs: Array
2021-08-02 13:22:15 +08:00
},
components: {
Chart,
DateTimeRange,
TimeRefresh
},
2021-06-11 23:00:33 +08:00
data () {
return {
chartList: []
2021-06-11 23:00:33 +08:00
}
},
computed: {
tabTitle () {
let title
switch (this.typeName) {
case 'ipEntityDetail':{//client IP
title = this.$t('entities.ipDetail')
break
}
case 'serverIpEntityDetail': {
title = this.$t('entities.ipDetail')
break
}
case 'domainEntityDetail': {
title = this.$t('entities.domainDetail')
break
}
case 'appEntityDetail': {
title = this.$t('entities.appDetail')
break
}
default: break
}
return title
}
},
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) {
let tab = ''
if (!_.isEmpty(props.tabs)) {
tab = ref(props.tabs[0].key)
}
// data
const dateRangeValue = 60
const { startTime, endTime } = getNowTime(dateRangeValue)
const timeFilter = ref({ startTime, endTime, dateRangeValue })
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,
panel,
timeFilter,
api,
tab
2021-06-11 23:00:33 +08:00
}
},
methods: {
goBack () {
this.$emit('goBack')
},
async changeTab (label) {
let routePath;
if(label=='clientIP'){
routePath = 'ipEntityDetail';
}else if(label=='serverIP'){
routePath = 'serverIpEntityDetail';
}
this.panelType = panelTypeAndRouteMapping[routePath];
await this.init();
},
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-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)
})
}
},
timeRefreshChange () {
if (!this.$refs.dateTimeRange.isCustom) {
const value = this.timeFilter.dateRangeValue
this.$refs.dateTimeRange.quickChange(value)
}
/* if (!this.$refs.dateTimeRange) {
this.reloadCharts()
return
}
if (this.$refs.dateTimeRange.isCustom) {
this.reloadCharts()
} else {
const value = this.timeFilter.dateRangeValue
this.$refs.dateTimeRange.quickChange(value)
} */
},
reload (s, e, v) {
this.dateTimeRangeChange(s, e, v)
/* this.$nextTick(() => {
this.reloadCharts()
}) */
},
// 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()
})
}
},
beforeUnmount () {
this.$store.commit('setEntityName', '')
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>