cosmos-explorer/src/components/CardParameter.vue

46 lines
1.3 KiB
Vue
Raw Normal View History

2023-04-26 16:18:13 +00:00
<script lang="ts" setup>
import type { PropType } from 'vue';
2023-05-06 14:56:04 +00:00
import { useFormatter } from '@/stores';
2023-04-26 16:18:13 +00:00
const props = defineProps({
2023-04-27 11:00:44 +00:00
cardItem: {
type: Object as PropType<{ title: string; items: Array<any> }>,
},
});
2023-04-28 14:00:15 +00:00
2023-05-06 14:56:04 +00:00
const formatter = useFormatter();
function calculateValue(value: any) {
if (Array.isArray(value)) {
return (value[0] && value[0].amount) || '-';
2023-04-28 14:00:15 +00:00
}
2023-05-06 14:56:04 +00:00
const newValue = Number(value);
if (`${newValue}` === 'NaN' || typeof value === 'boolean') {
return value;
2023-04-28 14:00:15 +00:00
}
2023-05-06 14:56:04 +00:00
2023-04-28 14:00:15 +00:00
if (newValue < 1 && newValue > 0) {
2023-05-06 14:56:04 +00:00
return formatter.formatDecimalToPercent(value);
2023-04-28 14:00:15 +00:00
}
2023-05-06 14:56:04 +00:00
return newValue;
2023-04-28 14:00:15 +00:00
}
2023-04-26 16:18:13 +00:00
</script>
<template>
2023-04-27 11:00:44 +00:00
<div
2023-05-05 00:37:12 +00:00
class="bg-base-100 px-4 pt-3 pb-4 rounded mt-5"
2023-04-27 11:00:44 +00:00
v-if="props.cardItem?.items && props.cardItem?.items?.length > 0"
>
<div class="text-base mb-3 text-main">{{ props.cardItem?.title }}</div>
<div
2023-05-20 05:36:05 +00:00
class="grid grid-cols-2 md:!grid-cols-4 lg:!grid-cols-5 2xl:!grid-cols-6 gap-4"
2023-04-27 11:00:44 +00:00
>
<div
v-for="(item, index) of props.cardItem?.items"
:key="index"
class="rounded-sm bg-active px-4 py-2"
>
<div class="text-xs mb-2 text-secondary">{{ item?.subtitle }}</div>
2023-04-28 14:00:15 +00:00
<div class="text-base text-main">{{ calculateValue(item?.value) }}</div>
2023-04-27 11:00:44 +00:00
</div>
</div>
2023-04-27 11:00:44 +00:00
</div>
</template>