feat:企业用户弹窗逻辑
- 通过getuserinfo获取企业参数判断是否是企业用户
This commit is contained in:
@ -9,8 +9,6 @@ import * as vscode from 'vscode';
|
||||
import { getStrangeLoopApiUrl, getConfig } from '../config/settings';
|
||||
import type { UserInfoResponse, MembershipResponse, MultiMembershipVO, MembershipItemVO } from '../types/api';
|
||||
import { fetchBalanceWithToken, getCachedBalance } from './creditsService';
|
||||
import { getIsPluginTrialFromToken } from '../utils/jwtUtils';
|
||||
// 移除 WelcomePanel 导入,改用消息通知方式
|
||||
|
||||
/**
|
||||
* HTTP 请求选项
|
||||
@ -145,7 +143,7 @@ export async function getUserInfo(token: string): Promise<UserInfo | null> {
|
||||
// 处理响应数据 - 检查 code 是否为 200
|
||||
if (response.code === 200 && response.user) {
|
||||
const user = response.user;
|
||||
return {
|
||||
const userInfo: UserInfo = {
|
||||
userId: String(user.userId),
|
||||
username: user.userName,
|
||||
nickname: user.nickName,
|
||||
@ -157,6 +155,20 @@ export async function getUserInfo(token: string): Promise<UserInfo | null> {
|
||||
createTime: user.createTime,
|
||||
loginDate: user.loginDate
|
||||
};
|
||||
|
||||
// 从接口响应中获取企业试用标识
|
||||
if (response.isPluginTrial === true) {
|
||||
userInfo.isPluginTrial = true;
|
||||
console.log('[UserService] 从 getInfo 接口获取到 isPluginTrial: true');
|
||||
}
|
||||
|
||||
// 获取试用到期时间
|
||||
if (response.enterpriseTrialExpires) {
|
||||
userInfo.pluginTrialExpiresAt = response.enterpriseTrialExpires;
|
||||
console.log('[UserService] 试用到期时间:', new Date(response.enterpriseTrialExpires).toLocaleString());
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
console.error('[UserService] 获取用户信息失败:', response);
|
||||
@ -232,10 +244,6 @@ export async function onTokenReceived(token: string): Promise<UserInfo | null> {
|
||||
try {
|
||||
console.log('[UserService] Token 已获取,正在获取用户信息、会员信息和余额...');
|
||||
|
||||
// 从 token 中提取 ispluginTrial 标识
|
||||
const isPluginTrial = getIsPluginTrialFromToken(token);
|
||||
console.log('[UserService] 从 token 中提取 ispluginTrial:', isPluginTrial);
|
||||
|
||||
// 并行获取用户信息、会员信息和余额
|
||||
const [userInfo, membershipInfo, credits] = await Promise.all([
|
||||
getUserInfo(token),
|
||||
@ -248,12 +256,6 @@ export async function onTokenReceived(token: string): Promise<UserInfo | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 将 token 中的 ispluginTrial 标识添加到用户信息
|
||||
if (isPluginTrial !== null) {
|
||||
userInfo.isPluginTrial = isPluginTrial;
|
||||
console.log('[UserService] 已将 ispluginTrial 添加到用户信息:', isPluginTrial);
|
||||
}
|
||||
|
||||
// 添加 Credits 余额到用户信息
|
||||
console.log('[UserService] 获取到的 Credits 余额:', credits);
|
||||
if (credits !== null) {
|
||||
|
||||
@ -407,6 +407,10 @@ export interface UserInfoResponse {
|
||||
isDefaultModifyPwd: boolean;
|
||||
/** 密码是否过期 */
|
||||
isPasswordExpired: boolean;
|
||||
/** 是否为插件试用用户 */
|
||||
isPluginTrial?: boolean;
|
||||
/** 企业试用到期时间(毫秒时间戳) */
|
||||
enterpriseTrialExpires?: number;
|
||||
/** 用户信息 */
|
||||
user: {
|
||||
userId: number;
|
||||
@ -419,6 +423,7 @@ export interface UserInfoResponse {
|
||||
status?: string;
|
||||
createTime?: string;
|
||||
loginDate?: string;
|
||||
remark?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user