|
@@ -1,6 +1,7 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { NavController } from '@ionic/angular';
|
|
|
import { CloudObject, CloudQuery, CloudUser } from 'src/lib/ncloud';
|
|
|
+import { AuthService } from '../services/auth.service';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tab4',
|
|
@@ -16,6 +17,7 @@ export class Tab4Page implements OnInit {
|
|
|
totalWords: number = 0;
|
|
|
|
|
|
constructor(
|
|
|
+ private authService: AuthService,
|
|
|
private navCtrl:NavController
|
|
|
) { }
|
|
|
|
|
@@ -26,7 +28,6 @@ export class Tab4Page implements OnInit {
|
|
|
async loadUserData() {
|
|
|
// 获取当前用户
|
|
|
this.currentUser = await CloudUser.current();
|
|
|
-
|
|
|
if (this.currentUser) {
|
|
|
// 获取用户日记统计
|
|
|
await this.getDiaryStats();
|
|
@@ -64,7 +65,20 @@ export class Tab4Page implements OnInit {
|
|
|
return uniqueDates.size;
|
|
|
}
|
|
|
|
|
|
- goLogin(user?:string){
|
|
|
- this.navCtrl.navigateForward(["tabs","tab4","login"])
|
|
|
+ async goLogin(action?:string){
|
|
|
+ if (this.currentUser) {
|
|
|
+ // 已登录,执行登出
|
|
|
+ const success = await this.authService.logout();
|
|
|
+ if (success) {
|
|
|
+ this.currentUser = null;
|
|
|
+ this.diaryCount = 0;
|
|
|
+ this.recordDays = 0;
|
|
|
+ this.totalWords = 0;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 未登录,跳转到登录页面
|
|
|
+ this.navCtrl.navigateForward(["tabs","tab4","login"]);
|
|
|
+ }
|
|
|
+ //this.navCtrl.navigateForward(["tabs","tab4","login"])
|
|
|
}
|
|
|
}
|