生产管理系统 - 2种角色的登录

This commit is contained in:
2025-10-31 14:52:30 +08:00
parent 46ff61eaed
commit ad600ce059
7 changed files with 371 additions and 25 deletions

View File

@@ -28,7 +28,7 @@ import {
import { toast } from 'sonner';
import { useAuth } from '@/components/auth/AuthContext';
import { authReducer, initialAuthState, AuthState, AuthAction } from './authReducer';
import { loginApiV1AuthLoginPost } from '@/lib/api/sdk.gen';
import { getCaptchaApiV1AuthCaptchaGet, loginApiV1AuthLoginPost } from '@/lib/api/sdk.gen';
import type { CaptchaResponse } from '@/lib/api/types.gen';
interface LoginFormProps {
@@ -128,6 +128,8 @@ export function LoginForm({ onRegisterClick }: LoginFormProps) {
enterpriseId: response.data.enterprise_id || '',
enterpriseName: response.data.enterprise_name || '',
createdAt: response.data.created_at || new Date().toISOString(),
// 重要存储token到用户对象中
token: response.data.access_token || response.data.token || null,
};
// 打印登录成功日志
@@ -137,10 +139,20 @@ export function LoginForm({ onRegisterClick }: LoginFormProps) {
timestamp: new Date().toISOString()
});
// 验证token是否正确存储
if (userData.token) {
console.log('🔑 Token已存储:', userData.token.substring(0, 20) + '...');
} else {
console.warn('⚠️ 未找到token请检查API响应格式');
}
login(userData);
toast.success('登录成功!');
// 暂时不实现页面跳转
console.log('✅ 登录流程完成,等待后续页面跳转实现');
toast.success('登录成功!正在跳转...');
// 跳转到个人中心页面
setTimeout(() => {
window.location.href = '/central-config/personal-center/personal-info';
}, 1000);
} else {
dispatch({ type: 'SET_ERROR', payload: '登录失败,请检查用户名和密码' });
toast.error('登录失败,请检查用户名和密码');