...
|
...
|
@@ -4,128 +4,82 @@ |
4
|
4
|
v-bind="$attrs"
|
5
|
5
|
:active-tab-key="activeKey"
|
6
|
6
|
@tabChange="onTabChange"
|
|
7
|
+ v-if="!isAdmin(role)"
|
7
|
8
|
>
|
8
|
|
- <template #tabBarExtraContent v-if="!isAdmin(role)">
|
|
9
|
+ <template #tabBarExtraContent>
|
9
|
10
|
<div class="extra-date">
|
10
|
|
- <template v-for="(item, index) in dateList" :key="item">
|
11
|
|
- <span @click="changeDate(index)" :class="{ active: index === activeIndex }">{{
|
12
|
|
- item
|
|
11
|
+ <template v-for="(item, index) in dateList" :key="item.value">
|
|
12
|
+ <span @click="changeDate(index, item.value)" :class="{ active: index === activeIndex }">{{
|
|
13
|
+ item.label
|
13
|
14
|
}}</span>
|
14
|
15
|
</template>
|
15
|
16
|
<DatePicker @change="onDateChange" />
|
16
|
17
|
</div>
|
17
|
18
|
</template>
|
18
|
19
|
<div v-if="activeKey === '1'">
|
19
|
|
- <p class="center">{{ !isAdmin(role) ? '告警数' : '租户趋势' }}</p>
|
|
20
|
+ <p class="center">告警数</p>
|
|
21
|
+ <!-- 折线图 -->
|
20
|
22
|
<VisitAnalysis v-if="!isAdmin(role)" :alarmList="state.alarmList" />
|
21
|
|
- <VisitAnalysisBar v-else />
|
22
|
23
|
</div>
|
23
|
24
|
<div v-if="activeKey === '2'">
|
24
|
25
|
<p class="center">消息量</p>
|
25
|
|
- <VisitAnalysisBar :dataPointList="state.dataPointList" :messageList="state.messageList" />
|
|
26
|
+ <!-- 柱形图 -->
|
|
27
|
+ <VisitAnalysisBar
|
|
28
|
+ v-if="!isAdmin(role)"
|
|
29
|
+ :dataPointList="state.dataPointList"
|
|
30
|
+ :messageList="state.messageList"
|
|
31
|
+ />
|
26
|
32
|
</div>
|
27
|
33
|
</Card>
|
28
|
|
- <Card v-bind="$attrs" :tab-list="tab1ListTitle" v-if="isAdmin(role)">
|
29
|
|
- <p class="center">客户趋势</p>
|
30
|
|
- <VisitAnalysis
|
31
|
|
- /></Card>
|
|
34
|
+ <Card v-bind="$attrs" v-if="isAdmin(role)" title="租户趋势">
|
|
35
|
+ <TenantTrend />
|
|
36
|
+ </Card>
|
|
37
|
+ <Card v-bind="$attrs" v-if="isAdmin(role)" title="客户趋势">
|
|
38
|
+ <CustomerTrend />
|
|
39
|
+ </Card>
|
32
|
40
|
</template>
|
33
|
41
|
<script lang="ts" setup>
|
34
|
|
- import { ref, defineExpose, reactive } from 'vue';
|
|
42
|
+ import { ref, reactive } from 'vue';
|
35
|
43
|
import { Card, DatePicker } from 'ant-design-vue';
|
36
|
44
|
import VisitAnalysis from './VisitAnalysis.vue';
|
37
|
45
|
import VisitAnalysisBar from './VisitAnalysisBar.vue';
|
38
|
|
- import { defineProps } from 'vue';
|
39
|
46
|
import { isAdmin } from '/@/enums/roleEnum';
|
40
|
47
|
import { useWebSocket } from '@vueuse/core';
|
41
|
48
|
import { getAuthCache } from '/@/utils/auth';
|
|
49
|
+ import CustomerTrend from './CustomerTrend.vue';
|
|
50
|
+ import TenantTrend from './TenantTrend.vue';
|
42
|
51
|
import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum';
|
43
|
|
-
|
|
52
|
+ import { formatToDateTime } from '/@/utils/dateUtil';
|
|
53
|
+ import { getEntitiesId } from '/@/api/dashboard/index';
|
44
|
54
|
defineExpose({
|
45
|
55
|
isAdmin,
|
46
|
56
|
});
|
47
|
|
- const props = defineProps<{
|
|
57
|
+ defineProps<{
|
48
|
58
|
role: string;
|
49
|
59
|
}>();
|
50
|
60
|
const activeKey = ref('1');
|
51
|
|
-
|
52
|
|
- // 动态根据登录角色来判断
|
53
|
|
- const tabListTitle = !isAdmin(props.role)
|
54
|
|
- ? [
|
55
|
|
- {
|
56
|
|
- key: '1',
|
57
|
|
- tab: '告警数统计',
|
58
|
|
- },
|
59
|
|
- {
|
60
|
|
- key: '2',
|
61
|
|
- tab: '消息量统计',
|
62
|
|
- },
|
63
|
|
- ]
|
64
|
|
- : [
|
65
|
|
- {
|
66
|
|
- key: '1',
|
67
|
|
- tab: '租户',
|
68
|
|
- },
|
69
|
|
- ];
|
70
|
|
-
|
71
|
|
- const tab1ListTitle = [
|
|
61
|
+ let entityId = null;
|
|
62
|
+ // 图表tab切换选项卡
|
|
63
|
+ const tabListTitle = [
|
72
|
64
|
{
|
73
|
65
|
key: '1',
|
74
|
|
- tab: '客户',
|
|
66
|
+ tab: '告警数统计',
|
|
67
|
+ },
|
|
68
|
+ {
|
|
69
|
+ key: '2',
|
|
70
|
+ tab: '消息量统计',
|
75
|
71
|
},
|
76
|
72
|
];
|
77
|
|
-
|
78
|
|
- const dateList = ref(['1小时', '1天', '7天', '30天']);
|
|
73
|
+ const activeIndex = ref(0);
|
|
74
|
+ const dateList = ref([
|
|
75
|
+ { label: '1小时', value: 3600000 },
|
|
76
|
+ { label: '1天', value: 86400000 },
|
|
77
|
+ { label: '7天', value: 604800000 },
|
|
78
|
+ { label: '30天', value: 2592000000 },
|
|
79
|
+ ]);
|
79
|
80
|
// web Socket
|
80
|
81
|
const token: string = getAuthCache(JWT_TOKEN_KEY);
|
81
|
|
- const sendValue = JSON.stringify({
|
82
|
|
- entityDataCmds: [
|
83
|
|
- {
|
84
|
|
- query: {
|
85
|
|
- entityFilter: {
|
86
|
|
- type: 'singleEntity',
|
87
|
|
- singleEntity: {
|
88
|
|
- id: '33782740-5d97-11ec-8ac9-f38ed935ea2a',
|
89
|
|
- entityType: 'API_USAGE_STATE',
|
90
|
|
- },
|
91
|
|
- },
|
92
|
|
- pageLink: {
|
93
|
|
- pageSize: 1024,
|
94
|
|
- page: 0,
|
95
|
|
- sortOrder: {
|
96
|
|
- key: {
|
97
|
|
- type: 'ENTITY_FIELD',
|
98
|
|
- key: 'createdTime',
|
99
|
|
- },
|
100
|
|
- direction: 'DESC',
|
101
|
|
- },
|
102
|
|
- },
|
103
|
|
- entityFields: [
|
104
|
|
- {
|
105
|
|
- type: 'ENTITY_FIELD',
|
106
|
|
- key: 'name',
|
107
|
|
- },
|
108
|
|
- {
|
109
|
|
- type: 'ENTITY_FIELD',
|
110
|
|
- key: 'label',
|
111
|
|
- },
|
112
|
|
- {
|
113
|
|
- type: 'ENTITY_FIELD',
|
114
|
|
- key: 'additionalInfo',
|
115
|
|
- },
|
116
|
|
- ],
|
117
|
|
- latestValues: [
|
118
|
|
- {
|
119
|
|
- type: 'TIME_SERIES',
|
120
|
|
- key: 'createdAlarmsCountHourly',
|
121
|
|
- },
|
122
|
|
- ],
|
123
|
|
- },
|
124
|
|
- cmdId: activeKey.value,
|
125
|
|
- },
|
126
|
|
- ],
|
127
|
|
- });
|
128
|
|
- const activeIndex = ref(0);
|
|
82
|
+
|
129
|
83
|
const state = reactive({
|
130
|
84
|
server: `${import.meta.env.VITE_WEB_SOCKET}${token}`,
|
131
|
85
|
alarmList: new Array<[number, string]>(),
|
...
|
...
|
@@ -136,7 +90,53 @@ |
136
|
90
|
MsgCount: new Array<[number, string]>(),
|
137
|
91
|
});
|
138
|
92
|
const { send, close } = useWebSocket(state.server, {
|
139
|
|
- onConnected() {
|
|
93
|
+ async onConnected() {
|
|
94
|
+ const res = await getEntitiesId();
|
|
95
|
+ entityId = res.data[0].entityId;
|
|
96
|
+ const sendValue = JSON.stringify({
|
|
97
|
+ entityDataCmds: [
|
|
98
|
+ {
|
|
99
|
+ query: {
|
|
100
|
+ entityFilter: {
|
|
101
|
+ type: 'singleEntity',
|
|
102
|
+ singleEntity: entityId,
|
|
103
|
+ },
|
|
104
|
+ pageLink: {
|
|
105
|
+ pageSize: 1024,
|
|
106
|
+ page: 0,
|
|
107
|
+ sortOrder: {
|
|
108
|
+ key: {
|
|
109
|
+ type: 'ENTITY_FIELD',
|
|
110
|
+ key: 'createdTime',
|
|
111
|
+ },
|
|
112
|
+ direction: 'DESC',
|
|
113
|
+ },
|
|
114
|
+ },
|
|
115
|
+ entityFields: [
|
|
116
|
+ {
|
|
117
|
+ type: 'ENTITY_FIELD',
|
|
118
|
+ key: 'name',
|
|
119
|
+ },
|
|
120
|
+ {
|
|
121
|
+ type: 'ENTITY_FIELD',
|
|
122
|
+ key: 'label',
|
|
123
|
+ },
|
|
124
|
+ {
|
|
125
|
+ type: 'ENTITY_FIELD',
|
|
126
|
+ key: 'additionalInfo',
|
|
127
|
+ },
|
|
128
|
+ ],
|
|
129
|
+ latestValues: [
|
|
130
|
+ {
|
|
131
|
+ type: 'TIME_SERIES',
|
|
132
|
+ key: 'createdAlarmsCountHourly',
|
|
133
|
+ },
|
|
134
|
+ ],
|
|
135
|
+ },
|
|
136
|
+ cmdId: activeKey.value,
|
|
137
|
+ },
|
|
138
|
+ ],
|
|
139
|
+ });
|
140
|
140
|
send(sendValue);
|
141
|
141
|
console.log('建立连接了');
|
142
|
142
|
},
|
...
|
...
|
@@ -144,9 +144,12 @@ |
144
|
144
|
const { data, update } = JSON.parse(e.data);
|
145
|
145
|
if (activeKey.value === '1') {
|
146
|
146
|
if (data) {
|
147
|
|
- const { createdAlarmsCountHourly } = data.data[0].latest.TIME_SERIES;
|
148
|
|
- state.alarmItem = [createdAlarmsCountHourly.ts, createdAlarmsCountHourly.value];
|
149
|
|
- state.alarmList.push([createdAlarmsCountHourly.ts, createdAlarmsCountHourly.value]);
|
|
147
|
+ const alarmData = data.data[0]?.latest.TIME_SERIES;
|
|
148
|
+ if (alarmData?.createdAlarmsCountHourly) {
|
|
149
|
+ const { createdAlarmsCountHourly } = alarmData;
|
|
150
|
+ state.alarmItem = [createdAlarmsCountHourly.ts, createdAlarmsCountHourly.value];
|
|
151
|
+ state.alarmList.push([createdAlarmsCountHourly.ts, createdAlarmsCountHourly.value]);
|
|
152
|
+ }
|
150
|
153
|
}
|
151
|
154
|
if (update) {
|
152
|
155
|
const { createdAlarmsCountHourly } = update[0].timeseries;
|
...
|
...
|
@@ -177,8 +180,9 @@ |
177
|
180
|
}
|
178
|
181
|
if (update) {
|
179
|
182
|
const { transportDataPointsCountHourly, transportMsgCountHourly } = update[0].timeseries;
|
180
|
|
- const newArray: any = [];
|
181
|
|
- const newArray1: any = [];
|
|
183
|
+ const newArray: any[] = [];
|
|
184
|
+ const newArray1: any[] = [];
|
|
185
|
+ console.log(update[0]);
|
182
|
186
|
for (const item of transportDataPointsCountHourly) {
|
183
|
187
|
newArray.push([item.ts, item.value]);
|
184
|
188
|
}
|
...
|
...
|
@@ -208,7 +212,7 @@ |
208
|
212
|
endTs: 1641370336692,
|
209
|
213
|
interval: 43200000,
|
210
|
214
|
limit: 60,
|
211
|
|
- agg: 'SUM',
|
|
215
|
+ agg: 'COUNT',
|
212
|
216
|
},
|
213
|
217
|
},
|
214
|
218
|
],
|
...
|
...
|
@@ -221,10 +225,7 @@ |
221
|
225
|
query: {
|
222
|
226
|
entityFilter: {
|
223
|
227
|
type: 'singleEntity',
|
224
|
|
- singleEntity: {
|
225
|
|
- id: '33782740-5d97-11ec-8ac9-f38ed935ea2a',
|
226
|
|
- entityType: 'API_USAGE_STATE',
|
227
|
|
- },
|
|
228
|
+ singleEntity: entityId,
|
228
|
229
|
},
|
229
|
230
|
pageLink: {
|
230
|
231
|
pageSize: 1024,
|
...
|
...
|
@@ -285,11 +286,42 @@ |
285
|
286
|
send(sendMessageValue2);
|
286
|
287
|
}
|
287
|
288
|
}
|
288
|
|
- function onDateChange(date, dateString) {
|
289
|
|
- console.log(date, dateString);
|
|
289
|
+ function onDateChange(_, dateString) {
|
|
290
|
+ const dateTime = formatToDateTime(dateString, 'x');
|
|
291
|
+ console.log(dateTime);
|
290
|
292
|
}
|
291
|
|
- function changeDate(index: number) {
|
|
293
|
+ function changeDate(index: number, value: number) {
|
292
|
294
|
activeIndex.value = index;
|
|
295
|
+ let limit;
|
|
296
|
+ if (value === 3600000 || value === 86400000) {
|
|
297
|
+ limit = 12;
|
|
298
|
+ } else if (value === 604800000) {
|
|
299
|
+ limit = 7;
|
|
300
|
+ } else if (value === 2592000000) {
|
|
301
|
+ limit = 30;
|
|
302
|
+ }
|
|
303
|
+ // 动态发送ws数据
|
|
304
|
+ const sendValue = JSON.stringify({
|
|
305
|
+ entityDataCmds: [
|
|
306
|
+ {
|
|
307
|
+ cmdId: activeKey.value,
|
|
308
|
+ historyCmd: {
|
|
309
|
+ keys:
|
|
310
|
+ activeKey.value === '1'
|
|
311
|
+ ? ['createdAlarmsCountHourly']
|
|
312
|
+ : ['transportMsgCountHourly', 'transportDataPointsCountHourly'],
|
|
313
|
+ startTs: Date.now() - value,
|
|
314
|
+ endTs: Date.now(),
|
|
315
|
+ interval: value > 3600000 ? 7200000 : 300000,
|
|
316
|
+ limit,
|
|
317
|
+ agg: 'COUNT',
|
|
318
|
+ },
|
|
319
|
+ },
|
|
320
|
+ ],
|
|
321
|
+ });
|
|
322
|
+ send(sendValue);
|
|
323
|
+
|
|
324
|
+ console.log(value);
|
293
|
325
|
}
|
294
|
326
|
</script>
|
295
|
327
|
|
...
|
...
|
|