陈松 4 сар өмнө
parent
commit
e40c157c7d

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 286 - 254
package-lock.json


+ 1 - 0
package.json

@@ -38,6 +38,7 @@
     "@angular/cli": "^17.0.0",
     "@angular/compiler-cli": "^17.0.2",
     "@angular/language-service": "^17.0.2",
+    "@compodoc/compodoc": "^1.1.25",
     "@ionic/angular-toolkit": "^11.0.1",
     "@types/jasmine": "~5.1.0",
     "@types/parse": "^3.0.9",

+ 28 - 35
src/modules/user/page-info/page-info.component.html

@@ -1,49 +1,42 @@
-<ion-header [translucent]="true">
+<ion-header>
   <ion-toolbar>
-    <ion-title>资料编辑</ion-title>
+    <ion-buttons slot="start">
+      <ion-back-button defaultHref="/lesson/mine"></ion-back-button>
+    </ion-buttons>
+    <ion-title>
+      个人信息
+    </ion-title>
   </ion-toolbar>
 </ion-header>
 
-<ion-content [fullscreen]="true">
-  <ion-header collapse="condense">
-    <ion-toolbar>
-      <ion-title size="large">资料编辑</ion-title>
-    </ion-toolbar>
-  </ion-header>
-
+<ion-content>
   <ion-card>
     <ion-card-header>
-      <ion-card-title>{{currentUser?.get('username')}} - {{currentUser?.id}}</ion-card-title>
+      <ion-card-title>个人资料</ion-card-title>
     </ion-card-header>
+
     <ion-card-content>
-      <ion-list>
-        <ion-item>
-          <ion-input label="姓名" type="text" [(ngModel)]="userInfo.name"></ion-input>
-        </ion-item>
-        <ion-item>
-          <ion-input label="手机" type="tel" [(ngModel)]="userInfo.mobile"></ion-input>
-        </ion-item>
-        <ion-item>
-          <ion-select label="性别" [(ngModel)]="userInfo.gender">
-            <ion-select-option value="男">男</ion-select-option>
-            <ion-select-option value="女">女</ion-select-option>
-          </ion-select>
-        </ion-item>
-        <ion-item>
-          <ion-label>生日</ion-label>
-          <ion-datetime-button datetime="birthday"></ion-datetime-button>
-          <ion-modal [keepContentsMounted]="true">
-            <ng-template>
-              <ion-datetime id="birthday" displayFormat="MM/DD/YYYY" [(ngModel)]="userInfo.birthday"></ion-datetime>
-            </ng-template>
-          </ion-modal>
-        </ion-item>
-      </ion-list>
+      <ion-item>
+        <ion-label position="floating">姓名</ion-label>
+        <ion-input [(ngModel)]="userData.name" name="name" type="text"></ion-input>
+      </ion-item>
+
+      <ion-item>
+        <ion-label position="floating">年龄</ion-label>
+        <ion-input [(ngModel)]="userData.age" name="age" type="number"></ion-input>
+      </ion-item>
+
+      <ion-item>
+        <ion-label position="floating">性别</ion-label>
+        <ion-select [(ngModel)]="userData.gender" name="gender">
+          <ion-select-option value="male">男</ion-select-option>
+          <ion-select-option value="female">女</ion-select-option>
+        </ion-select>
+      </ion-item>
     </ion-card-content>
   </ion-card>
 
-  <ion-button expand="block" (click)="save()">保存</ion-button>
-  <ion-button expand="block" (click)="cancel()">取消</ion-button>
+  <ion-button expand="block" (click)="saveInfo()">保存</ion-button>
 </ion-content>
 
 

+ 44 - 39
src/modules/user/page-info/page-info.component.ts

@@ -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();
   }
-
-}

+ 1 - 1
src/modules/user/page-login/page-login.component.html

@@ -25,7 +25,7 @@
         </ion-card-content>
     
         <ion-button expand="block" (click)="login()">登录</ion-button>
-        <ion-button expand="block" fill="clear"routerLink="../../tabs/tab3" >返回</ion-button>
+        <ion-button expand="block" fill="clear"routerLink="/lesson/mine" >返回</ion-button>
     </ion-card>
 </div>
 

+ 1 - 2
src/modules/user/page-login/page-login.component.ts

@@ -37,8 +37,7 @@ export class PageLoginComponent {
       await alert.present();
 
       // 导航到目标页面
-      this.router.navigateByUrl('tabs/tab3');
-      window.location.reload();
+      this.router.navigateByUrl('/lesson/mine');
     } catch (error: any) {
       const alert = await this.alertController.create({
         header: '登录失败',

+ 2 - 2
src/modules/user/page-register/page-register.component.html

@@ -1,4 +1,4 @@
-
+<!-- IonicModule + FormsModule implementation, default styling -->
 <div class="register-modal">
     <ion-card>
         <ion-card-header>
@@ -24,7 +24,7 @@
         </ion-card-content>
 
         <ion-button expand="block" (click)="register()">注册</ion-button>
-        <ion-button expand="block" fill="clear" routerLink="../../tabs/tab3">返回</ion-button>
+        <ion-button expand="block" fill="clear" routerLink="/lesson/mine">返回</ion-button>
     </ion-card>
 </div>
 

+ 0 - 8
src/modules/user/page-register/page-register.component.scss

@@ -1,8 +0,0 @@
-.register-modal{
-    height:100vh;
-    width: 100vw;
-    display: flex;
-    flex-direction: column;
-    vertical-align: middle;
-    justify-content: center;
-}

+ 1 - 1
src/modules/user/page-register/page-register.component.ts

@@ -41,7 +41,7 @@ export class PageRegisterComponent {
       await alert.present();
 
       // 导航到目标页面
-      this.router.navigateByUrl('tabs/tab3');
+      this.router.navigateByUrl('/lesson/mine');
     } catch (error: any) {
       const alert = await this.alertController.create({
         header: '注册失败',

+ 3 - 0
tsconfig.doc.json

@@ -0,0 +1,3 @@
+{
+    "include": ["src/**/*.ts"]
+}

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно