| 1 | <template> |
| 2 | <div class="@container"> |
| 3 | <CardEntity :embedded hoverable size="small"> |
| 4 | <div class="grid-auto-fit-200 flex flex-col gap-2 @lg:grid"> |
| 5 | <CardKV v-for="prop of displayData" :key="prop.key" :class="{ 'hidden @lg:flex': prop.hideMobile }"> |
| 6 | <template #key> |
| 7 | {{ prop.key }} |
| 8 | </template> |
| 9 | <template #value> |
| 10 | {{ prop.value }} |
| 11 | </template> |
| 12 | </CardKV> |
| 13 | <CardKV class="hover:border-primary! cursor-pointer" @click="showDetails = true"> |
| 14 | <template #value> |
| 15 | <div class="flex h-full w-full items-center justify-center text-center">view more...</div> |
| 16 | </template> |
| 17 | </CardKV> |
| 18 | </div> |
| 19 | </CardEntity> |
| 20 | |
| 21 | <n-modal |
| 22 | v-model:show="showDetails" |
| 23 | preset="card" |
| 24 | :style="{ maxWidth: 'min(800px, 90vw)', overflow: 'hidden' }" |
| 25 | :bordered="false" |
| 26 | title="Collected Item" |
| 27 | > |
| 28 | <SimpleJsonViewer class="vuesjv-override" :model-value="jsonData" :initial-expanded-depth="2" /> |
| 29 | </n-modal> |
| 30 | </div> |
| 31 | </template> |
| 32 | |
| 33 | <script setup lang="ts"> |
| 34 | import type { CollectResult } from "@/types/artifacts.d" |
| 35 | import _isNumber from "lodash/isNumber" |
| 36 | import _isString from "lodash/isString" |
| 37 | import { NModal } from "naive-ui" |
| 38 | import { onBeforeMount, ref } from "vue" |
| 39 | import { SimpleJsonViewer } from "vue-sjv" |
| 40 | import CardEntity from "@/components/common/cards/CardEntity.vue" |
| 41 | import CardKV from "@/components/common/cards/CardKV.vue" |
| 42 | import { useSettingsStore } from "@/stores/settings" |
| 43 | import dayjs from "@/utils/dayjs" |
| 44 | import { formatDate } from "@/utils/format" |
| 45 | import "@/assets/scss/overrides/vuesjv-override.scss" |
| 46 | |
| 47 | interface Prop { |
| 48 | key: string |
| 49 | value: string | number |
| 50 | hideMobile: boolean |
| 51 | } |
| 52 | |
| 53 | const { collect, embedded } = defineProps<{ collect: CollectResult; embedded?: boolean }>() |
| 54 | |
| 55 | const jsonData = ref<CollectResult>({}) |
| 56 | const displayData = ref<Prop[]>([]) |
| 57 | |
| 58 | const showDetails = ref(false) |
| 59 | const dFormats = useSettingsStore().dateFormat |
| 60 | |
| 61 | onBeforeMount(() => { |
| 62 | for (const key in collect) { |
| 63 | const value = collect[key] |
| 64 | |
| 65 | const prop: Prop = { |
| 66 | key: "", |
| 67 | value: "", |
| 68 | hideMobile: false |
| 69 | } |
| 70 | |
| 71 | if ((_isString(value) || _isNumber(value)) && value !== "" && key !== "___id") { |
| 72 | prop.key = key |
| 73 | prop.value = value |
| 74 | } |
| 75 | |
| 76 | if (prop.value && typeof prop.value === "string") { |
| 77 | prop.value = dayjs(prop.value).isValid() |
| 78 | ? formatDate(prop.value, dFormats.datetimesec).toString() |
| 79 | : prop.value |
| 80 | } |
| 81 | |
| 82 | if (prop.value && typeof prop.value === "number") { |
| 83 | const numText = prop.value.toString() |
| 84 | |
| 85 | if (numText.length === 10 || numText.length === 13) { |
| 86 | if (dayjs(prop.value).isValid()) { |
| 87 | prop.value = formatDate(prop.value, dFormats.datetimesec).toString() |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (prop.key && displayData.value.length < 5) { |
| 93 | if (displayData.value.length > 2) { |
| 94 | prop.hideMobile = true |
| 95 | } |
| 96 | displayData.value.push(prop) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | jsonData.value = collect |
| 101 | |
| 102 | delete jsonData.value.___id |
| 103 | }) |
| 104 | </script> |