|
@@ -178,17 +178,23 @@ export class Tab3Page implements OnInit {
|
|
|
let user = new CloudUser();
|
|
|
await user.login(this.loginData.username, this.loginData.password);
|
|
|
|
|
|
- // 更新界面状态
|
|
|
+ // 登录后检查用户是否真的存在
|
|
|
+ const currentUser = new CloudUser();
|
|
|
+ if (!currentUser.get('username')) {
|
|
|
+ throw new Error('用户不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果登录成功且用户存在,更新界面状态
|
|
|
this.isLoggedIn = true;
|
|
|
- this.userName = user.get('username');
|
|
|
- this.userLevel = user.get('level') || 'LV.1 新手学习者';
|
|
|
- this.userAvatar = user.get('avatar') || 'assets/anime-avatar.png';
|
|
|
+ this.userName = currentUser.get('username');
|
|
|
+ this.userLevel = currentUser.get('level') || 'LV.1 新手学习者';
|
|
|
+ this.userAvatar = currentUser.get('avatar') || 'assets/anime-avatar.png';
|
|
|
|
|
|
// 更新用户统计数据
|
|
|
this.userStats = {
|
|
|
- learningDays: user.get('learningDays') || 0,
|
|
|
- achievementCount: user.get('achievementCount') || 0,
|
|
|
- completionRate: user.get('completionRate') || 0
|
|
|
+ learningDays: currentUser.get('learningDays') || 0,
|
|
|
+ achievementCount: currentUser.get('achievementCount') || 0,
|
|
|
+ completionRate: currentUser.get('completionRate') || 0
|
|
|
};
|
|
|
|
|
|
// 显示登录成功提示
|
|
@@ -202,8 +208,12 @@ export class Tab3Page implements OnInit {
|
|
|
} catch (error: any) {
|
|
|
console.error('登录错误:', error);
|
|
|
let errorMessage = '登录失败,请稍后重试';
|
|
|
+
|
|
|
+ // 根据错误代码显示不同的错误信息
|
|
|
if (error.code === 101) {
|
|
|
errorMessage = '用户名或密码错误';
|
|
|
+ } else if (error.code === 205 || error.message === '用户不存在') {
|
|
|
+ errorMessage = '用户不存在,请先注册';
|
|
|
}
|
|
|
|
|
|
const alert = await this.alertController.create({
|
|
@@ -212,6 +222,10 @@ export class Tab3Page implements OnInit {
|
|
|
buttons: ['确定']
|
|
|
});
|
|
|
await alert.present();
|
|
|
+
|
|
|
+ // 如果出错,确保用户状态为未登录
|
|
|
+ this.isLoggedIn = false;
|
|
|
+ this.resetUserData();
|
|
|
}
|
|
|
}
|
|
|
|