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