2023-09-01 12:40:34 +08:00
|
|
|
import byteSize from 'byte-size'
|
|
|
|
import dayjs from 'dayjs'
|
2023-09-03 03:26:29 +08:00
|
|
|
import type { SubscriptionInfo as ISubscriptionInfo } from '~/types'
|
2023-09-01 12:40:34 +08:00
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => {
|
2023-09-02 10:44:13 +08:00
|
|
|
const total = byteSize(subscriptionInfo.Total, { units: 'iec' })
|
|
|
|
const used = byteSize(subscriptionInfo.Download + subscriptionInfo.Upload, {
|
|
|
|
units: 'iec',
|
|
|
|
})
|
2023-09-01 12:40:34 +08:00
|
|
|
const percentage = (
|
|
|
|
((subscriptionInfo.Download + subscriptionInfo.Upload) /
|
|
|
|
subscriptionInfo.Total) *
|
|
|
|
100
|
|
|
|
).toFixed(2)
|
|
|
|
const expireStr = () => {
|
|
|
|
if (subscriptionInfo.Expire === 0) {
|
|
|
|
return 'Null'
|
|
|
|
}
|
|
|
|
|
|
|
|
return dayjs(subscriptionInfo.Expire * 1000).format('YYYY-MM-DD')
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
total,
|
|
|
|
used,
|
|
|
|
percentage,
|
|
|
|
expireStr,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const SubscriptionInfo = (props: {
|
|
|
|
subscriptionInfo: ISubscriptionInfo
|
|
|
|
}) => {
|
2023-09-01 12:40:34 +08:00
|
|
|
if (!props.subscriptionInfo) {
|
|
|
|
return
|
|
|
|
}
|
2023-09-03 15:30:56 +08:00
|
|
|
|
2023-09-01 12:40:34 +08:00
|
|
|
const info = getSubscriptionsInfo(props.subscriptionInfo)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-09-01 13:45:30 +08:00
|
|
|
<progress class="progress" value={info.percentage} max="100" />
|
|
|
|
|
2023-09-01 12:40:34 +08:00
|
|
|
<div class="text-sm text-slate-500">
|
|
|
|
{`${info.used}`} / {`${info.total}`} ( {info.percentage}% )
|
|
|
|
</div>
|
2023-09-01 13:45:30 +08:00
|
|
|
|
2023-09-01 12:40:34 +08:00
|
|
|
<div class="text-sm text-slate-500">Expire: {info.expireStr()} </div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|