main
vue 81 lines 2.1 KB
Raw
1 <template>
2 <n-spin :show="loading">
3 <CardStatsBars
4 title="Alerts"
5 hovered
6 class="h-full cursor-pointer"
7 :values
8 @click="routeIncidentManagementAlerts().navigate()"
9 >
10 <template #icon>
11 <CardStatsIcon :icon-name="AlertsIcon" boxed :box-size="30"></CardStatsIcon>
12 </template>
13 </CardStatsBars>
14 </n-spin>
15 </template>
16
17 <script setup lang="ts">
18 import type { ItemProps } from "@/components/common/cards/CardStatsBars.vue"
19 import { NSpin, useMessage } from "naive-ui"
20 import { computed, onBeforeMount, ref } from "vue"
21 import Api from "@/api"
22 import CardStatsBars from "@/components/common/cards/CardStatsBars.vue"
23 import CardStatsIcon from "@/components/common/cards/CardStatsIcon.vue"
24 import { useNavigation } from "@/composables/useNavigation"
25
26 const AlertsIcon = "carbon:warning-hex"
27 const { routeIncidentManagementAlerts } = useNavigation()
28 const message = useMessage()
29 const loading = ref(false)
30 const total = ref(0)
31 const openedCount = ref(0)
32 const inProgressCount = ref(0)
33 const closedCount = ref(0)
34 const values = computed<ItemProps[]>(() => [
35 { value: total.value, label: "Total", isTotal: true },
36 { value: openedCount.value, label: "Open", status: "error" },
37 { value: inProgressCount.value, label: "In Progress", status: "warning" },
38 { value: closedCount.value, label: "Closed", status: "success" }
39 ])
40
41 function getData() {
42 loading.value = true
43
44 Api.incidentManagement.alerts
45 .getAlertsList({
46 page: 0,
47 pageSize: 0
48 })
49 .then(res => {
50 if (res.data.success) {
51 total.value = res.data.total || 0
52 closedCount.value = res.data.closed || 0
53 inProgressCount.value = res.data.in_progress || 0
54 openedCount.value = res.data.open || 0
55 } else {
56 message.warning(res.data?.message || "An error occurred. Please try again later.")
57 }
58 loading.value = false
59 })
60 .catch(err => {
61 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
62 })
63 .finally(() => {
64 loading.value = false
65 })
66 }
67
68 onBeforeMount(() => {
69 getData()
70 })
71 </script>
72
73 <style lang="scss" scoped>
74 .n-spin-container {
75 :deep() {
76 .n-spin-content {
77 height: 100%;
78 }
79 }
80 }
81 </style>