RealTimeData.vue
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<template>
<BasicTable @register="registerTable" />
</template>
<script lang="ts">
import { defineComponent, reactive, onMounted, onUnmounted } from 'vue';
import { BasicTable, useTable } from '/@/components/Table';
import { realTimeDataColumns, realTimeDataSearchSchemas } from '../../config/detail.config';
import { useWebSocket } from '@vueuse/core';
import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
import { getAuthCache } from '/@/utils/auth';
export default defineComponent({
name: 'DeviceManagement',
components: {
BasicTable,
},
setup(_) {
const [registerTable] = useTable({
columns: realTimeDataColumns,
formConfig: {
labelWidth: 120,
schemas: realTimeDataSearchSchemas,
},
useSearchForm: true,
showTableSetting: true,
bordered: true,
showIndexColumn: false,
});
const token = getAuthCache(JWT_TOKEN_KEY);
const state = reactive({
server: `ws://192.168.10.139:8080/api/ws/plugins/telemetry?token=${token}`,
sendValue: '',
recordList: [] as { id: number; time: number; res: string }[],
});
const { status, data, send, close, open } = useWebSocket(state.server, {
autoReconnect: false,
heartbeat: true,
});
onMounted(() => {
open();
send(
JSON.stringify({
attrSubCmds: [],
tsSubCmds: [
{
entityType: 'DEVICE',
entityId: '3199a500-6302-11ec-ba36-417bcc842c0a',
scope: 'LATEST_TELEMETRY',
cmdId: 1,
},
],
historyCmds: [],
entityDataCmds: [],
entityDataUnsubscribeCmds: [],
alarmDataCmds: [],
alarmDataUnsubscribeCmds: [],
entityCountCmds: [],
entityCountUnsubscribeCmds: [],
})
);
console.log(JSON.parse(data.value));
});
onUnmounted(() => {
close();
});
return {
registerTable,
};
},
});
</script>