|
1
|
+<template>
|
|
2
|
+ <Card
|
|
3
|
+ :tab-list="tabListTitle"
|
|
4
|
+ v-bind="$attrs"
|
|
5
|
+ :active-tab-key="activeKey"
|
|
6
|
+ @tabChange="onTabChange"
|
|
7
|
+ v-if="!isAdmin(role)"
|
|
8
|
+ >
|
|
9
|
+ <template #tabBarExtraContent>
|
|
10
|
+ <div class="extra-date">
|
|
11
|
+ <template v-for="(item, index) in dateList" :key="item.value">
|
|
12
|
+ <span
|
|
13
|
+ @click="quickQueryDate(index, item.value, role === 'CUSTOMER_USER' && 'customer')"
|
|
14
|
+ :class="{ active: index === activeIndex }"
|
|
15
|
+ >{{ item.label }}</span
|
|
16
|
+ >
|
|
17
|
+ </template>
|
|
18
|
+ <DatePicker
|
|
19
|
+ @change="
|
|
20
|
+ (_, DateString) => onDateChange(_, DateString, role === 'CUSTOMER_USER' && 'customer')
|
|
21
|
+ "
|
|
22
|
+ v-model:value="dateValue"
|
|
23
|
+ />
|
|
24
|
+ </div>
|
|
25
|
+ </template>
|
|
26
|
+ <div v-if="activeKey === '1'">
|
|
27
|
+ <!-- 折线图 -->
|
|
28
|
+ <CustomerAlarmMessage
|
|
29
|
+ v-if="role === 'CUSTOMER_USER'"
|
|
30
|
+ type="CUSTOMER_ALARM_STATISTICAL"
|
|
31
|
+ :customerList="customerAlarmList"
|
|
32
|
+ />
|
|
33
|
+ <VisitAnalysis v-else :alarmList="state.alarmList" />
|
|
34
|
+ </div>
|
|
35
|
+ <div v-if="activeKey === '2'">
|
|
36
|
+ <!-- 柱形图 -->
|
|
37
|
+ <CustomerAlarmMessage
|
|
38
|
+ v-if="role === 'CUSTOMER_USER'"
|
|
39
|
+ type="CUSTOMER_MESSAGE_STATISTICAL"
|
|
40
|
+ :customerList="customerMessageList"
|
|
41
|
+ />
|
|
42
|
+ <VisitAnalysisBar
|
|
43
|
+ v-else
|
|
44
|
+ :dataPointList="state.dataPointList"
|
|
45
|
+ :messageList="state.messageList"
|
|
46
|
+ />
|
|
47
|
+ </div>
|
|
48
|
+ </Card>
|
|
49
|
+ <div v-if="isAdmin(role)">
|
|
50
|
+ <Card
|
|
51
|
+ v-bind="$attrs"
|
|
52
|
+ title="租户趋势"
|
|
53
|
+ style="height: 26.75rem"
|
|
54
|
+ :bodyStyle="{ padding: '0 24px' }"
|
|
55
|
+ >
|
|
56
|
+ <template #extra>
|
|
57
|
+ <div class="extra-date">
|
|
58
|
+ <template v-for="(item, index) in TenantOrCustomerDateList" :key="item.value">
|
|
59
|
+ <span
|
|
60
|
+ @click="quickQueryTenantOrCustomerTime(index, item.value, 'tenant')"
|
|
61
|
+ :class="{ active: index === activeTenantIndex }"
|
|
62
|
+ >{{ item.label }}</span
|
|
63
|
+ >
|
|
64
|
+ </template>
|
|
65
|
+ <DatePicker.RangePicker
|
|
66
|
+ @change="onDateTenantChange"
|
|
67
|
+ size="small"
|
|
68
|
+ v-model:value="tenantDateValue"
|
|
69
|
+ />
|
|
70
|
+ </div>
|
|
71
|
+ </template>
|
|
72
|
+ <TenantTrend :tenantTrendList="tenantTrendList" />
|
|
73
|
+ </Card>
|
|
74
|
+ <!-- <Card
|
|
75
|
+ v-bind="$attrs"
|
|
76
|
+ title="客户趋势"
|
|
77
|
+ style="height: 26.75rem"
|
|
78
|
+ :bodyStyle="{ padding: '0 24px' }"
|
|
79
|
+ >
|
|
80
|
+ <template #extra>
|
|
81
|
+ <div class="extra-date">
|
|
82
|
+ <template v-for="(item, index) in TenantOrCustomerDateList" :key="item.value">
|
|
83
|
+ <span
|
|
84
|
+ @click="quickQueryTenantOrCustomerTime(index, item.value)"
|
|
85
|
+ :class="{ active: index === activeCustomerIndex }"
|
|
86
|
+ >{{ item.label }}</span
|
|
87
|
+ >
|
|
88
|
+ </template>
|
|
89
|
+ <DatePicker.RangePicker
|
|
90
|
+ @change="onDateCustomerChange"
|
|
91
|
+ size="small"
|
|
92
|
+ v-model:value="customerDateValue"
|
|
93
|
+ />
|
|
94
|
+ </div>
|
|
95
|
+ </template>
|
|
96
|
+ <CustomerTrend :customerTrendList="customerTrendList" />
|
|
97
|
+ </Card> -->
|
|
98
|
+ </div>
|
|
99
|
+</template>
|
|
100
|
+<script lang="ts" setup>
|
|
101
|
+ import { ref, reactive } from 'vue';
|
|
102
|
+ import { Card, DatePicker } from 'ant-design-vue';
|
|
103
|
+ import VisitAnalysis from './VisitAnalysis.vue';
|
|
104
|
+ import VisitAnalysisBar from './VisitAnalysisBar.vue';
|
|
105
|
+ import { isAdmin } from '/@/enums/roleEnum';
|
|
106
|
+ import { useWebSocket } from '@vueuse/core';
|
|
107
|
+ import { getAuthCache } from '/@/utils/auth';
|
|
108
|
+ import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
|
|
109
|
+ import { formatToDateTime } from '/@/utils/dateUtil';
|
|
110
|
+ import { getEntitiesId } from '/@/api/dashboard/index';
|
|
111
|
+ // import CustomerTrend from './CustomerTrend.vue';
|
|
112
|
+ import TenantTrend from './TenantTrend.vue';
|
|
113
|
+ import CustomerAlarmMessage from './CustomerAlarmMessage.vue';
|
|
114
|
+ import { useDate } from '../hooks/useDate';
|
|
115
|
+ import { getTrendData } from '/@/api/dashboard';
|
|
116
|
+ import { useGlobSetting } from '/@/hooks/setting';
|
|
117
|
+
|
|
118
|
+ defineExpose({
|
|
119
|
+ isAdmin,
|
|
120
|
+ });
|
|
121
|
+ const props = defineProps<{
|
|
122
|
+ role: string;
|
|
123
|
+ }>();
|
|
124
|
+ const activeKey = ref('2');
|
|
125
|
+ let entityId = null;
|
|
126
|
+ // 图表tab切换选项卡 1965 1280 1861 836
|
|
127
|
+ const tabListTitle = [
|
|
128
|
+ // {
|
|
129
|
+ // key: '1',
|
|
130
|
+ // tab: '告警数统计',
|
|
131
|
+ // },
|
|
132
|
+ {
|
|
133
|
+ key: '2',
|
|
134
|
+ tab: '消息量统计',
|
|
135
|
+ },
|
|
136
|
+ ];
|
|
137
|
+ // 快速选择日期
|
|
138
|
+ const activeIndex = ref(3);
|
|
139
|
+ const dateValue = ref();
|
|
140
|
+ const dateList = ref([
|
|
141
|
+ { label: '1小时', value: 3600000 },
|
|
142
|
+ { label: '1天', value: 86400000 },
|
|
143
|
+ { label: '7天', value: 604800000 },
|
|
144
|
+ { label: '30天', value: 2592000000 },
|
|
145
|
+ ]);
|
|
146
|
+
|
|
147
|
+ // web Socket
|
|
148
|
+ const token: string = getAuthCache(JWT_TOKEN_KEY);
|
|
149
|
+ const { socketUrl } = useGlobSetting();
|
|
150
|
+ const state = reactive({
|
|
151
|
+ server: `${socketUrl}${token}`,
|
|
152
|
+ alarmList: new Array<[number, string]>(),
|
|
153
|
+ alarmItem: new Array<[number, string]>(),
|
|
154
|
+ dataPointList: new Array<[number, string]>(),
|
|
155
|
+ messageList: new Array<[number, string]>(),
|
|
156
|
+ dataPoint: new Array<[number, string]>(),
|
|
157
|
+ MsgCount: new Array<[number, string]>(),
|
|
158
|
+ });
|
|
159
|
+ const { send, close } = useWebSocket(state.server, {
|
|
160
|
+ async onConnected() {
|
|
161
|
+ if (isAdmin(props.role)) return;
|
|
162
|
+ const res = await getEntitiesId();
|
|
163
|
+ entityId = res.data[0]?.entityId;
|
|
164
|
+ const sendValue = JSON.stringify({
|
|
165
|
+ entityDataCmds: [
|
|
166
|
+ {
|
|
167
|
+ query: {
|
|
168
|
+ entityFilter: {
|
|
169
|
+ type: 'singleEntity',
|
|
170
|
+ singleEntity: entityId,
|
|
171
|
+ },
|
|
172
|
+ pageLink: {
|
|
173
|
+ pageSize: 1024,
|
|
174
|
+ page: 0,
|
|
175
|
+ sortOrder: {
|
|
176
|
+ key: {
|
|
177
|
+ type: 'ENTITY_FIELD',
|
|
178
|
+ key: 'createdTime',
|
|
179
|
+ },
|
|
180
|
+ direction: 'DESC',
|
|
181
|
+ },
|
|
182
|
+ },
|
|
183
|
+ entityFields: [
|
|
184
|
+ {
|
|
185
|
+ type: 'ENTITY_FIELD',
|
|
186
|
+ key: 'name',
|
|
187
|
+ },
|
|
188
|
+ {
|
|
189
|
+ type: 'ENTITY_FIELD',
|
|
190
|
+ key: 'label',
|
|
191
|
+ },
|
|
192
|
+ {
|
|
193
|
+ type: 'ENTITY_FIELD',
|
|
194
|
+ key: 'additionalInfo',
|
|
195
|
+ },
|
|
196
|
+ ],
|
|
197
|
+ latestValues: [
|
|
198
|
+ {
|
|
199
|
+ type: 'TIME_SERIES',
|
|
200
|
+ key: 'createdAlarmsCountHourly',
|
|
201
|
+ },
|
|
202
|
+ ],
|
|
203
|
+ },
|
|
204
|
+ cmdId: activeKey.value,
|
|
205
|
+ },
|
|
206
|
+ ],
|
|
207
|
+ });
|
|
208
|
+ const sendValue1 = JSON.stringify({
|
|
209
|
+ entityDataCmds: [
|
|
210
|
+ {
|
|
211
|
+ cmdId: activeKey.value,
|
|
212
|
+ historyCmd: {
|
|
213
|
+ keys: ['createdAlarmsCountHourly'],
|
|
214
|
+ startTs: Date.now() - 2592000000,
|
|
215
|
+ endTs: Date.now(),
|
|
216
|
+ interval: 86400000,
|
|
217
|
+ agg: 'SUM',
|
|
218
|
+ },
|
|
219
|
+ },
|
|
220
|
+ ],
|
|
221
|
+ });
|
|
222
|
+ send(sendValue);
|
|
223
|
+ send(sendValue1);
|
|
224
|
+ },
|
|
225
|
+ onMessage(_, e) {
|
|
226
|
+ const { data, update } = JSON.parse(e.data);
|
|
227
|
+ if (activeKey.value === '1') {
|
|
228
|
+ if (data) {
|
|
229
|
+ const { createdAlarmsCountHourly } = data.data[0].latest.TIME_SERIES;
|
|
230
|
+ state.alarmItem = [createdAlarmsCountHourly.ts, createdAlarmsCountHourly.value];
|
|
231
|
+ state.alarmList.push([createdAlarmsCountHourly.ts, createdAlarmsCountHourly.value]);
|
|
232
|
+ }
|
|
233
|
+ if (update) {
|
|
234
|
+ const { createdAlarmsCountHourly } = update[0].timeseries;
|
|
235
|
+ const newArray: any = [];
|
|
236
|
+ for (const item of createdAlarmsCountHourly) {
|
|
237
|
+ newArray.push([item.ts, item.value]);
|
|
238
|
+ }
|
|
239
|
+ state.alarmList = newArray;
|
|
240
|
+ }
|
|
241
|
+ } else {
|
|
242
|
+ if (data) {
|
|
243
|
+ const { transportDataPointsCountHourly, transportMsgCountHourly } =
|
|
244
|
+ data.data[0].latest.TIME_SERIES;
|
|
245
|
+ state.dataPoint = [
|
|
246
|
+ transportDataPointsCountHourly.ts,
|
|
247
|
+ transportDataPointsCountHourly.value,
|
|
248
|
+ ];
|
|
249
|
+ state.MsgCount = [
|
|
250
|
+ transportDataPointsCountHourly.ts,
|
|
251
|
+ transportDataPointsCountHourly.value,
|
|
252
|
+ ];
|
|
253
|
+ state.dataPointList.push([
|
|
254
|
+ transportDataPointsCountHourly.ts,
|
|
255
|
+ transportDataPointsCountHourly.value,
|
|
256
|
+ ]);
|
|
257
|
+ state.messageList.push([transportMsgCountHourly.ts, transportMsgCountHourly.value]);
|
|
258
|
+ }
|
|
259
|
+ if (update) {
|
|
260
|
+ const { transportDataPointsCountHourly, transportMsgCountHourly } = update[0].timeseries;
|
|
261
|
+ const newArray: any[] = [];
|
|
262
|
+ const newArray1: any[] = [];
|
|
263
|
+ for (const item of transportDataPointsCountHourly) {
|
|
264
|
+ newArray.push([item.ts, item.value]);
|
|
265
|
+ }
|
|
266
|
+ for (const item of transportMsgCountHourly) {
|
|
267
|
+ newArray1.push([item.ts, item.value]);
|
|
268
|
+ }
|
|
269
|
+ state.dataPointList = newArray;
|
|
270
|
+ state.messageList = newArray1;
|
|
271
|
+ }
|
|
272
|
+ }
|
|
273
|
+ },
|
|
274
|
+ onDisconnected() {
|
|
275
|
+ console.log('断开连接了');
|
|
276
|
+ close();
|
|
277
|
+ },
|
|
278
|
+ });
|
|
279
|
+
|
|
280
|
+ // 切换tab页
|
|
281
|
+ function onTabChange(key: string) {
|
|
282
|
+ activeKey.value = key;
|
|
283
|
+ activeIndex.value = 3;
|
|
284
|
+ dateValue.value = '';
|
|
285
|
+ const sendValue = JSON.stringify({
|
|
286
|
+ entityDataCmds: [
|
|
287
|
+ {
|
|
288
|
+ cmdId: activeKey.value,
|
|
289
|
+ historyCmd: {
|
|
290
|
+ keys:
|
|
291
|
+ activeKey.value === '1'
|
|
292
|
+ ? ['createdAlarmsCountHourly']
|
|
293
|
+ : ['transportMsgCountHourly', 'transportDataPointsCountHourly'],
|
|
294
|
+ startTs: Date.now() - 2592000000,
|
|
295
|
+ endTs: Date.now(),
|
|
296
|
+ interval: 86400000,
|
|
297
|
+ agg: 'SUM',
|
|
298
|
+ },
|
|
299
|
+ },
|
|
300
|
+ ],
|
|
301
|
+ });
|
|
302
|
+ if (key === '2') {
|
|
303
|
+ const sendMessageValue = JSON.stringify({
|
|
304
|
+ entityDataCmds: [
|
|
305
|
+ {
|
|
306
|
+ query: {
|
|
307
|
+ entityFilter: {
|
|
308
|
+ type: 'singleEntity',
|
|
309
|
+ singleEntity: entityId,
|
|
310
|
+ },
|
|
311
|
+ pageLink: {
|
|
312
|
+ pageSize: 1024,
|
|
313
|
+ page: 0,
|
|
314
|
+ sortOrder: {
|
|
315
|
+ key: {
|
|
316
|
+ type: 'ENTITY_FIELD',
|
|
317
|
+ key: 'createdTime',
|
|
318
|
+ },
|
|
319
|
+ direction: 'DESC',
|
|
320
|
+ },
|
|
321
|
+ },
|
|
322
|
+ entityFields: [
|
|
323
|
+ {
|
|
324
|
+ type: 'ENTITY_FIELD',
|
|
325
|
+ key: 'name',
|
|
326
|
+ },
|
|
327
|
+ {
|
|
328
|
+ type: 'ENTITY_FIELD',
|
|
329
|
+ key: 'label',
|
|
330
|
+ },
|
|
331
|
+ {
|
|
332
|
+ type: 'ENTITY_FIELD',
|
|
333
|
+ key: 'additionalInfo',
|
|
334
|
+ },
|
|
335
|
+ ],
|
|
336
|
+ latestValues: [
|
|
337
|
+ {
|
|
338
|
+ type: 'TIME_SERIES',
|
|
339
|
+ key: 'transportMsgCountHourly',
|
|
340
|
+ },
|
|
341
|
+ {
|
|
342
|
+ type: 'TIME_SERIES',
|
|
343
|
+ key: 'transportDataPointsCountHourly',
|
|
344
|
+ },
|
|
345
|
+ ],
|
|
346
|
+ },
|
|
347
|
+ cmdId: activeKey.value,
|
|
348
|
+ },
|
|
349
|
+ ],
|
|
350
|
+ });
|
|
351
|
+ send(sendMessageValue);
|
|
352
|
+ }
|
|
353
|
+ send(sendValue);
|
|
354
|
+ }
|
|
355
|
+ // 选择日期
|
|
356
|
+ async function onDateChange(_, dateString, roleType = '') {
|
|
357
|
+ console.log(_, dateString, roleType);
|
|
358
|
+ activeIndex.value = -1;
|
|
359
|
+ const dateTime = Number(formatToDateTime(dateString, 'x'));
|
|
360
|
+ if (!dateString) return;
|
|
361
|
+ if (roleType === 'customer') {
|
|
362
|
+ if (activeKey.value === '1') {
|
|
363
|
+ const data = await getTrendData({
|
|
364
|
+ startTs: dateTime,
|
|
365
|
+ endTs: dateTime + 86400000,
|
|
366
|
+ interval: 7200000,
|
|
367
|
+ trend: 'CUSTOMER_ALARM_STATISTICAL',
|
|
368
|
+ });
|
|
369
|
+ customerAlarmList.value = data;
|
|
370
|
+ } else if (activeKey.value === '2') {
|
|
371
|
+ const data = await getTrendData({
|
|
372
|
+ startTs: dateTime,
|
|
373
|
+ endTs: dateTime + 86400000,
|
|
374
|
+ interval: 7200000,
|
|
375
|
+ trend: 'CUSTOMER_MESSAGE_STATISTICAL',
|
|
376
|
+ });
|
|
377
|
+ customerMessageList.value = data;
|
|
378
|
+ }
|
|
379
|
+ } else {
|
|
380
|
+ // 动态发送ws数据
|
|
381
|
+ const sendValue = JSON.stringify({
|
|
382
|
+ entityDataCmds: [
|
|
383
|
+ {
|
|
384
|
+ cmdId: activeKey.value,
|
|
385
|
+ historyCmd: {
|
|
386
|
+ keys:
|
|
387
|
+ activeKey.value === '1'
|
|
388
|
+ ? ['createdAlarmsCountHourly']
|
|
389
|
+ : ['transportMsgCountHourly', 'transportDataPointsCountHourly'],
|
|
390
|
+ startTs: dateTime,
|
|
391
|
+ endTs: dateTime + 86400000,
|
|
392
|
+ interval: 7200000,
|
|
393
|
+ limit: 12,
|
|
394
|
+ agg: 'SUM',
|
|
395
|
+ },
|
|
396
|
+ },
|
|
397
|
+ ],
|
|
398
|
+ });
|
|
399
|
+ send(sendValue);
|
|
400
|
+ }
|
|
401
|
+ }
|
|
402
|
+ const customerAlarmList = ref([]);
|
|
403
|
+ const customerMessageList = ref([]);
|
|
404
|
+ // 快速选择时间
|
|
405
|
+ async function quickQueryDate(index: number, value: number, roleType = '') {
|
|
406
|
+ if (activeIndex.value === index) return;
|
|
407
|
+ activeIndex.value = index;
|
|
408
|
+ dateValue.value = '';
|
|
409
|
+ let interval = 300000;
|
|
410
|
+ if (value === 86400000) {
|
|
411
|
+ interval = 7200000;
|
|
412
|
+ } else if (value === 604800000 || value === 2592000000) {
|
|
413
|
+ interval = 86400000;
|
|
414
|
+ }
|
|
415
|
+ if (roleType === 'customer') {
|
|
416
|
+ if (activeKey.value === '1') {
|
|
417
|
+ const data = await getTrendData({
|
|
418
|
+ startTs: Date.now() - value,
|
|
419
|
+ endTs: Date.now(),
|
|
420
|
+ interval,
|
|
421
|
+ trend: 'CUSTOMER_ALARM_STATISTICAL',
|
|
422
|
+ });
|
|
423
|
+ customerAlarmList.value = data;
|
|
424
|
+ } else if (activeKey.value === '2') {
|
|
425
|
+ const data = await getTrendData({
|
|
426
|
+ startTs: Date.now() - value,
|
|
427
|
+ endTs: Date.now(),
|
|
428
|
+ interval,
|
|
429
|
+ trend: 'CUSTOMER_MESSAGE_STATISTICAL',
|
|
430
|
+ });
|
|
431
|
+ customerMessageList.value = data;
|
|
432
|
+ }
|
|
433
|
+ } else {
|
|
434
|
+ // 动态发送ws数据
|
|
435
|
+ const sendValue = JSON.stringify({
|
|
436
|
+ entityDataCmds: [
|
|
437
|
+ {
|
|
438
|
+ cmdId: activeKey.value,
|
|
439
|
+ historyCmd: {
|
|
440
|
+ keys:
|
|
441
|
+ activeKey.value === '1'
|
|
442
|
+ ? ['createdAlarmsCountHourly']
|
|
443
|
+ : ['transportMsgCountHourly', 'transportDataPointsCountHourly'],
|
|
444
|
+ startTs: Date.now() - value,
|
|
445
|
+ endTs: Date.now(),
|
|
446
|
+ interval,
|
|
447
|
+ agg: 'SUM',
|
|
448
|
+ },
|
|
449
|
+ },
|
|
450
|
+ ],
|
|
451
|
+ });
|
|
452
|
+ send(sendValue);
|
|
453
|
+ }
|
|
454
|
+ }
|
|
455
|
+ const {
|
|
456
|
+ tenantDateValue,
|
|
457
|
+ // customerDateValue,
|
|
458
|
+ tenantTrendList,
|
|
459
|
+ // customerTrendList,
|
|
460
|
+ activeTenantIndex,
|
|
461
|
+ // activeCustomerIndex,
|
|
462
|
+ TenantOrCustomerDateList,
|
|
463
|
+ quickQueryTenantOrCustomerTime,
|
|
464
|
+ onDateTenantChange,
|
|
465
|
+ // onDateCustomerChange,
|
|
466
|
+ } = useDate();
|
|
467
|
+</script>
|
|
468
|
+
|
|
469
|
+<style lang="less">
|
|
470
|
+ .center {
|
|
471
|
+ display: flex;
|
|
472
|
+ justify-content: center;
|
|
473
|
+ font-size: 16px;
|
|
474
|
+ }
|
|
475
|
+
|
|
476
|
+ .active {
|
|
477
|
+ color: #0960bd;
|
|
478
|
+ font-weight: 500;
|
|
479
|
+ }
|
|
480
|
+
|
|
481
|
+ .extra-date {
|
|
482
|
+ display: flex;
|
|
483
|
+ align-items: center;
|
|
484
|
+ justify-content: space-between;
|
|
485
|
+
|
|
486
|
+ span {
|
|
487
|
+ margin-right: 20px;
|
|
488
|
+ cursor: pointer;
|
|
489
|
+ }
|
|
490
|
+ }
|
|
491
|
+</style> |
...
|
...
|
|