fix(frontend): 修正用户端日卡额度提示
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
0b40470597
commit
a66f771cb1
@ -127,11 +127,7 @@
|
|||||||
v-if="subscription.daily_window_start"
|
v-if="subscription.daily_window_start"
|
||||||
class="text-xs text-gray-500 dark:text-dark-400"
|
class="text-xs text-gray-500 dark:text-dark-400"
|
||||||
>
|
>
|
||||||
{{
|
{{ formatDailyUsageWindow(subscription) }}
|
||||||
t('userSubscriptions.resetIn', {
|
|
||||||
time: formatResetTime(subscription.daily_window_start, 24)
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -256,6 +252,7 @@ import AppLayout from '@/components/layout/AppLayout.vue'
|
|||||||
import Icon from '@/components/icons/Icon.vue'
|
import Icon from '@/components/icons/Icon.vue'
|
||||||
import { formatDateOnly } from '@/utils/format'
|
import { formatDateOnly } from '@/utils/format'
|
||||||
import { platformBorderClass, platformBadgeClass, platformButtonClass, platformLabel } from '@/utils/platformColors'
|
import { platformBorderClass, platformBadgeClass, platformButtonClass, platformLabel } from '@/utils/platformColors'
|
||||||
|
import { getRemainingDurationParts, isOneTimeDailyQuota, type RemainingDurationParts } from '@/utils/subscriptionQuota'
|
||||||
|
|
||||||
function platformAccentDotClass(p: string): string {
|
function platformAccentDotClass(p: string): string {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
@ -334,30 +331,38 @@ function getExpirationClass(expiresAt: string): string {
|
|||||||
return 'text-gray-700 dark:text-gray-300'
|
return 'text-gray-700 dark:text-gray-300'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDurationParts(parts: RemainingDurationParts): string {
|
||||||
|
if (parts.days > 0) {
|
||||||
|
return `${parts.days}d ${parts.hours}h`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts.hours > 0) {
|
||||||
|
return `${parts.hours}h ${parts.minutes}m`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${parts.minutes}m`
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDailyUsageWindow(subscription: UserSubscription): string {
|
||||||
|
if (isOneTimeDailyQuota(subscription) && subscription.expires_at) {
|
||||||
|
const parts = getRemainingDurationParts(subscription.expires_at)
|
||||||
|
if (!parts) return t('userSubscriptions.windowNotActive')
|
||||||
|
return t('userSubscriptions.quotaEndsIn', { time: formatDurationParts(parts) })
|
||||||
|
}
|
||||||
|
|
||||||
|
return t('userSubscriptions.resetIn', {
|
||||||
|
time: formatResetTime(subscription.daily_window_start, 24)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function formatResetTime(windowStart: string | null, windowHours: number): string {
|
function formatResetTime(windowStart: string | null, windowHours: number): string {
|
||||||
if (!windowStart) return t('userSubscriptions.windowNotActive')
|
if (!windowStart) return t('userSubscriptions.windowNotActive')
|
||||||
|
|
||||||
const start = new Date(windowStart)
|
const start = new Date(windowStart)
|
||||||
const end = new Date(start.getTime() + windowHours * 60 * 60 * 1000)
|
const end = new Date(start.getTime() + windowHours * 60 * 60 * 1000)
|
||||||
const now = new Date()
|
const parts = getRemainingDurationParts(end)
|
||||||
const diff = end.getTime() - now.getTime()
|
|
||||||
|
|
||||||
if (diff <= 0) return t('userSubscriptions.windowNotActive')
|
return parts ? formatDurationParts(parts) : t('userSubscriptions.windowNotActive')
|
||||||
|
|
||||||
const hours = Math.floor(diff / (1000 * 60 * 60))
|
|
||||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
|
|
||||||
|
|
||||||
if (hours > 24) {
|
|
||||||
const days = Math.floor(hours / 24)
|
|
||||||
const remainingHours = hours % 24
|
|
||||||
return `${days}d ${remainingHours}h`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hours > 0) {
|
|
||||||
return `${hours}h ${minutes}m`
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${minutes}m`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user