|
@@ -1,5 +1,5 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
-import { AlertController, NavController } from '@ionic/angular';
|
|
|
+import { Component } from '@angular/core';
|
|
|
+import { AlertController } from '@ionic/angular';
|
|
|
import * as Parse from 'parse';
|
|
|
|
|
|
@Component({
|
|
@@ -7,50 +7,55 @@ import * as Parse from 'parse';
|
|
|
templateUrl: './page-info.component.html',
|
|
|
styleUrls: ['./page-info.component.scss']
|
|
|
})
|
|
|
-export class PageInfoComponent implements OnInit {
|
|
|
-
|
|
|
- userInfo: any = {
|
|
|
+export class PageInfoComponent {
|
|
|
+ userData = {
|
|
|
name: '',
|
|
|
- mobile: '',
|
|
|
- gender: '',
|
|
|
- birthday: ''
|
|
|
+ age: null,
|
|
|
+ gender: ''
|
|
|
};
|
|
|
- currentUser: Parse.User | undefined;
|
|
|
-
|
|
|
- constructor(private navController: NavController) {}
|
|
|
-
|
|
|
- ngOnInit() {
|
|
|
- this.currentUser = Parse.User.current();
|
|
|
- if (this.currentUser) {
|
|
|
- let json = this.currentUser.toJSON();
|
|
|
- for (const key in json) {
|
|
|
- if (this.userInfo.hasOwnProperty(key)) {
|
|
|
- this.userInfo[key] = json[key];
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ constructor(private alertController: AlertController) {
|
|
|
+ (Parse as any).serverURL = 'https://web2023.fmode.cn/parse';
|
|
|
+ Parse.initialize('dev');
|
|
|
+
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ if (currentUser) {
|
|
|
+ this.userData.name = currentUser.get('name') || '';
|
|
|
+ this.userData.age = currentUser.get('age') || null;
|
|
|
+ this.userData.gender = currentUser.get('gender') || '';
|
|
|
}
|
|
|
- console.log(this.userInfo);
|
|
|
}
|
|
|
|
|
|
- save() {
|
|
|
- this.currentUser = Parse.User.current();
|
|
|
- if (this.currentUser) {
|
|
|
- console.log(this.userInfo);
|
|
|
- for (const key in this.userInfo) {
|
|
|
- if (this.userInfo.hasOwnProperty(key)) {
|
|
|
- this.currentUser.set(key, this.userInfo[key]);
|
|
|
- }
|
|
|
+ async saveInfo() {
|
|
|
+ const { name, age, gender } = this.userData;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ if (currentUser) {
|
|
|
+ currentUser.set('name', name);
|
|
|
+ currentUser.set('age', age);
|
|
|
+ currentUser.set('gender', gender);
|
|
|
+
|
|
|
+ await currentUser.save();
|
|
|
+
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '保存成功',
|
|
|
+ message: '个人信息已保存。',
|
|
|
+ buttons: ['确定']
|
|
|
+ });
|
|
|
+
|
|
|
+ await alert.present();
|
|
|
+ } else {
|
|
|
+ throw new Error('用户未登录');
|
|
|
}
|
|
|
- this.currentUser.save().then(() => {
|
|
|
- this.navController.back();
|
|
|
- }).catch((error) => {
|
|
|
- console.error('Error saving user data: ', error);
|
|
|
+ } catch (error: any) {
|
|
|
+ const alert = await this.alertController.create({
|
|
|
+ header: '保存失败',
|
|
|
+ message: error.message,
|
|
|
+ buttons: ['确定']
|
|
|
});
|
|
|
+
|
|
|
+ await alert.present();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- cancel() {
|
|
|
- this.navController.back();
|
|
|
}
|
|
|
-
|
|
|
-}
|