main
vue 51 lines 1.35 KB
Raw
1 <template>
2 <div class="soc-assets-list">
3 <n-spin :show="loadingAssets" class="min-h-14">
4 <div v-if="assetsList?.length" class="flex flex-col gap-2 p-7">
5 <SocAlertAssetsItem v-for="asset of assetsList" :key="asset.asset_id" :asset />
6 </div>
7 <template v-else>
8 <n-empty v-if="!loadingAssets" description="No items found" class="h-48 justify-center" />
9 </template>
10 </n-spin>
11 </div>
12 </template>
13
14 <script setup lang="ts">
15 import type { SocAlertAsset } from "@/types/soc/asset.d"
16 import { NEmpty, NSpin, useMessage } from "naive-ui"
17 import { onBeforeMount, ref } from "vue"
18 import Api from "@/api"
19 import SocAlertAssetsItem from "./SocAlertAssetsItem.vue"
20
21 const { alertId } = defineProps<{ alertId: string | number }>()
22
23 const loadingAssets = ref(false)
24 const message = useMessage()
25
26 const assetsList = ref<SocAlertAsset[] | null>(null)
27
28 function getAssets() {
29 loadingAssets.value = true
30
31 Api.soc
32 .getAssetsByAlert(alertId.toString())
33 .then(res => {
34 if (res.data.success) {
35 assetsList.value = res.data?.assets || null
36 } else {
37 message.warning(res.data?.message || "An error occurred. Please try again later.")
38 }
39 })
40 .catch(err => {
41 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
42 })
43 .finally(() => {
44 loadingAssets.value = false
45 })
46 }
47
48 onBeforeMount(() => {
49 getAssets()
50 })
51 </script>