Commit 8141b0f4cc59b047026a582a118d72233684dd3b

Authored by sqy
1 parent 9ade13f0

wip:历史记录折线图,接口待调试

@@ -21,10 +21,10 @@ @@ -21,10 +21,10 @@
21 import { BasicTable, useTable, TableAction } from '/@/components/Table'; 21 import { BasicTable, useTable, TableAction } from '/@/components/Table';
22 import { alarmColumns, alarmSearchSchemas } from './config/detail.config'; 22 import { alarmColumns, alarmSearchSchemas } from './config/detail.config';
23 import { getDeviceAlarm } from '/@/api/device/deviceManager'; 23 import { getDeviceAlarm } from '/@/api/device/deviceManager';
24 - import AlarmDetailDrawer from './cpns/AlarmDetailDrawer.vue';  
25 import { useDrawer } from '/@/components/Drawer'; 24 import { useDrawer } from '/@/components/Drawer';
  25 + import AlarmDetailDrawer from './cpns/AlarmDetailDrawer.vue';
26 export default defineComponent({ 26 export default defineComponent({
27 - name: 'DeviceManagement', 27 + name: 'AlarmCenter',
28 components: { 28 components: {
29 BasicTable, 29 BasicTable,
30 TableAction, 30 TableAction,
  1 +export const getLineData = (() => {
  2 + const category: any[] = [];
  3 + let dottedBase = +new Date();
  4 + const lineData: any[] = [];
  5 +
  6 + for (let i = 0; i < 20; i++) {
  7 + const date = new Date((dottedBase += 1000 * 3600 * 24));
  8 + category.push([date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'));
  9 + const b = Math.random() * 200;
  10 + const d = Math.random() * 200;
  11 + lineData.push(d + b);
  12 + }
  13 + console.log(lineData);
  14 + return { category, lineData };
  15 +})();
@@ -25,14 +25,21 @@ @@ -25,14 +25,21 @@
25 </template> 25 </template>
26 </BasicTable> 26 </BasicTable>
27 </div> 27 </div>
28 - <a-button type="primary" @click="handleClick">打开弹窗</a-button>  
29 - <BasicModal @register="registerModal" title="历史数据" width="70%"> 28 + <a-button type="primary" @click="openHistoryModal">打开弹窗</a-button>
  29 + <BasicModal
  30 + @register="registerModal"
  31 + title="历史数据"
  32 + width="70%"
  33 + :footer="null"
  34 + @cancel="cancelHistoryModal"
  35 + >
30 <BasicForm @register="registerForm" /> 36 <BasicForm @register="registerForm" />
  37 + <div ref="chartRef" :style="{ height: '300px', width }"></div>
31 </BasicModal> 38 </BasicModal>
32 </div> 39 </div>
33 </template> 40 </template>
34 <script lang="ts"> 41 <script lang="ts">
35 - import { defineComponent, ref, nextTick, unref, onMounted } from 'vue'; 42 + import { defineComponent, ref, nextTick, unref, onMounted, Ref } from 'vue';
36 import { useScript } from '/@/hooks/web/useScript'; 43 import { useScript } from '/@/hooks/web/useScript';
37 import { formSchema, columns } from './config.data'; 44 import { formSchema, columns } from './config.data';
38 import { BasicTable, useTable } from '/@/components/Table'; 45 import { BasicTable, useTable } from '/@/components/Table';
@@ -43,6 +50,10 @@ @@ -43,6 +50,10 @@
43 import { useModal, BasicModal } from '/@/components/Modal'; 50 import { useModal, BasicModal } from '/@/components/Modal';
44 import { BasicForm, useForm } from '/@/components/Form'; 51 import { BasicForm, useForm } from '/@/components/Form';
45 import { schemas } from './config.data'; 52 import { schemas } from './config.data';
  53 +
  54 + import { useECharts } from '/@/hooks/web/useECharts';
  55 + import { getLineData } from './data';
  56 +
46 export default defineComponent({ 57 export default defineComponent({
47 name: 'BaiduMap', 58 name: 'BaiduMap',
48 components: { 59 components: {
@@ -77,9 +88,6 @@ @@ -77,9 +88,6 @@
77 map.centerAndZoom(point, 15); 88 map.centerAndZoom(point, 15);
78 map.enableScrollWheelZoom(true); 89 map.enableScrollWheelZoom(true);
79 } 90 }
80 - onMounted(() => {  
81 - initMap();  
82 - });  
83 91
84 const [registerTable] = useTable({ 92 const [registerTable] = useTable({
85 api: devicePage, 93 api: devicePage,
@@ -106,6 +114,7 @@ @@ -106,6 +114,7 @@
106 }; 114 };
107 map.centerAndZoom(point, 15); 115 map.centerAndZoom(point, 15);
108 map.enableScrollWheelZoom(true); 116 map.enableScrollWheelZoom(true);
  117 + // 创建信息窗口对象
109 let infoWindow = new BMap.InfoWindow( 118 let infoWindow = new BMap.InfoWindow(
110 ` 119 `
111 <div style="display:flex;justify-content:space-between; margin:20px 0px;"> 120 <div style="display:flex;justify-content:space-between; margin:20px 0px;">
@@ -129,7 +138,7 @@ @@ -129,7 +138,7 @@
129 </div> 138 </div>
130 `, 139 `,
131 options 140 options
132 - ); // 创建信息窗口对象 141 + );
133 map.openInfoWindow(infoWindow, map.getCenter()); 142 map.openInfoWindow(infoWindow, map.getCenter());
134 let preMarker = null; 143 let preMarker = null;
135 const rivet = 144 const rivet =
@@ -161,22 +170,89 @@ @@ -161,22 +170,89 @@
161 }; 170 };
162 171
163 const [registerModal, { openModal }] = useModal(); 172 const [registerModal, { openModal }] = useModal();
164 - const [registerForm] = useForm({ 173 + const [registerForm, { resetFields }] = useForm({
165 labelWidth: 120, 174 labelWidth: 120,
166 schemas, 175 schemas,
167 }); 176 });
168 - const handleClick = () => { 177 +
  178 + const chartRef = ref<HTMLDivElement | null>(null);
  179 + const { setOptions, echarts } = useECharts(chartRef as Ref<HTMLDivElement>);
  180 + const { lineData, category } = getLineData;
  181 + const openHistoryModal = () => {
169 openModal(true); 182 openModal(true);
  183 + setOptions({
  184 + backgroundColor: '#0f375f',
  185 + tooltip: {
  186 + trigger: 'axis',
  187 + axisPointer: {
  188 + type: 'shadow',
  189 + label: {
  190 + show: true,
  191 + backgroundColor: '#333',
  192 + },
  193 + },
  194 + },
  195 + xAxis: {
  196 + data: category,
  197 + axisLine: {
  198 + lineStyle: {
  199 + color: '#ccc',
  200 + },
  201 + },
  202 + },
  203 + yAxis: {
  204 + splitLine: { show: false },
  205 + axisLine: {
  206 + lineStyle: {
  207 + color: '#ccc',
  208 + },
  209 + },
  210 + },
  211 + series: [
  212 + {
  213 + name: '当日数据',
  214 + type: 'line',
  215 + smooth: true,
  216 + showAllSymbol: 'auto',
  217 + symbol: 'emptyCircle',
  218 + symbolSize: 15,
  219 + data: lineData,
  220 + },
  221 + {
  222 + name: 'line',
  223 + type: 'bar',
  224 + barGap: '-100%',
  225 + barWidth: 10,
  226 + itemStyle: {
  227 + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  228 + { offset: 0, color: 'rgba(20,200,212,0.5)' },
  229 + { offset: 0.2, color: 'rgba(20,200,212,0.2)' },
  230 + { offset: 1, color: 'rgba(20,200,212,0)' },
  231 + ]),
  232 + },
  233 + z: -12,
  234 + data: lineData,
  235 + },
  236 + ],
  237 + });
  238 + };
  239 + const cancelHistoryModal = () => {
  240 + resetFields();
170 }; 241 };
  242 + onMounted(() => {
  243 + initMap();
  244 + });
171 245
172 return { 246 return {
173 wrapRef, 247 wrapRef,
174 registerTable, 248 registerTable,
175 deviceRowClick, 249 deviceRowClick,
176 DeviceState, 250 DeviceState,
177 - handleClick,  
178 registerModal, 251 registerModal,
179 registerForm, 252 registerForm,
  253 + chartRef,
  254 + openHistoryModal,
  255 + cancelHistoryModal,
180 }; 256 };
181 }, 257 },
182 }); 258 });
@@ -8,8 +8,8 @@ @@ -8,8 +8,8 @@
8 import { useWebSocket } from '@vueuse/core'; 8 import { useWebSocket } from '@vueuse/core';
9 import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum'; 9 import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
10 import { getAuthCache } from '/@/utils/auth'; 10 import { getAuthCache } from '/@/utils/auth';
11 - import type { socketDataType } from '../../types';  
12 import { useMessage } from '/@/hooks/web/useMessage'; 11 import { useMessage } from '/@/hooks/web/useMessage';
  12 + import type { socketDataType } from '../../types';
13 export default defineComponent({ 13 export default defineComponent({
14 name: 'RealTimeData', 14 name: 'RealTimeData',
15 components: { 15 components: {
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 }, 22 },
23 }, 23 },
24 setup(props) { 24 setup(props) {
25 - const token = getAuthCache(JWT_TOKEN_KEY); 25 + const token: string = getAuthCache(JWT_TOKEN_KEY);
26 const state = reactive({ 26 const state = reactive({
27 server: `ws://101.133.234.90:8080/api/ws/plugins/telemetry?token=${token}`, 27 server: `ws://101.133.234.90:8080/api/ws/plugins/telemetry?token=${token}`,
28 sendValue: JSON.stringify({ 28 sendValue: JSON.stringify({
@@ -58,23 +58,22 @@ @@ -58,23 +58,22 @@
58 onConnected() { 58 onConnected() {
59 send(state.sendValue); 59 send(state.sendValue);
60 console.log('建立连接了'); 60 console.log('建立连接了');
61 - console.log(props.deviceDetail.tbDeviceId);  
62 }, 61 },
63 onMessage(_, e) { 62 onMessage(_, e) {
64 const { data } = JSON.parse(e.data); 63 const { data } = JSON.parse(e.data);
65 console.log('来新消息了', 'data---', data); 64 console.log('来新消息了', 'data---', data);
66 - const newArray: any = []; 65 + const newArray: socketDataType[] = [];
67 for (const key in data) { 66 for (const key in data) {
68 - const newData = data[key].flat(1); 67 + const [time, value] = data[key].flat(1);
69 let obj = { 68 let obj = {
70 key, 69 key,
71 - time: newData[0],  
72 - value: newData[1], 70 + time,
  71 + value,
73 }; 72 };
74 if (state.recordList.length === 0) { 73 if (state.recordList.length === 0) {
75 - state.recordList.push(obj); 74 + state.recordList.unshift(obj);
76 } else { 75 } else {
77 - newArray.push(obj); 76 + newArray.unshift(obj);
78 } 77 }
79 } 78 }
80 newArray.forEach((item) => { 79 newArray.forEach((item) => {
@@ -91,7 +90,6 @@ @@ -91,7 +90,6 @@
91 } 90 }
92 }); 91 });
93 }, 92 },
94 - onDisconnected() {},  
95 onError() { 93 onError() {
96 createMessage.error('webSocket连接超时,请联系管理员'); 94 createMessage.error('webSocket连接超时,请联系管理员');
97 }, 95 },