imp: show duration text

This commit is contained in:
liangping 2023-06-13 15:41:34 +08:00
parent 436a5cc3a1
commit ff621bd67c

View File

@ -12,6 +12,19 @@ function calculateValue(value: any) {
if (Array.isArray(value)) {
return (value[0] && value[0].amount) || '-';
}
if(String(value).search(/^\d+s$/g) > -1) {
const duration = Number(value.replace(/s/, ''))
if(duration > 24*60*60) {
return `${duration / ( 24 * 60 * 60)} days`
}
if(duration > 60*60) {
return `${duration / (60 * 60)} hours`
}
if(duration > 60) {
return `${duration / 60} mins`
}
return duration
}
const newValue = Number(value);
if (`${newValue}` === 'NaN' || typeof value === 'boolean') {
return value;
@ -22,6 +35,11 @@ function calculateValue(value: any) {
}
return newValue;
}
function formatTitle(v: string) {
if(!v) return ""
return v.replace(/_/g, " ")
}
</script>
<template>
<div
@ -37,7 +55,7 @@ function calculateValue(value: any) {
:key="index"
class="rounded-sm bg-active px-4 py-2"
>
<div class="text-xs mb-2 text-secondary">{{ item?.subtitle }}</div>
<div class="text-xs mb-2 text-secondary capitalize">{{ formatTitle(item?.subtitle) }}</div>
<div class="text-base text-main">{{ calculateValue(item?.value) }}</div>
</div>
</div>