fix: 修复订阅窗口过期后进度条显示不正确的问题

问题:滑动窗口过期后(如昨天用满额度),前端仍显示历史数据(红色进度条100%、"即将重置")

解决:
- 后端返回数据前检查窗口是否过期,过期则清零展示数据
- 前端处理 window_start 为 null 的情况,显示"窗口未激活"
- 不影响实际的窗口激活逻辑,窗口仍从当天零点开始
This commit is contained in:
shaw
2025-12-23 10:38:15 +08:00
parent eb55947ec4
commit 5bbfbcdae9
5 changed files with 56 additions and 7 deletions

View File

@@ -592,6 +592,8 @@ const getProgressClass = (used: number, limit: number | null): string => {
// Format reset time based on window start and period type
const formatResetTime = (windowStart: string, period: 'daily' | 'weekly' | 'monthly'): string => {
if (!windowStart) return t('admin.subscriptions.windowNotActive')
const start = new Date(windowStart)
const now = new Date()
@@ -610,7 +612,7 @@ const formatResetTime = (windowStart: string, period: 'daily' | 'weekly' | 'mont
}
const diffMs = resetTime.getTime() - now.getTime()
if (diffMs <= 0) return t('admin.subscriptions.resetNow')
if (diffMs <= 0) return t('admin.subscriptions.windowNotActive')
const diffSeconds = Math.floor(diffMs / 1000)
const days = Math.floor(diffSeconds / 86400)

View File

@@ -229,14 +229,14 @@ function getExpirationClass(expiresAt: string): string {
}
function formatResetTime(windowStart: string | null, windowHours: number): string {
if (!windowStart) return '--';
if (!windowStart) return t('userSubscriptions.windowNotActive');
const start = new Date(windowStart);
const end = new Date(start.getTime() + windowHours * 60 * 60 * 1000);
const now = new Date();
const diff = end.getTime() - now.getTime();
if (diff <= 0) return 'Now';
if (diff <= 0) return t('userSubscriptions.windowNotActive');
const hours = Math.floor(diff / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));