2021-06-20 13:31:55 +08:00
|
|
|
|
<template>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
<!-- echarts类的图标,如饼图、柱状图、折线图等 -->
|
2021-06-20 13:31:55 +08:00
|
|
|
|
<echarts-frame
|
|
|
|
|
|
v-if="isEcharts"
|
|
|
|
|
|
:layout="layout"
|
|
|
|
|
|
:style="computePosition"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #title v-if="layout.indexOf(layoutConstant.HEADER) > -1">{{chartInfo.i18n ? $t(chartInfo.i18n) : chartInfo.name}}</template>
|
|
|
|
|
|
<template #operations v-if="layout.indexOf(layoutConstant.HEADER) > -1">
|
|
|
|
|
|
<i class="cn-icon cn-icon-more-light"></i>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #default>
|
|
|
|
|
|
<div class="chart-drawing" :id="`chart${chartInfo.id}`"></div>
|
|
|
|
|
|
</template>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
<template #footer v-if="layout.indexOf(layoutConstant.FOOTER) > -1">
|
|
|
|
|
|
<!-- 带Table的饼图,展示Table -->
|
|
|
|
|
|
<template v-if="isEchartsWithTable">
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</template>
|
2021-06-20 13:31:55 +08:00
|
|
|
|
</echarts-frame>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
<!-- 单值图 -->
|
2021-06-20 13:31:55 +08:00
|
|
|
|
<single-value
|
|
|
|
|
|
v-else-if="isSingleValue"
|
|
|
|
|
|
:type="chartInfo.type"
|
|
|
|
|
|
:style="computePosition"
|
|
|
|
|
|
>
|
|
|
|
|
|
</single-value>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
<!-- 表格 -->
|
2021-06-20 13:31:55 +08:00
|
|
|
|
<chart-table
|
|
|
|
|
|
v-else-if="isTable"
|
2021-06-21 20:33:39 +08:00
|
|
|
|
:table-columns="table.tableColumns"
|
|
|
|
|
|
:table-data="table.currentPageData"
|
2021-06-20 13:31:55 +08:00
|
|
|
|
:style="computePosition"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #title>{{chartInfo.i18n ? $t(chartInfo.i18n) : chartInfo.name}}</template>
|
|
|
|
|
|
<template #operations>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
<!-- <div class="header__operation header__operation--table">
|
2021-06-20 13:31:55 +08:00
|
|
|
|
<span class="option__button"><i class="cn-icon cn-icon-download"></i></span>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
</div>-->
|
2021-06-21 20:33:39 +08:00
|
|
|
|
<div class="header__operation header__operation--table">
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
size="mini"
|
|
|
|
|
|
v-model="table.limit"
|
2021-06-22 21:19:04 +08:00
|
|
|
|
class="option__select select-topn"
|
2021-06-21 20:33:39 +08:00
|
|
|
|
placeholder=""
|
2021-06-22 21:19:04 +08:00
|
|
|
|
popper-class="option-popper"
|
2021-06-21 20:33:39 +08:00
|
|
|
|
>
|
|
|
|
|
|
<el-option v-for="item in chartTableTopOptions" :key="item" :value="item">TOP {{item}}</el-option>
|
|
|
|
|
|
<template #prefix>TOP </template>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="header__operation header__operation--table">
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
size="mini"
|
|
|
|
|
|
v-model="table.orderBy"
|
2021-06-22 21:19:04 +08:00
|
|
|
|
class="option__select select-column"
|
2021-06-21 20:33:39 +08:00
|
|
|
|
placeholder=""
|
2021-06-22 21:19:04 +08:00
|
|
|
|
popper-class="option-popper"
|
2021-06-21 20:33:39 +08:00
|
|
|
|
>
|
|
|
|
|
|
<el-option v-for="item in table.tableColumns" :key="item" :value="item">{{item}}</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
<!-- <div class="header__operation header__operation--table">
|
2021-06-20 13:31:55 +08:00
|
|
|
|
<span class="option__button"><i class="cn-icon cn-icon-style"></i></span>
|
|
|
|
|
|
<div class="icon-group-divide"></div>
|
|
|
|
|
|
<span class="option__button"><i class="cn-icon cn-icon-dropdown"></i></span>
|
2021-06-22 21:19:04 +08:00
|
|
|
|
</div>-->
|
2021-06-20 13:31:55 +08:00
|
|
|
|
<div class="header__operation header__operation--table">
|
|
|
|
|
|
<span class="option__button"><i class="cn-icon cn-icon-full-screen"></i></span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
2021-06-21 20:33:39 +08:00
|
|
|
|
<template #footer>
|
|
|
|
|
|
<chart-table-pagination
|
|
|
|
|
|
:total="table.tableData.length"
|
|
|
|
|
|
@pageJump="pageJump"
|
|
|
|
|
|
></chart-table-pagination>
|
|
|
|
|
|
</template>
|
2021-06-20 13:31:55 +08:00
|
|
|
|
</chart-table>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import * as echarts from 'echarts'
|
2021-06-22 21:19:04 +08:00
|
|
|
|
import { isEcharts, isSingleValue, isTable, getOption, getTypeCategory, getLayout, layoutConstant, heightUnit, isEchartsWithTable } from '@/components/charts/chart-options'
|
2021-06-20 13:31:55 +08:00
|
|
|
|
import EchartsFrame from '@/components/charts/EchartsFrame'
|
|
|
|
|
|
import SingleValue from '@/components/charts/ChartSingleValue'
|
|
|
|
|
|
import Table from '@/components/charts/ChartTable'
|
2021-06-21 20:33:39 +08:00
|
|
|
|
import ChartTablePagination from '@/components/charts/ChartTablePagination'
|
|
|
|
|
|
import { chartTableDefaultPageSize, chartTableTopOptions } from '@/utils/constants'
|
2021-06-20 13:31:55 +08:00
|
|
|
|
import { get } from '@/utils/http'
|
|
|
|
|
|
|
|
|
|
|
|
let myChart // echarts实例
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'Chart',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
chart: Object // 图表对象,包括id、name、type等数据
|
|
|
|
|
|
},
|
|
|
|
|
|
components: {
|
|
|
|
|
|
EchartsFrame,
|
|
|
|
|
|
SingleValue,
|
2021-06-21 20:33:39 +08:00
|
|
|
|
ChartTablePagination,
|
2021-06-20 13:31:55 +08:00
|
|
|
|
'chart-table': Table
|
|
|
|
|
|
},
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2021-06-21 20:33:39 +08:00
|
|
|
|
table: {
|
|
|
|
|
|
pageSize: chartTableDefaultPageSize,
|
|
|
|
|
|
limit: chartTableTopOptions[0], // top-n
|
|
|
|
|
|
orderBy: '',
|
|
|
|
|
|
tableColumns: [], // table字段
|
|
|
|
|
|
tableData: [], // table的所有数据
|
|
|
|
|
|
currentPageData: [] // table当前页的数据
|
|
|
|
|
|
}
|
2021-06-20 13:31:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
initChart () {
|
|
|
|
|
|
const now = new Date().getTime()
|
|
|
|
|
|
const params = this.chartInfo.params ? JSON.parse(this.chartInfo.params) : null
|
|
|
|
|
|
if (this.isEcharts) {
|
|
|
|
|
|
myChart = echarts.init(document.getElementById(`chart${this.chartInfo.id}`))
|
|
|
|
|
|
myChart.setOption(this.chartOption)
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
myChart.resize()
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (this.isTable) {
|
|
|
|
|
|
if (params) {
|
|
|
|
|
|
const tableColumns = new Set()
|
|
|
|
|
|
tableResponse.data.forEach(d => {
|
|
|
|
|
|
Object.keys(d).forEach(k => {
|
|
|
|
|
|
tableColumns.add(k)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2021-06-21 20:33:39 +08:00
|
|
|
|
this.table.tableColumns = Array.from(tableColumns)
|
|
|
|
|
|
this.table.orderBy = this.table.tableColumns[0]
|
|
|
|
|
|
this.table.tableData = tableResponse.data
|
|
|
|
|
|
this.table.currentPageData = this.getTargetPageData(1, this.table.pageSize, this.table.tableData)
|
2021-06-20 13:31:55 +08:00
|
|
|
|
/* get(params.url, { startTime: now - 3600000, endTime: now, order: params.order ? params.order : null, limit: params.limit ? params.limit : null }).then(response => {
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
const tableColumns = new Set()
|
|
|
|
|
|
response.data.forEach(d => {
|
|
|
|
|
|
Object.keys(d).forEach(k => {
|
|
|
|
|
|
tableColumns.add(k)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2021-06-21 20:33:39 +08:00
|
|
|
|
this.table.tableColumns = tableColumns
|
|
|
|
|
|
this.table.tableData = response.data
|
2021-06-20 13:31:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}) */
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-21 20:33:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
pageJump (val) {
|
|
|
|
|
|
this.table.currentPageData = this.getTargetPageData(val, this.table.pageSize, this.table.tableData)
|
|
|
|
|
|
},
|
|
|
|
|
|
getTargetPageData (pageNum, pageSize, tableData) {
|
|
|
|
|
|
return this.$_.slice(tableData, (pageNum - 1) * pageSize, pageNum * pageSize)
|
2021-06-20 13:31:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
computePosition () {
|
|
|
|
|
|
const gridColumn = `${this.chartInfo.x} / ${this.chartInfo.x + this.chartInfo.w}`
|
|
|
|
|
|
const gridRow = `${this.chartInfo.y} / ${this.chartInfo.y + this.chartInfo.h}`
|
|
|
|
|
|
return {
|
|
|
|
|
|
gridColumn,
|
|
|
|
|
|
gridRow
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted () {
|
|
|
|
|
|
this.initChart()
|
|
|
|
|
|
},
|
|
|
|
|
|
setup (props) {
|
|
|
|
|
|
const chartInfo = JSON.parse(JSON.stringify(props.chart))
|
|
|
|
|
|
chartInfo.category = getTypeCategory(props.chart.type)
|
|
|
|
|
|
return {
|
|
|
|
|
|
chartInfo,
|
|
|
|
|
|
layoutConstant,
|
2021-06-21 20:33:39 +08:00
|
|
|
|
chartTableTopOptions,
|
2021-06-20 13:31:55 +08:00
|
|
|
|
chartOption: getOption(props.chart.type),
|
|
|
|
|
|
isEcharts: isEcharts(props.chart.type),
|
2021-06-22 21:19:04 +08:00
|
|
|
|
isEchartsWithTable: isEchartsWithTable(props.chart.type),
|
2021-06-20 13:31:55 +08:00
|
|
|
|
isSingleValue: isSingleValue(props.chart.type),
|
|
|
|
|
|
isTable: isTable(props.chart.type),
|
|
|
|
|
|
layout: getLayout(props.chart.type)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const tableResponse = JSON.parse(`{
|
|
|
|
|
|
"status": 200,
|
|
|
|
|
|
"success": true,
|
|
|
|
|
|
"message": "OK",
|
|
|
|
|
|
"statistics": {
|
|
|
|
|
|
"elapsed": 2111,
|
|
|
|
|
|
"rows_read": 1750155,
|
|
|
|
|
|
"result_size": 872,
|
|
|
|
|
|
"result_rows": 10
|
|
|
|
|
|
},
|
|
|
|
|
|
"data": [{
|
|
|
|
|
|
"ip": "192.168.32.107",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.108",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.109",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.110",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.111",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.112",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.113",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.114",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.115",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.116",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.117",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.118",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
},{
|
|
|
|
|
|
"ip": "192.168.32.119",
|
|
|
|
|
|
"sessions": "229112",
|
|
|
|
|
|
"packets": "245823",
|
|
|
|
|
|
"bytes": "17974141"
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}`)
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|