main
vue 79 lines 2.12 KB
Raw
1 <template>
2 <n-spin :show="loading">
3 <CardStatsBars
4 title="Cases"
5 hovered
6 class="h-full cursor-pointer"
7 :values
8 @click="routeIncidentManagementCases().navigate()"
9 >
10 <template #icon>
11 <CardStatsIcon :icon-name="CasesIcon" 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 CasesIcon = "carbon:ibm-secure-infrastructure-on-vpc-for-regulated-industries"
27 const { routeIncidentManagementCases } = useNavigation()
28 const message = useMessage()
29 const loading = ref(false)
30
31 const total = ref(0)
32 const openedCount = ref(0)
33 const inProgressCount = ref(0)
34 const closedCount = ref(0)
35
36 const values = computed<ItemProps[]>(() => [
37 { value: total.value, label: "Total", isTotal: true },
38 { value: openedCount.value, label: "Open", status: "error" },
39 { value: inProgressCount.value, label: "In Progress", status: "warning" },
40 { value: closedCount.value, label: "Closed", status: "success" }
41 ])
42
43 function getData() {
44 loading.value = true
45
46 Api.incidentManagement.cases
47 .getCasesList(undefined, { page: 1, pageSize: 1 })
48 .then(res => {
49 if (res.data.success) {
50 total.value = res.data.total || 0
51 openedCount.value = res.data.open || 0
52 inProgressCount.value = res.data.in_progress || 0
53 closedCount.value = res.data.closed || 0
54 } else {
55 message.warning(res.data?.message || "An error occurred. Please try again later.")
56 }
57 })
58 .catch(err => {
59 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
60 })
61 .finally(() => {
62 loading.value = false
63 })
64 }
65
66 onBeforeMount(() => {
67 getData()
68 })
69 </script>
70
71 <style lang="scss" scoped>
72 .n-spin-container {
73 :deep() {
74 .n-spin-content {
75 height: 100%;
76 }
77 }
78 }
79 </style>