GrowCard.vue
11 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<template>
<div>
<!-- 首页基础信息 -->
<section class="flex gap-4">
<StatisticalCard
:style="{ width: `${100 / statisticalPanelList.length}%` }"
v-for="(item, index) in statisticalPanelList"
:key="index"
:value="item"
/>
</section>
<!-- 首页饼图 -->
<div class="md:flex mt-4" v-if="!isAdmin(role)">
<Card
size="small"
class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:mr-4"
style="color: #666; width: 50%"
title="设备数量统计"
>
<a-row type="flex" justify="space-between" align="middle">
<a-col :span="12">
<PieChartDeviceSub
v-if="seriesData.length > 0"
:legendData="legendData"
:seriesData="seriesData"
:isCircle="false"
/></a-col>
<a-col :span="12">
<a-row type="flex" justify="space-between" align="middle" style="row-gap: 30px">
<a-col :offset="8" class="flex items-center">
<span class="left-icon-d-color"></span>
直连设备:
<span class="bold-text">{{ growCardList?.deviceInfo?.directConnection ?? 0 }}</span
>个</a-col
>
<a-col :offset="8" class="flex items-center">
<span class="left-icon-g-color"></span>
网关设备:
<span class="bold-text">{{ growCardList?.deviceInfo?.gateWay ?? 0 }}</span
>个</a-col
>
<a-col :offset="8" class="flex items-center">
<span class="left-icon-s-color"></span>
网关子设备:<span class="bold-text">{{
growCardList?.deviceInfo?.sensor ?? 0
}}</span
>个</a-col
>
</a-row>
</a-col>
</a-row>
</Card>
<Card
size="small"
class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:ml-1"
style="color: #666; width: 50%"
title="设备状态统计"
>
<a-row type="flex" justify="space-between" align="middle">
<a-col :span="12">
<PieChartDeviceStatus
v-if="seriesStatusData.length > 0"
:seriesStatusData="seriesStatusData"
/>
<div class="empty-box" v-else><Empty :image="Empty.PRESENTED_IMAGE_SIMPLE" /></div>
</a-col>
<a-col :span="12">
<a-row type="flex" justify="space-between" align="middle" style="row-gap: 30px">
<a-col :offset="8" class="flex items-center">
<span class="right-icon-d-color"></span>
待激活设备:
<span class="bold-text">{{ growCardList?.deviceInfo?.inActive ?? 0 }}</span
>个</a-col
>
<a-col :offset="8" class="flex items-center">
<span class="right-icon-g-color"></span>
在线设备:<span class="bold-text">{{ growCardList?.deviceInfo?.onLine ?? 0 }}</span
>个</a-col
>
<a-col :offset="8" class="flex items-center">
<span class="right-icon-s-color"></span>
离线设备:<span class="bold-text">{{ growCardList?.deviceInfo?.offLine ?? 0 }}</span
>个</a-col
>
</a-row>
</a-col>
</a-row>
</Card>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, onMounted, defineComponent, Ref, computed } from 'vue';
import { Card } from 'ant-design-vue';
import { getHomeData } from '/@/api/dashboard';
import { isAdmin } from '/@/enums/roleEnum';
import { toThousands } from '/@/utils/fnUtils';
import { CardList, seriesDataT } from './props';
import PieChartDeviceSub from './PieChartDeviceSub.vue';
import PieChartDeviceStatus from './PieChartDeviceStatus.vue';
import { Empty } from 'ant-design-vue';
import StatisticalCard from './StatisticalCard.vue';
import { HomeStatisticsRecordType } from '/@/api/dashboard/model';
import { useRole } from '/@/hooks/business/useRole';
import { unref } from 'vue';
import productPicture from '/@/assets/images/product.png';
import devicePicture from '/@/assets/images/device-count.png';
import alarmPicture from '/@/assets/images/alarm-count.png';
import msgPicture from '/@/assets/images/msg-count.png';
import tenantPicture from '/@/assets/images/zh.png';
import customerPicture from '/@/assets/images/kf.png';
import { useUserStore } from '/@/store/modules/user';
import { PermissionEnum } from '/@/enums/permissionEnum';
interface RecordType {
value: number;
label: string;
}
interface StatisticalItemType {
images: string;
totals: RecordType[];
tooltips: RecordType[];
todayTotals: RecordType[];
withUnit?: boolean;
}
defineProps<{
role: string;
}>();
defineExpose({
isAdmin,
toThousands,
});
defineComponent({
Card,
});
const legendData = ref(['网关设备', '直连设备', '网关子设备']);
const seriesData: Ref<seriesDataT[]> = ref([]);
const seriesStatusData: Ref<seriesDataT[]> = ref([]);
const growCardList = ref<CardList>();
const statisticalPanelList = ref<StatisticalItemType[]>([]);
const devicePieColor = [
{ key: 'directConnection', itemStyle: { color: '#5C7BD9' }, value: '直连设备' },
{ key: 'gateWay', itemStyle: { color: '#91CC75' }, value: '网关设备' },
{ key: 'sensor', itemStyle: { color: '#FAC859' }, value: '网关子设备' },
{ key: 'inActive', itemStyle: { color: '#5C7BD9' }, value: '待激活' },
{ key: 'onLine', itemStyle: { color: '#91CC75 ' }, value: '在线' },
{ key: 'offLine', itemStyle: { color: '#EC4040' }, value: '离线' },
];
const { isSysadmin, isPlatformAdmin } = useRole();
const userStore = useUserStore();
const hasTenantSubAdminPermission = computed(() => {
return userStore.getUserInfo?.level === PermissionEnum.TENANT_SUB_ADMINISTRATOR;
});
const handleTransformStatisticalInfo = (record: HomeStatisticsRecordType) => {
const {
deviceInfo,
productInfo,
alarmInfo,
messageInfo,
customerInfo,
tenantInfo,
alarmNoticeInfo,
} = record;
const productTotal: StatisticalItemType = {
images: productPicture,
totals: [{ label: '产品数', value: productInfo?.sumCount }],
tooltips: [
{ label: '产品数', value: productInfo?.sumCount },
{ label: '今日新增', value: productInfo?.todayAdd },
],
todayTotals: [{ label: '今日新增', value: productInfo?.todayAdd }],
};
const deviceTotal: StatisticalItemType = {
images: devicePicture,
totals: [{ label: '设备数', value: deviceInfo?.sumCount }],
tooltips: [
{ label: '设备数', value: deviceInfo?.sumCount },
{ label: '今日新增', value: deviceInfo?.todayAdd },
],
todayTotals: [{ label: '今日新增', value: deviceInfo?.todayAdd }],
};
const alarmTotal: StatisticalItemType = {
images: alarmPicture,
totals: [{ label: '告警数', value: alarmInfo?.sumCount }],
tooltips: [
{ label: '告警数', value: alarmInfo?.sumCount },
{ label: '今日新增', value: alarmInfo?.todayAdd },
],
todayTotals: [{ label: '今日新增', value: alarmInfo?.todayAdd }],
};
const messageTotal: StatisticalItemType = {
images: msgPicture,
withUnit: true,
totals: [
{ label: '消息数', value: messageInfo?.messageCount },
{ label: '消息点数', value: messageInfo?.dataPointsCount },
],
tooltips: [
{ label: '今日消息数', value: messageInfo?.todayMessageAdd },
{ label: '今日消息点数', value: messageInfo?.todayDataPointsAdd },
],
todayTotals: [
{ label: '今日消息数', value: messageInfo?.todayMessageAdd },
{ label: '今日消息点数', value: messageInfo?.todayDataPointsAdd },
],
};
const tenantTotal: StatisticalItemType = {
images: tenantPicture,
totals: [{ label: '租户总量', value: tenantInfo?.sumCount }],
tooltips: [
{ label: '租户总量', value: tenantInfo?.sumCount },
{ label: '今日新增', value: tenantInfo?.todayAdd },
],
todayTotals: [{ label: '今日新增', value: tenantInfo?.todayAdd }],
};
const customerTotal: StatisticalItemType = {
images: customerPicture,
totals: [{ label: '客户总量', value: customerInfo?.sumCount }],
tooltips: [
{ label: '客户总量', value: customerInfo?.sumCount },
{ label: '今日新增', value: customerInfo?.todayAdd },
],
todayTotals: [{ label: '今日新增', value: customerInfo?.todayAdd }],
};
const alarmNoticeInfoTotal: StatisticalItemType = {
images: msgPicture,
totals: [{ label: '告警通知数', value: alarmNoticeInfo?.sumCount }],
tooltips: [
{ label: '告警通知数', value: alarmNoticeInfo?.sumCount },
{ label: '今日新增', value: alarmNoticeInfo?.todayAdd },
],
todayTotals: [{ label: '今日新增', value: alarmNoticeInfo?.todayAdd }],
};
if (unref(isSysadmin) || unref(isPlatformAdmin)) {
statisticalPanelList.value = [deviceTotal, tenantTotal, customerTotal];
} else {
statisticalPanelList.value = [
productTotal,
deviceTotal,
alarmTotal,
hasTenantSubAdminPermission.value ? alarmNoticeInfoTotal : messageTotal,
];
}
};
onMounted(async () => {
const res = await getHomeData();
growCardList.value = res;
handleTransformStatisticalInfo(res);
const { deviceInfo } = growCardList.value!;
let data = Object.entries(deviceInfo).map(([key, value]) => {
const name = devicePieColor?.find((f) => f.key === key)?.value;
const itemStyle = devicePieColor?.find((f) => f.key === key)?.itemStyle;
return { key, value, itemStyle, name };
});
seriesData.value = data.filter(
(f) => f.key === 'directConnection' || f.key === 'gateWay' || f.key === 'sensor'
);
seriesStatusData.value = data.filter(
(f) => f.key === 'inActive' || f.key === 'onLine' || f.key === 'offLine'
);
});
</script>
<style lang="less">
.text {
color: #333;
display: flex;
flex-wrap: nowrap;
}
.bold-text {
font-weight: bold;
}
.base-left-icon-color {
border-radius: 50%;
width: 0.75rem;
height: 0.75rem;
display: block;
position: relative;
right: 0.5rem;
}
.left-icon-d-color :extend(.base-left-icon-color) {
background-color: #5c7bd9 !important;
}
.left-icon-g-color :extend(.base-left-icon-color) {
background-color: #91cc75 !important;
}
.left-icon-s-color :extend(.base-left-icon-color) {
background-color: #fac859 !important;
}
.right-icon-d-color :extend(.base-left-icon-color) {
background-color: #5c7bd9;
}
.right-icon-g-color :extend(.base-left-icon-color) {
background-color: #91cc75;
}
.right-icon-s-color :extend(.base-left-icon-color) {
background-color: #ec4040;
}
</style>