From 68de33165edbbf3d7acca1a5ad8b842e6afa3810 Mon Sep 17 00:00:00 2001 From: Roe-xin Date: Tue, 3 Mar 2026 18:03:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E7=94=A8=E6=88=B7=E4=BB=8D=E5=BC=B9=E5=87=BA?= =?UTF-8?q?=E9=82=80=E8=AF=B7=E7=A0=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/userService.ts | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/services/userService.ts b/src/services/userService.ts index 9bd8167..30c3bf4 100644 --- a/src/services/userService.ts +++ b/src/services/userService.ts @@ -335,28 +335,38 @@ export async function onTokenReceived(token: string): Promise { console.log('[UserService] 检查用户类型,isPluginTrial:', userInfo.isPluginTrial); console.log('[UserService] extensionContext 是否存在:', !!extensionContext); - if (userInfo.isPluginTrial === true) { - // 插件试用用户:标记需要显示欢迎弹窗 - const hasWelcomed = extensionContext?.globalState.get('pluginTrialWelcomed'); - console.log('[UserService] 是否已显示过欢迎弹窗:', hasWelcomed); + if (userInfo.isPluginTrial === true && userInfo.pluginTrialExpiresAt !== null && userInfo.pluginTrialExpiresAt !== undefined) { + // 检查是否过期 + const now = Date.now(); + const isExpired = now >= userInfo.pluginTrialExpiresAt; + console.log('[UserService] 试用到期时间:', new Date(userInfo.pluginTrialExpiresAt).toLocaleString()); + console.log('[UserService] 当前时间:', new Date(now).toLocaleString()); + console.log('[UserService] 是否过期:', isExpired); - if (!hasWelcomed && extensionContext) { - // 设置标记,让聊天面板显示欢迎弹窗 - await extensionContext.globalState.update('showWelcomeModal', true); - await extensionContext.globalState.update('pluginTrialWelcomed', true); - console.log('[UserService] ✅ 已设置欢迎弹窗标记 showWelcomeModal=true'); - - // 验证标记是否设置成功 - const checkMark = extensionContext.globalState.get('showWelcomeModal'); - console.log('[UserService] 验证标记:', checkMark); - } else if (!extensionContext) { - console.error('[UserService] ❌ extensionContext 为 null,无法设置标记'); + if (isExpired) { + // 已过期:显示邀请码弹窗 + console.log('[UserService] 试用已过期,将显示邀请码弹窗'); } else { - console.log('[UserService] 已经显示过欢迎弹窗,跳过'); + // 未过期:显示欢迎弹窗 + const hasWelcomed = extensionContext?.globalState.get('pluginTrialWelcomed'); + console.log('[UserService] 是否已显示过欢迎弹窗:', hasWelcomed); + + if (!hasWelcomed && extensionContext) { + await extensionContext.globalState.update('showWelcomeModal', true); + await extensionContext.globalState.update('pluginTrialWelcomed', true); + console.log('[UserService] ✅ 已设置欢迎弹窗标记 showWelcomeModal=true'); + + const checkMark = extensionContext.globalState.get('showWelcomeModal'); + console.log('[UserService] 验证标记:', checkMark); + } else if (!extensionContext) { + console.error('[UserService] ❌ extensionContext 为 null,无法设置标记'); + } else { + console.log('[UserService] 已经显示过欢迎弹窗,跳过'); + } } } else { - // 正式用户:显示邀请码弹窗(现有逻辑) - console.log('[UserService] 正式用户登录,将在面板中检查邀请码'); + // isPluginTrial=false 或 enterpriseTrialExpires 为 null:显示邀请码弹窗 + console.log('[UserService] 非试用用户或无过期时间,将显示邀请码弹窗'); } return userInfo;