Commit 886c0dab2f36fa1a4deeef8322e53e6bafc14df0

Authored by fengtao
1 parent f220935e

feat:报表导出 新增报表查看(可查看多个设备属性)

@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 :showOkBtn="false" 10 :showOkBtn="false"
11 > 11 >
12 <div class="wrapper"> 12 <div class="wrapper">
13 - <div class="inner item" v-for="(item, index) in chartData" :key="index"> 13 + <div class="inner item" v-for="(item, index) in initChartData" :key="index">
14 <p style="display: none">{{ item }}</p> 14 <p style="display: none">{{ item }}</p>
15 <div :id="`chart${index}`" :style="{ height, width }"></div> 15 <div :id="`chart${index}`" :style="{ height, width }"></div>
16 </div> 16 </div>
@@ -22,6 +22,8 @@ @@ -22,6 +22,8 @@
22 import { ref, PropType, nextTick } from 'vue'; 22 import { ref, PropType, nextTick } from 'vue';
23 import { BasicModal, useModalInner } from '/@/components/Modal'; 23 import { BasicModal, useModalInner } from '/@/components/Modal';
24 import * as echarts from 'echarts'; 24 import * as echarts from 'echarts';
  25 + import { exportViewChartApi } from '/@/api/export/exportManager';
  26 + import moment from 'moment';
25 27
26 defineProps({ 28 defineProps({
27 width: { 29 width: {
@@ -34,72 +36,120 @@ @@ -34,72 +36,120 @@
34 }, 36 },
35 }); 37 });
36 defineEmits(['register']); 38 defineEmits(['register']);
37 -  
38 const heightNum = ref(800); 39 const heightNum = ref(800);
39 - const chartData = ref([1, 2, 3, 4]);  
40 - const [register] = useModalInner((data) => {  
41 - console.log(data);  
42 - //TODO待服务端返回值  
43 - nextTick(() => {  
44 - chartData.value.forEach((_, index) => {  
45 - let myChart = echarts.init(document.getElementById(`chart${index}`) as HTMLElement);  
46 - let myOption = {  
47 - title: {  
48 - text: '报表趋势图',  
49 - subtext: `图${index + 1}`,  
50 - left: 'left',  
51 - },  
52 - tooltip: {  
53 - trigger: 'axis',  
54 - },  
55 - legend: {  
56 - data: ['CO', 'CO2', 'Temp'],  
57 - top: '20px',  
58 - },  
59 - toolbox: {},  
60 - grid: {  
61 - left: '3%',  
62 - right: '4%',  
63 - bottom: '3%',  
64 - containLabel: true,  
65 - },  
66 - xAxis: {  
67 - type: 'category',  
68 - data: ['1', '2', '3', '4', '5', '6', '7'],  
69 - boundaryGap: false,  
70 - },  
71 - yAxis: {  
72 - type: 'value',  
73 - boundaryGap: false,  
74 - },  
75 - series: [  
76 - {  
77 - name: 'CO',  
78 - type: 'line',  
79 - stack: 'Total',  
80 - data: [150, 230, 224, 218, 135, 147, 260],  
81 - },  
82 - {  
83 - name: 'CO2',  
84 - type: 'line',  
85 - stack: 'Total',  
86 - data: [15, 23, 22, 28, 15, 17, 20],  
87 - }, 40 + const getItem: any = ref([]);
  41 + const initChartData: any = ref([]);
  42 + //生成随机颜色
  43 + let getRandomColor = function () {
  44 + return (
  45 + 'rgb(' +
  46 + Math.round(Math.random() * 255) +
  47 + ',' +
  48 + Math.round(Math.random() * 255) +
  49 + ',' +
  50 + Math.round(Math.random() * 10) +
  51 + ')'
  52 + );
  53 + };
  54 + const [register, { setModalProps }] = useModalInner(async (data) => {
  55 + setModalProps({ loading: true });
  56 + try {
  57 + const entityId = data.record.executeCondition?.executeAttributes.map((m) => m?.device);
  58 + let key = data.record.executeCondition?.executeAttributes.map((m) => m?.attributes);
  59 + let params: any = {};
  60 + params = {
  61 + ...data.record.executeCondition?.executeCondition,
  62 + ...{
  63 + keys: key.length !== 0 ? key.join(',') : '',
  64 + },
  65 + };
  66 + const result = await exportViewChartApi(entityId[0], params);
  67 + getItem.value = Object.entries(result).map((item) => {
  68 + const [attr, val] = item;
  69 + return { attr, val };
  70 + });
  71 + //服务端返回值
  72 + initChartData.value = getItem.value.map((item): any => {
  73 + const seriesData = item.val.map((m1) => Number(m1.value));
  74 + return {
  75 + attr: item.attr,
  76 + lengendData: [item.attr],
  77 + xAxisData: item.val.map((m) => moment(m.ts).format('YYYY-MM-DD HH:mm:ss')),
  78 + seriesData: [
88 { 79 {
89 - name: 'Temp', 80 + name: item.attr,
90 type: 'line', 81 type: 'line',
91 - stack: 'Total',  
92 - data: [15, 23, 22, 28, 15, 17, 20], 82 + data: seriesData,
  83 + lineStyle: {
  84 + color: getRandomColor(),
  85 + },
93 }, 86 },
94 ], 87 ],
95 }; 88 };
96 - myChart.setOption(myOption);  
97 - //自适应  
98 - window.addEventListener('resize', () => {  
99 - myChart.resize(); 89 + });
  90 + nextTick(() => {
  91 + initChartData.value.forEach((item, index) => {
  92 + let myChart = echarts.init(document.getElementById(`chart${index}`) as HTMLElement);
  93 + let myOption = {
  94 + title: {
  95 + text: `${item.attr}趋势图`,
  96 + subtext: `${item.attr}`,
  97 + left: 'left',
  98 + },
  99 + tooltip: {
  100 + trigger: 'axis',
  101 + },
  102 + legend: {
  103 + data: item.lengendData,
  104 + top: '20px',
  105 + },
  106 + toolbox: {},
  107 + grid: {
  108 + left: '3%',
  109 + right: '4%',
  110 + bottom: '3%',
  111 + containLabel: true,
  112 + },
  113 + dataZoom: [
  114 + {
  115 + type: 'slider',
  116 + show: true,
  117 + start: 0,
  118 + end: 30,
  119 + xAxisIndex: [0],
  120 + },
  121 + ],
  122 + xAxis: {
  123 + type: 'category',
  124 + data: item.xAxisData,
  125 + boundaryGap: false,
  126 + axisPointer: { type: 'shadow' },
  127 + axisLabel: {
  128 + color: '#333',
  129 + // 让x轴文字方向为竖向
  130 + interval: 0,
  131 + rotate: 90,
  132 + // formatter: function (value) {
  133 + // return value.split('').join('\n');
  134 + // },
  135 + },
  136 + },
  137 + yAxis: {
  138 + type: 'value',
  139 + boundaryGap: false,
  140 + },
  141 + series: item.seriesData,
  142 + };
  143 + myChart.setOption(myOption);
  144 + //自适应
  145 + window.addEventListener('resize', () => {
  146 + myChart.resize();
  147 + });
100 }); 148 });
101 }); 149 });
102 - }); 150 + } finally {
  151 + setModalProps({ loading: false });
  152 + }
103 }); 153 });
104 </script> 154 </script>
105 <style lang="less" scoped> 155 <style lang="less" scoped>