refactor(passport): 适配二维码登录后端ConfirmLoginResult接口
- 扩展ConfirmLoginResult状态字段,添加accessToken、expiresIn等信息 - 新增绑定手机号、跳转等下一步操作字段支持 - 更新登录确认逻辑,使用status字段判断confirmed状态 - 支持successMessage及message多样提示内容 - 增加绑定手机号状态时提示并跳转到手机号绑定页 - 保留兼容旧版success布尔字段处理逻辑
This commit is contained in:
@@ -78,19 +78,36 @@ export interface ConfirmLoginParam {
|
||||
deviceInfo?: string;
|
||||
}
|
||||
|
||||
// 确认登录响应
|
||||
// 确认登录响应(适配后端 QrLoginStatusResponse)
|
||||
export interface ConfirmLoginResult {
|
||||
// 是否成功
|
||||
success: boolean;
|
||||
// 消息
|
||||
message: string;
|
||||
// 登录用户信息
|
||||
// 状态: pending-等待扫码, scanned-已扫码, confirmed-已确认, bind_phone-待绑定手机号, expired-已过期
|
||||
status: string;
|
||||
// JWT访问令牌(仅在confirmed状态时返回)
|
||||
accessToken?: string;
|
||||
// 用户信息
|
||||
userInfo?: {
|
||||
userId: number;
|
||||
username?: string;
|
||||
nickname?: string;
|
||||
avatar?: string;
|
||||
phone?: string;
|
||||
};
|
||||
// 剩余过期时间(秒)
|
||||
expiresIn?: number;
|
||||
// 租户ID
|
||||
tenantId?: number;
|
||||
// 是否需要绑定手机号
|
||||
needBindPhone?: boolean;
|
||||
// 状态提示信息
|
||||
message?: string;
|
||||
// 下一步操作:bind_phone-绑定手机号, redirect-跳转, wait-等待
|
||||
nextAction?: string;
|
||||
// 跳转URL(当nextAction为redirect时使用)
|
||||
redirectUrl?: string;
|
||||
// 成功消息
|
||||
successMessage?: string;
|
||||
// 兼容字段:如果后端返回 success
|
||||
success?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,10 +140,13 @@ const QRConfirmPage: React.FC = () => {
|
||||
}
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
// 根据 status 判断成功:confirmed 表示登录成功
|
||||
const isConfirmed = result.status === 'confirmed' || result.success === true;
|
||||
|
||||
if (isConfirmed) {
|
||||
setConfirmed(true);
|
||||
Taro.showToast({
|
||||
title: '登录确认成功',
|
||||
title: result.successMessage || result.message || '登录确认成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
@@ -164,6 +167,15 @@ const QRConfirmPage: React.FC = () => {
|
||||
});
|
||||
}
|
||||
}, 3000);
|
||||
} else if (result.status === 'bind_phone' || result.needBindPhone) {
|
||||
// 需要绑定手机号
|
||||
Taro.showToast({
|
||||
title: '请先绑定手机号',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
Taro.redirectTo({ url: '/passport/sms-login' });
|
||||
}, 1500);
|
||||
} else {
|
||||
setError(result.message || '登录确认失败');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user