main
vue 42 lines 1.15 KB
Raw
1 <template>
2 <div class="flex flex-col gap-3">
3 <div v-for="item of itemsPaginated" :key="item.id">
4 <SoftwareCard :id="item.id" :entity="item.entity" @loaded="item.entity = $event" />
5 </div>
6 <div v-if="list.length" class="flex justify-end">
7 <n-pagination
8 v-model:page="currentPage"
9 v-model:page-size="pageSize"
10 :item-count="list.length"
11 :page-slot="6"
12 />
13 </div>
14 <n-empty v-else description="No items found" class="h-48 justify-center" />
15 </div>
16 </template>
17
18 <script setup lang="ts">
19 import type { MitreSoftwareDetails } from "@/types/mitre.d"
20 import { NEmpty, NPagination } from "naive-ui"
21 import { computed, onMounted, ref } from "vue"
22 import SoftwareCard from "./SoftwareCard.vue"
23
24 const { list } = defineProps<{
25 list: string[]
26 }>()
27
28 const pageSize = ref(5)
29 const currentPage = ref(1)
30 const software = ref<{ id: string; entity?: MitreSoftwareDetails }[]>([])
31
32 const itemsPaginated = computed(() => {
33 const from = (currentPage.value - 1) * pageSize.value
34 const to = currentPage.value * pageSize.value
35
36 return software.value.slice(from, to)
37 })
38
39 onMounted(() => {
40 software.value = list.map(o => ({ id: o, entity: undefined }))
41 })
42 </script>