2 Commits

Author SHA1 Message Date
erio
a7089936a4 fix: 修复页面加载时闪现「入口未开放」的问题
allEntriesClosed 判断需要等 userLoaded 和 channelsLoaded 都完成,
避免 channelsLoaded 先完成但 config 还未加载时误判为入口关闭。
2026-03-15 12:03:27 +08:00
erio
6bca9853b3 style: fix prettier formatting in user route 2026-03-15 03:14:47 +08:00
2 changed files with 10 additions and 10 deletions

View File

@@ -8,7 +8,6 @@ import { resolveLocale } from '@/lib/locale';
import { getSystemConfig } from '@/lib/system-config'; import { getSystemConfig } from '@/lib/system-config';
import { resolveEnabledPaymentTypes } from '@/lib/payment/resolve-enabled-types'; import { resolveEnabledPaymentTypes } from '@/lib/payment/resolve-enabled-types';
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
const locale = resolveLocale(request.nextUrl.searchParams.get('lang')); const locale = resolveLocale(request.nextUrl.searchParams.get('lang'));
const userId = Number(request.nextUrl.searchParams.get('user_id')); const userId = Number(request.nextUrl.searchParams.get('user_id'));
@@ -54,10 +53,7 @@ export async function GET(request: NextRequest) {
return { enabledTypes, methodLimits, balanceDisabled: balanceDisabledVal === 'true' }; return { enabledTypes, methodLimits, balanceDisabled: balanceDisabledVal === 'true' };
}); });
const [user, { enabledTypes, methodLimits, balanceDisabled }] = await Promise.all([ const [user, { enabledTypes, methodLimits, balanceDisabled }] = await Promise.all([getUser(userId), configPromise]);
getUser(userId),
configPromise,
]);
// 收集 sublabel 覆盖 // 收集 sublabel 覆盖
const sublabelOverrides: Record<string, string> = {}; const sublabelOverrides: Record<string, string> = {};

View File

@@ -82,6 +82,7 @@ function PayContent() {
const [showTopUpForm, setShowTopUpForm] = useState(false); const [showTopUpForm, setShowTopUpForm] = useState(false);
const [selectedPlan, setSelectedPlan] = useState<PlanInfo | null>(null); const [selectedPlan, setSelectedPlan] = useState<PlanInfo | null>(null);
const [channelsLoaded, setChannelsLoaded] = useState(false); const [channelsLoaded, setChannelsLoaded] = useState(false);
const [userLoaded, setUserLoaded] = useState(false);
const [config, setConfig] = useState<AppConfig>({ const [config, setConfig] = useState<AppConfig>({
enabledPaymentTypes: [], enabledPaymentTypes: [],
@@ -217,7 +218,10 @@ function PayContent() {
} }
} }
} }
} catch {} } catch {
} finally {
setUserLoaded(true);
}
}, [token, locale]); }, [token, locale]);
// 加载渠道和订阅套餐 // 加载渠道和订阅套餐
@@ -487,8 +491,8 @@ function PayContent() {
// ── 渲染 ── // ── 渲染 ──
// R7: 检查是否所有入口都关闭(无可用充值方式 且 无订阅套餐) // R7: 检查是否所有入口都关闭(无可用充值方式 且 无订阅套餐)
const allEntriesClosed = channelsLoaded && !canTopUp && !hasPlans; const allEntriesClosed = channelsLoaded && userLoaded && !canTopUp && !hasPlans;
const showMainTabs = channelsLoaded && !allEntriesClosed && (hasChannels || hasPlans); const showMainTabs = channelsLoaded && userLoaded && !allEntriesClosed && (hasChannels || hasPlans);
const pageTitle = showMainTabs const pageTitle = showMainTabs
? pickLocaleText(locale, '选择适合你的 充值/订阅服务', 'Choose Your Recharge / Subscription') ? pickLocaleText(locale, '选择适合你的 充值/订阅服务', 'Choose Your Recharge / Subscription')
: pickLocaleText(locale, 'Sub2API 余额充值', 'Sub2API Balance Recharge'); : pickLocaleText(locale, 'Sub2API 余额充值', 'Sub2API Balance Recharge');
@@ -613,7 +617,7 @@ function PayContent() {
)} )}
{/* 加载中 */} {/* 加载中 */}
{!channelsLoaded && config.enabledPaymentTypes.length === 0 && ( {(!channelsLoaded || !userLoaded) && !allEntriesClosed && (
<div className="flex items-center justify-center py-12"> <div className="flex items-center justify-center py-12">
<div className="h-6 w-6 animate-spin rounded-full border-2 border-blue-500 border-t-transparent" /> <div className="h-6 w-6 animate-spin rounded-full border-2 border-blue-500 border-t-transparent" />
<span className={['ml-3 text-sm', isDark ? 'text-slate-400' : 'text-gray-500'].join(' ')}> <span className={['ml-3 text-sm', isDark ? 'text-slate-400' : 'text-gray-500'].join(' ')}>
@@ -887,7 +891,7 @@ function PayContent() {
)} )}
{/* ── 无渠道配置传统充值UI ── */} {/* ── 无渠道配置传统充值UI ── */}
{channelsLoaded && !showMainTabs && canTopUp && !selectedPlan && ( {channelsLoaded && userLoaded && !showMainTabs && canTopUp && !selectedPlan && (
<> <>
{isMobile ? ( {isMobile ? (
activeMobileTab === 'pay' ? ( activeMobileTab === 'pay' ? (