Commit 8141b0f4cc59b047026a582a118d72233684dd3b

Authored by sqy
1 parent 9ade13f0

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

... ... @@ -21,10 +21,10 @@
21 21 import { BasicTable, useTable, TableAction } from '/@/components/Table';
22 22 import { alarmColumns, alarmSearchSchemas } from './config/detail.config';
23 23 import { getDeviceAlarm } from '/@/api/device/deviceManager';
24   - import AlarmDetailDrawer from './cpns/AlarmDetailDrawer.vue';
25 24 import { useDrawer } from '/@/components/Drawer';
  25 + import AlarmDetailDrawer from './cpns/AlarmDetailDrawer.vue';
26 26 export default defineComponent({
27   - name: 'DeviceManagement',
  27 + name: 'AlarmCenter',
28 28 components: {
29 29 BasicTable,
30 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 25 </template>
26 26 </BasicTable>
27 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 36 <BasicForm @register="registerForm" />
  37 + <div ref="chartRef" :style="{ height: '300px', width }"></div>
31 38 </BasicModal>
32 39 </div>
33 40 </template>
34 41 <script lang="ts">
35   - import { defineComponent, ref, nextTick, unref, onMounted } from 'vue';
  42 + import { defineComponent, ref, nextTick, unref, onMounted, Ref } from 'vue';
36 43 import { useScript } from '/@/hooks/web/useScript';
37 44 import { formSchema, columns } from './config.data';
38 45 import { BasicTable, useTable } from '/@/components/Table';
... ... @@ -43,6 +50,10 @@
43 50 import { useModal, BasicModal } from '/@/components/Modal';
44 51 import { BasicForm, useForm } from '/@/components/Form';
45 52 import { schemas } from './config.data';
  53 +
  54 + import { useECharts } from '/@/hooks/web/useECharts';
  55 + import { getLineData } from './data';
  56 +
46 57 export default defineComponent({
47 58 name: 'BaiduMap',
48 59 components: {
... ... @@ -77,9 +88,6 @@
77 88 map.centerAndZoom(point, 15);
78 89 map.enableScrollWheelZoom(true);
79 90 }
80   - onMounted(() => {
81   - initMap();
82   - });
83 91
84 92 const [registerTable] = useTable({
85 93 api: devicePage,
... ... @@ -106,6 +114,7 @@
106 114 };
107 115 map.centerAndZoom(point, 15);
108 116 map.enableScrollWheelZoom(true);
  117 + // 创建信息窗口对象
109 118 let infoWindow = new BMap.InfoWindow(
110 119 `
111 120 <div style="display:flex;justify-content:space-between; margin:20px 0px;">
... ... @@ -129,7 +138,7 @@
129 138 </div>
130 139 `,
131 140 options
132   - ); // 创建信息窗口对象
  141 + );
133 142 map.openInfoWindow(infoWindow, map.getCenter());
134 143 let preMarker = null;
135 144 const rivet =
... ... @@ -161,22 +170,89 @@
161 170 };
162 171
163 172 const [registerModal, { openModal }] = useModal();
164   - const [registerForm] = useForm({
  173 + const [registerForm, { resetFields }] = useForm({
165 174 labelWidth: 120,
166 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 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 246 return {
173 247 wrapRef,
174 248 registerTable,
175 249 deviceRowClick,
176 250 DeviceState,
177   - handleClick,
178 251 registerModal,
179 252 registerForm,
  253 + chartRef,
  254 + openHistoryModal,
  255 + cancelHistoryModal,
180 256 };
181 257 },
182 258 });
... ...
... ... @@ -8,8 +8,8 @@
8 8 import { useWebSocket } from '@vueuse/core';
9 9 import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
10 10 import { getAuthCache } from '/@/utils/auth';
11   - import type { socketDataType } from '../../types';
12 11 import { useMessage } from '/@/hooks/web/useMessage';
  12 + import type { socketDataType } from '../../types';
13 13 export default defineComponent({
14 14 name: 'RealTimeData',
15 15 components: {
... ... @@ -22,7 +22,7 @@
22 22 },
23 23 },
24 24 setup(props) {
25   - const token = getAuthCache(JWT_TOKEN_KEY);
  25 + const token: string = getAuthCache(JWT_TOKEN_KEY);
26 26 const state = reactive({
27 27 server: `ws://101.133.234.90:8080/api/ws/plugins/telemetry?token=${token}`,
28 28 sendValue: JSON.stringify({
... ... @@ -58,23 +58,22 @@
58 58 onConnected() {
59 59 send(state.sendValue);
60 60 console.log('建立连接了');
61   - console.log(props.deviceDetail.tbDeviceId);
62 61 },
63 62 onMessage(_, e) {
64 63 const { data } = JSON.parse(e.data);
65 64 console.log('来新消息了', 'data---', data);
66   - const newArray: any = [];
  65 + const newArray: socketDataType[] = [];
67 66 for (const key in data) {
68   - const newData = data[key].flat(1);
  67 + const [time, value] = data[key].flat(1);
69 68 let obj = {
70 69 key,
71   - time: newData[0],
72   - value: newData[1],
  70 + time,
  71 + value,
73 72 };
74 73 if (state.recordList.length === 0) {
75   - state.recordList.push(obj);
  74 + state.recordList.unshift(obj);
76 75 } else {
77   - newArray.push(obj);
  76 + newArray.unshift(obj);
78 77 }
79 78 }
80 79 newArray.forEach((item) => {
... ... @@ -91,7 +90,6 @@
91 90 }
92 91 });
93 92 },
94   - onDisconnected() {},
95 93 onError() {
96 94 createMessage.error('webSocket连接超时,请联系管理员');
97 95 },
... ...