|
@@ -1,6 +1,7 @@
|
|
|
import { Component } from '@angular/core';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { AlertController } from '@ionic/angular';
|
|
|
+import { ChangeDetectorRef } from '@angular/core';
|
|
|
// import { AuthService } from './AuthService';
|
|
|
import Parse from "parse"
|
|
|
|
|
@@ -13,7 +14,7 @@ export class Tab3Page {
|
|
|
isLoggedIn: boolean = false;
|
|
|
// isLoggedIn: boolean = false;
|
|
|
user = {
|
|
|
- name: 'John Doe',
|
|
|
+ nickname: 'John Doe',
|
|
|
avatarUrl: 'assets/美津未.jpg',
|
|
|
campus: 'Main Campus',
|
|
|
building: 'A',
|
|
@@ -25,30 +26,37 @@ export class Tab3Page {
|
|
|
|
|
|
constructor(
|
|
|
private router: Router,
|
|
|
- private alertController: AlertController
|
|
|
+ private alertController: AlertController,private cdr: ChangeDetectorRef
|
|
|
) {
|
|
|
const navigation = this.router.getCurrentNavigation();
|
|
|
const state = navigation?.extras.state;
|
|
|
if (state && state['isLoggedIn']) {
|
|
|
this.isLoggedIn = true;
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ refreshView() {
|
|
|
+ // 执行变化检测并刷新视图
|
|
|
+ this.cdr.detectChanges();
|
|
|
+ };
|
|
|
currentUser:Parse.User|undefined
|
|
|
|
|
|
async ngOnInit() {
|
|
|
this.currentUser = await Parse.User.current();
|
|
|
+ setInterval(()=>{
|
|
|
+ this.refreshPage()
|
|
|
+ },1000)
|
|
|
if (this.currentUser) {
|
|
|
// 如果有当前用户信息,则更新user对象
|
|
|
- this.user.name = this.currentUser.get("name");
|
|
|
+ this.user.nickname = this.currentUser.get("nickname");
|
|
|
this.user.gender=this.currentUser.get("gender");
|
|
|
// 根据你的数据库字段来更新其他用户信息
|
|
|
- // this.user.avatarUrl = this.currentUser.get("avatarUrl");
|
|
|
+ this.user.avatarUrl = this.currentUser.get("avatarUrl");
|
|
|
this.user.campus = this.currentUser.get("campus");
|
|
|
this.user.building = this.currentUser.get("building");
|
|
|
// this.user.gender = this.username.get("gender");
|
|
|
- console.log(this.user.name);
|
|
|
+ console.log(this.user.nickname);
|
|
|
//detectChanges();
|
|
|
}
|
|
|
}
|
|
@@ -58,7 +66,17 @@ export class Tab3Page {
|
|
|
// this.username = await Parse.User.current()
|
|
|
// },1000)
|
|
|
|
|
|
-
|
|
|
+ async refreshPage() {
|
|
|
+ this.currentUser = await Parse.User.current();
|
|
|
+ if (this.currentUser) {
|
|
|
+ this.user.nickname = this.currentUser.get("nickname");
|
|
|
+ this.user.gender = this.currentUser.get("gender");
|
|
|
+ this.user.campus = this.currentUser.get("campus");
|
|
|
+ this.user.building = this.currentUser.get("building");
|
|
|
+ // detectChanges( );
|
|
|
+ // 可根据需要更新其他用户信息
|
|
|
+ }
|
|
|
+ }
|
|
|
onFileSelected(event: any) {
|
|
|
const file: File = event.target.files[0];
|
|
|
const reader = new FileReader();
|
|
@@ -66,6 +84,7 @@ export class Tab3Page {
|
|
|
this.editedUser.avatarUrl = reader.result as string;
|
|
|
};
|
|
|
reader.readAsDataURL(file);
|
|
|
+ this.refreshPage();
|
|
|
}
|
|
|
|
|
|
startEditing() {
|
|
@@ -93,11 +112,11 @@ export class Tab3Page {
|
|
|
logout() {
|
|
|
// Handle logout logic here
|
|
|
Parse.User.logOut();
|
|
|
+ this.refreshPage();
|
|
|
+ // detectChanges();
|
|
|
console.log("退出登入!");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function detectChanges() {
|
|
|
- throw new Error('Function not implemented.');
|
|
|
-}
|
|
|
+
|