| | |
| | | <div class="title-container"> |
| | | <h1>运维监控报表</h1> |
| | | <div class="select-container"> |
| | | <el-select v-model="company" placeholder="请选择运维公司" @change="companyChange"> |
| | | <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"> |
| | | <el-select v-model="params.unitId" placeholder="请选择运维公司" @change="showData"> |
| | | <el-option v-for="item in options" :key="item.label" :label="item.label" :value="item.value"> |
| | | </el-option> |
| | | </el-select> |
| | | </div> |
| | | <div class="date-container"> |
| | | <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期" |
| | | end-placeholder="结束日期"> |
| | | <el-date-picker type="monthrange" v-model="params.dateRange" range-separator="至" start-placeholder="开始月份" |
| | | end-placeholder="结束月份" @change="showData"> |
| | | </el-date-picker> |
| | | </div> |
| | | </div> |
| | |
| | | |
| | | <script> |
| | | import * as echarts from 'echarts'; |
| | | import { ywUnitList, monitor } from "@/api/platform/home"; |
| | | let lineChart = null; |
| | | let observer = null; |
| | | export default { |
| | | name: 'DataChart', |
| | | data() { |
| | | return { |
| | | dateRange: '', |
| | | company: '', |
| | | options: [ |
| | | { label: 'XX运维公司1', value: 'XX运维公司1' }, |
| | | { label: 'XX运维公司2', value: 'XX运维公司2' }, |
| | | { label: 'XX运维公司3', value: 'XX运维公司3' }, |
| | | { label: 'XX运维公司4', value: 'XX运维公司4' }, |
| | | ], |
| | | dataList: [ |
| | | { |
| | | name: 'XX运维公司1', |
| | | state: { '1月': 1000, '2月': 2131, '3月': 1233, '4月': 2132, '5月': 3211 }, |
| | | state2: { '1月': 123, '2月': 213, '3月': 1412, '4月': 23, '5月': 123 } |
| | | }, |
| | | { |
| | | name: 'XX运维公司2', |
| | | state: { '1月': 213, '2月': 2131, '3月': 1233, '4月': 2132, '5月': 3211 }, |
| | | state2: { '1月': 123, '2月': 123, '3月': 1412, '4月': 23, '5月': 123 } |
| | | }, |
| | | { |
| | | name: 'XX运维公司3', |
| | | state: { '1月': 1000, '2月': 2131, '3月': 1233, '4月': 2132, '5月': 3211, '6月': 1321 }, |
| | | state2: { '1月': 123, '2月': 213, '3月': 123, '4月': 23, '5月': 123 } |
| | | }, |
| | | { |
| | | name: 'XX运维公司4', |
| | | state: { '1月': 1000, '2月': 2131, '3月': 1233, '4月': 2132, '5月': 3211 }, |
| | | state2: { '1月': 123, '2月': 613, '3月': 1412, '4月': 2336, '5月': 123 } |
| | | }, |
| | | { |
| | | name: 'XX运维公司5', |
| | | state: { '1月': 1000, '2月': 433, '3月': 1233, '4月': 2132, '5月': 8886 }, |
| | | state2: { '1月': 123, '2月': 213, '3月': 1412, '4月': 23, '5月': 123 } |
| | | }, |
| | | ], |
| | | params: { |
| | | dateRange: '', |
| | | unitId: '' |
| | | }, |
| | | options: [], |
| | | dataList: [], |
| | | } |
| | | }, |
| | | methods: { |
| | | initChart() { |
| | | const sortedKeys = Object.keys(this.acitveData.state) |
| | | .sort(); // 按照字符串的字典序对键进行排序 |
| | | const option = { |
| | | legend: { |
| | | right: '2%', |
| | | top: '5%', |
| | | right: 'right', |
| | | top: 'top', |
| | | orient: "vertical", |
| | | icon: 'rect', |
| | | data: [ |
| | | { |
| | | |
| | | name: '正常数', |
| | | itemStyle: { |
| | | color: 'rgba(62, 144, 247, 1)' |
| | |
| | | tooltip: {}, |
| | | xAxis: { |
| | | type: 'category', |
| | | data: Object.keys(this.acitveData.state), |
| | | data: sortedKeys, |
| | | }, |
| | | yAxis: {}, |
| | | series: [ |
| | | { |
| | | name: '正常数', |
| | | data: Object.entries(this.acitveData.state).map(([key, value]) => value), |
| | | data: sortedKeys.map(key => this.acitveData.state[key]), |
| | | type: 'line', |
| | | itemStyle: { |
| | | color: 'rgba(62, 144, 247, 1)' |
| | |
| | | }, |
| | | { |
| | | name: '异常数', |
| | | data: Object.entries(this.acitveData.state2).map(([key, value]) => value), |
| | | data: sortedKeys.map(key => this.acitveData.state2[key]), |
| | | type: 'line', |
| | | itemStyle: { |
| | | color: 'rgba(85, 192, 191, 1)' |
| | |
| | | }, |
| | | |
| | | |
| | | companyChange() { |
| | | this.acitveData = this.dataList.find((item) => { |
| | | return item.name === this.company; |
| | | }); |
| | | if (this.acitveData) { |
| | | showData() { |
| | | monitor(this.params).then(res => { |
| | | this.acitveData = res.data; |
| | | if (Object.keys(this.acitveData).length === 0) { |
| | | this.acitveData = { |
| | | "name": "", |
| | | "state": {}, |
| | | "state2": {} |
| | | } |
| | | } |
| | | lineChart = echarts.init(this.$refs.chartContent); |
| | | this.initChart(); |
| | | } |
| | | this.observe(); |
| | | }) |
| | | }, |
| | | |
| | | // 监听变化 |
| | |
| | | |
| | | }, |
| | | mounted() { |
| | | this.acitveData = this.dataList[0]; |
| | | this.company = this.acitveData.name; |
| | | lineChart = echarts.init(this.$refs.chartContent); |
| | | this.initChart(); |
| | | this.observe(); |
| | | ywUnitList().then(res => { |
| | | this.options = res.data.data.map(item => { |
| | | return { |
| | | label: item.value, |
| | | value: item.id |
| | | } |
| | | }) |
| | | if (this.params.unitId === '') { |
| | | this.params.unitId = this.options[0].value; |
| | | } |
| | | this.showData(); |
| | | }) |
| | | }, |
| | | beforeDestroy() { |
| | | if (lineChart) { |
| | |
| | | align-items: center; |
| | | z-index: 2; |
| | | |
| | | |
| | | .more-button { |
| | | cursor: pointer; |
| | | font-size: 16px; |
| | |
| | | margin: 0 20px; |
| | | width: 180px; |
| | | } |
| | | </style> |
| | | </style> |