129 lines
4.1 KiB
JavaScript
129 lines
4.1 KiB
JavaScript
// Mock 用户数据
|
|
export const mockUsers = {
|
|
// 免费用户 - 手机号登录
|
|
'13800138000': {
|
|
id: 1,
|
|
phone: '13800138000',
|
|
nickname: '测试用户',
|
|
email: 'test@example.com',
|
|
avatar_url: 'https://i.pravatar.cc/150?img=1',
|
|
has_wechat: false,
|
|
created_at: '2024-01-01T00:00:00Z',
|
|
// 会员信息 - 免费用户
|
|
subscription_type: 'free',
|
|
subscription_status: 'active',
|
|
subscription_end_date: null,
|
|
is_subscription_active: true,
|
|
subscription_days_left: 0
|
|
},
|
|
|
|
// Pro 会员 - 手机号登录
|
|
'13900139000': {
|
|
id: 2,
|
|
phone: '13900139000',
|
|
nickname: 'Pro会员',
|
|
email: 'pro@example.com',
|
|
avatar_url: 'https://i.pravatar.cc/150?img=2',
|
|
has_wechat: true,
|
|
created_at: '2024-01-15T00:00:00Z',
|
|
// 会员信息 - Pro 会员
|
|
subscription_type: 'pro',
|
|
subscription_status: 'active',
|
|
subscription_end_date: '2025-12-31T23:59:59Z',
|
|
is_subscription_active: true,
|
|
subscription_days_left: 90
|
|
},
|
|
|
|
// Max 会员 - 手机号登录
|
|
'13700137000': {
|
|
id: 3,
|
|
phone: '13700137000',
|
|
nickname: 'Max会员',
|
|
email: 'max@example.com',
|
|
avatar_url: 'https://i.pravatar.cc/150?img=3',
|
|
has_wechat: false,
|
|
created_at: '2024-02-01T00:00:00Z',
|
|
// 会员信息 - Max 会员
|
|
subscription_type: 'max',
|
|
subscription_status: 'active',
|
|
subscription_end_date: '2026-12-31T23:59:59Z',
|
|
is_subscription_active: true,
|
|
subscription_days_left: 365
|
|
},
|
|
|
|
// 过期会员 - 测试过期状态
|
|
'13600136000': {
|
|
id: 4,
|
|
phone: '13600136000',
|
|
nickname: '过期会员',
|
|
email: 'expired@example.com',
|
|
avatar_url: 'https://i.pravatar.cc/150?img=4',
|
|
has_wechat: false,
|
|
created_at: '2023-01-01T00:00:00Z',
|
|
// 会员信息 - 已过期
|
|
subscription_type: 'pro',
|
|
subscription_status: 'expired',
|
|
subscription_end_date: '2024-01-01T00:00:00Z',
|
|
is_subscription_active: false,
|
|
subscription_days_left: -300
|
|
}
|
|
};
|
|
|
|
// Mock 验证码存储(实际项目中应该在后端验证)
|
|
export const mockVerificationCodes = new Map();
|
|
|
|
// 生成随机6位验证码
|
|
export function generateVerificationCode() {
|
|
return Math.floor(100000 + Math.random() * 900000).toString();
|
|
}
|
|
|
|
// 微信 session 存储
|
|
export const mockWechatSessions = new Map();
|
|
|
|
// 生成微信 session ID
|
|
export function generateWechatSessionId() {
|
|
return 'wx_' + Math.random().toString(36).substring(2, 15);
|
|
}
|
|
|
|
// ==================== 当前登录用户状态管理 ====================
|
|
// Mock 模式下使用 localStorage 持久化登录状态
|
|
|
|
// 设置当前登录用户
|
|
export function setCurrentUser(user) {
|
|
if (user) {
|
|
// 数据兼容处理:确保用户数据包含订阅信息字段
|
|
const normalizedUser = {
|
|
...user,
|
|
// 如果缺少订阅信息,添加默认值
|
|
subscription_type: user.subscription_type || 'free',
|
|
subscription_status: user.subscription_status || 'active',
|
|
subscription_end_date: user.subscription_end_date || null,
|
|
is_subscription_active: user.is_subscription_active !== false,
|
|
subscription_days_left: user.subscription_days_left || 0
|
|
};
|
|
localStorage.setItem('mock_current_user', JSON.stringify(normalizedUser));
|
|
console.log('[Mock State] 设置当前登录用户:', normalizedUser);
|
|
}
|
|
}
|
|
|
|
// 获取当前登录用户
|
|
export function getCurrentUser() {
|
|
try {
|
|
const stored = localStorage.getItem('mock_current_user');
|
|
if (stored) {
|
|
const user = JSON.parse(stored);
|
|
console.log('[Mock State] 获取当前登录用户:', user);
|
|
return user;
|
|
}
|
|
} catch (error) {
|
|
console.error('[Mock State] 解析用户数据失败:', error);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// 清除当前登录用户
|
|
export function clearCurrentUser() {
|
|
localStorage.removeItem('mock_current_user');
|
|
console.log('[Mock State] 清除当前登录用户');
|
|
}
|