Переглянути джерело

feat: accomplish modal-edit-page

cyx 3 місяців тому
батько
коміт
0b643f1839

+ 40 - 36
TFPower-app/src/app/app.routes.ts

@@ -1,39 +1,43 @@
-import { Routes,RouterModule } from '@angular/router';
-import { PostPageComponent } from './post-page/post-page.component'; // 导入 PostPage 组件
-import { CommunityPage } from './community/community.page';
-import { SharePageComponent } from './share-page/share-page.component';
-import { NgModule } from '@angular/core';
-export const routes: Routes = [
-  {
-    path: '',
-    loadChildren: () => import('./tabs/tabs.routes').then((m) => m.routes),
+import { Routes,RouterModule } from '@angular/router';
+import { PostPageComponent } from './post-page/post-page.component'; // 导入 PostPage 组件
+import { CommunityPage } from './community/community.page';
+import { SharePageComponent } from './share-page/share-page.component';
+import { NgModule } from '@angular/core';
+export const routes: Routes = [
+  {
+    path: '',
+    loadChildren: () => import('./tabs/tabs.routes').then((m) => m.routes),
+  },
+  {
+
+    path: 'community',
+    loadComponent: () => import('./community/community.page').then( m => m.CommunityPage)
+  },
+  { path: '', redirectTo: 'community', pathMatch: 'full' },
+  { path: 'community', component: CommunityPage },
+  { path: 'post-page/:id', component: PostPageComponent }, // 动态详情页面的路由
+  { path: 'share', component: SharePageComponent },
+
+    {path: 'login-page',
+    loadComponent: () =>
+      import('./page/login-page/login-page.page').then((m) => m.LoginPagePage),
+  },
+  {
+    path: 'register-page',
+    loadComponent: () =>
+      import('./page/register-page/register-page.page').then(
+        (m) => m.RegisterPagePage
+      ),
+  },
  {
+    path: 'modal-edit-page',
+    loadComponent: () => import('./page/modal-edit-page/modal-edit-page.page').then( m => m.ModalEditPagePage)
   },
-  {
 
-    path: 'community',
-    loadComponent: () => import('./community/community.page').then( m => m.CommunityPage)
-  },
-  { path: '', redirectTo: 'community', pathMatch: 'full' },
-  { path: 'community', component: CommunityPage },
-  { path: 'post-page/:id', component: PostPageComponent }, // 动态详情页面的路由
-  { path: 'share', component: SharePageComponent },
-
-    {path: 'login-page',
-    loadComponent: () =>
-      import('./page/login-page/login-page.page').then((m) => m.LoginPagePage),
-  },
-  {
-    path: 'register-page',
-    loadComponent: () =>
-      import('./page/register-page/register-page.page').then(
-        (m) => m.RegisterPagePage
-      ),
-  },
-];
-
-
-@NgModule({
-  imports: [RouterModule.forRoot(routes)],
-  exports: [RouterModule]
-})
+];
+
+
+@NgModule({
+  imports: [RouterModule.forRoot(routes)],
+  exports: [RouterModule]
+})
 export class AppRoutingModule { }

+ 4 - 0
TFPower-app/src/app/page/login-page/login-page.page.ts

@@ -42,6 +42,8 @@ export class LoginPagePage implements OnInit {
     sex: '-',
     email: '-',
     phoneNumber: '-',
+    height: 0,
+    weight: 0,
     fans: 0,
     likes: 0,
   };
@@ -72,6 +74,8 @@ export class LoginPagePage implements OnInit {
         this.user.sex = this.currentUser.data.sex;
         this.user.email = this.currentUser.data.email;
         this.user.phoneNumber = this.currentUser.data.phoneNumber;
+        this.user.height = this.currentUser.data.height;
+        this.user.weight = this.currentUser.data.weight;
         this.user.fans = this.currentUser.data.fans;
         this.user.likes = this.currentUser.data.likes;
         localStorage.setItem('userData', JSON.stringify(this.currentUser.data));

+ 32 - 0
TFPower-app/src/app/page/modal-edit-page/modal-edit-page.page.html

@@ -0,0 +1,32 @@
+<ion-header>
+  <ion-toolbar>
+    <ion-buttons slot="start">
+      <ion-button color="medium" (click)="cancel()">取消</ion-button>
+    </ion-buttons>
+    <ion-title>完善用户资料</ion-title>
+    <ion-buttons slot="end">
+      <ion-button (click)="confirm()" [strong]="true">确认</ion-button>
+    </ion-buttons>
+  </ion-toolbar>
+</ion-header>
+<ion-content class="ion-padding">
+  <ion-item>
+    <ion-input label="邮箱" [value]="email" placeholder="example@qq.com" (ionInput)="userInputEmail($event)"></ion-input>
+  </ion-item>
+  <ion-item>
+    <ion-input label="电话号码" [value]="phoneNumber" placeholder="10086"
+      (ionInput)="userInputPhoneNumber($event)"></ion-input>
+  </ion-item>
+  <ion-item>
+    <ion-input label="性别" [value]="sex" placeholder="男" (ionInput)="userInputSex($event)"></ion-input>
+  </ion-item>
+  <ion-item>
+    <ion-input label="年龄" [value]="age" placeholder="18" (ionInput)="userInputAge($event)"></ion-input>
+  </ion-item>
+  <ion-item>
+    <ion-input label="身高(cm)" [value]="height" placeholder="180" (ionInput)="userInputHeight($event)"></ion-input>
+  </ion-item>
+  <ion-item>
+    <ion-input label="体重(kg)" [value]="weight" placeholder="72" (ionInput)="userInputWeight($event)"></ion-input>
+  </ion-item>
+</ion-content>

+ 0 - 0
TFPower-app/src/app/page/modal-edit-page/modal-edit-page.page.scss


+ 17 - 0
TFPower-app/src/app/page/modal-edit-page/modal-edit-page.page.spec.ts

@@ -0,0 +1,17 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ModalEditPagePage } from './modal-edit-page.page';
+
+describe('ModalEditPagePage', () => {
+  let component: ModalEditPagePage;
+  let fixture: ComponentFixture<ModalEditPagePage>;
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(ModalEditPagePage);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 88 - 0
TFPower-app/src/app/page/modal-edit-page/modal-edit-page.page.ts

@@ -0,0 +1,88 @@
+import { Component, OnInit } from '@angular/core';
+import {
+  IonButton,
+  IonButtons,
+  IonContent,
+  IonHeader,
+  IonInput,
+  IonItem,
+  IonTitle,
+  IonToolbar,
+  ModalController,
+} from '@ionic/angular/standalone';
+
+@Component({
+  selector: 'app-modal-edit-page',
+  templateUrl: './modal-edit-page.page.html',
+  styleUrls: ['./modal-edit-page.page.scss'],
+  standalone: true,
+  imports: [
+    IonContent,
+    IonHeader,
+    IonTitle,
+    IonToolbar,
+    IonButtons,
+    IonButton,
+    IonItem,
+    IonInput,
+  ],
+})
+export class ModalEditPagePage implements OnInit {
+  name: string = '';
+  email: string = '';
+  phoneNumber: string = '';
+  sex: string = '';
+  age: number = 0;
+  height: number = 0;
+  weight: number = 0;
+  userInputEmail(ev: any) {
+    this.email = ev.detail.value;
+  }
+  userInputPhoneNumber(ev: any) {
+    this.phoneNumber = ev.detail.value;
+  }
+  userInputSex(ev: any) {
+    this.sex = ev.detail.value;
+  }
+  userInputAge(ev: any) {
+    this.age = ev.detail.value;
+  }
+  userInputHeight(ev: any) {
+    this.height = ev.detail.value;
+  }
+  userInputWeight(ev: any) {
+    this.weight = ev.detail.value;
+  }
+
+  constructor(private modalCtrl: ModalController) {
+    let userCache = localStorage.getItem('userData');
+    if (userCache) {
+      let userData = JSON.parse(userCache);
+      this.age = userData.age;
+      this.sex = userData.sex;
+      this.email = userData.email;
+      this.phoneNumber = userData.phoneNumber;
+      this.height = userData.height;
+      this.weight = userData.weight;
+    }
+  }
+
+  cancel() {
+    return this.modalCtrl.dismiss(null, 'cancel');
+  }
+
+  confirm() {
+    let userData = {
+      email: this.email,
+      phoneNumber: this.phoneNumber,
+      sex: this.sex,
+      age: this.age,
+      height: this.height,
+      weight: this.weight,
+    };
+
+    return this.modalCtrl.dismiss(userData, 'confirm');
+  }
+
+  ngOnInit() {}
+}

+ 3 - 48
TFPower-app/src/app/tab4/tab4.page.html

@@ -1,4 +1,4 @@
-<!-- <ion-header [translucent]="true">
+<ion-header [translucent]="true">
   <ion-toolbar>
     <ion-title>
       我的
@@ -22,7 +22,8 @@
         </ion-col>
       </ion-row>
       <ion-card-content>
-        <ion-button expand="block" (click)="updateUser()">修改</ion-button>
+        <!-- <ion-button expand="block" (click)="updateUser()">修改</ion-button> -->
+        <ion-button expand="block" (click)="openModal()">修改</ion-button>
         <ion-button expand="full" (click)="logout()">登出</ion-button>
       </ion-card-content>
       }
@@ -40,7 +41,6 @@
       </ion-row>
       <ion-card-content>
         <ion-button expand="full" (click)="navigateTo('login-page')">登录</ion-button>
-        <!-- <ion-button expand="full" (click)="login()">登录</ion-button> -->
         <ion-button expand="full" (click)="navigateTo('register-page')">注册</ion-button>
       </ion-card-content>
 
@@ -49,49 +49,4 @@
 
 
   </ion-card>
-
-</ion-content> -->
-
-
-
-
-
-
-
-
-
-<ion-header [translucent]="true">
-  <ion-toolbar color="success">
-    <ion-title>me</ion-title>
-  </ion-toolbar>
-</ion-header>
-
-<ion-content [fullscreen]="true">
-
-  <ion-card>
-    <!-- 未登录 -->
-     @if(!currentUser?.id){
-       <ion-card-header>
-         <ion-card-title>请登录</ion-card-title>
-         <ion-card-subtitle>暂无信息</ion-card-subtitle>
-        </ion-card-header>
-      }
-        <!-- 未登录 -->
-     @if(currentUser?.id){
-      <ion-card-header>
-        <ion-card-title>{{currentUser?.get("username")}} {{currentUser?.get("realname")}}</ion-card-title>
-        <ion-card-subtitle>性别:{{currentUser?.get("gender")||"-"}} 年龄:{{currentUser?.get("age")||"-"}}</ion-card-subtitle>
-      </ion-card-header>
-      }
-      <ion-card-content>
-      @if(!currentUser?.id){
-        <ion-button expand="block" (click)="signup()">注册</ion-button>
-        <ion-button expand="block" (click)="login()">登录</ion-button>
-      }
-     @if(currentUser?.id){
-      <ion-button expand="block" (click)="editUser()">编辑资料</ion-button>
-      <ion-button expand="block" (click)="logout()" color="light">登出</ion-button>
-    }
-    </ion-card-content>
-  </ion-card>
 </ion-content>

+ 68 - 288
TFPower-app/src/app/tab4/tab4.page.ts

@@ -1,30 +1,3 @@
-<<<<<<< Updated upstream
-// import { Component } from '@angular/core';
-// import {
-//   IonHeader,
-//   IonToolbar,
-//   IonTitle,
-//   IonContent,
-//   IonCard,
-//   IonCardContent,
-//   IonGrid,
-//   IonRow,
-//   IonCol,
-//   IonAvatar,
-//   IonButton,
-// } from '@ionic/angular/standalone';
-// import { CloudUser } from 'src/lib/cyxncloud';
-// interface User {
-//   avatar: string;
-//   username: string;
-//   age: number | null;
-//   sex: string;
-//   email: string;
-//   phoneNumber: string;
-//   fans: number;
-//   likes: number;
-// }
-=======
 import { Component } from '@angular/core';
 import { Router } from '@angular/router';
 import {
@@ -39,8 +12,10 @@ import {
   IonCol,
   IonAvatar,
   IonButton,
+  ModalController,
 } from '@ionic/angular/standalone';
 import { CloudUser } from 'src/lib/cyxncloud';
+import { ModalEditPagePage } from '../page/modal-edit-page/modal-edit-page.page';
 export interface User {
   avatar: string;
   username: string;
@@ -48,133 +23,35 @@ export interface User {
   sex: string;
   email: string;
   phoneNumber: string;
+  height: number;
+  weight: number;
   fans: number;
   likes: number;
 }
->>>>>>> Stashed changes
 
-// @Component({
-//   selector: 'app-tab4',
-//   templateUrl: 'tab4.page.html',
-//   styleUrls: ['tab4.page.scss'],
-//   standalone: true,
-//   imports: [
-//     IonHeader,
-//     IonToolbar,
-//     IonTitle,
-//     IonContent,
-//     IonCard,
-//     IonGrid,
-//     IonRow,
-//     IonCol,
-//     IonAvatar,
-//     IonCardContent,
-//     IonButton,
-//   ],
-// })
-// export class Tab4Page {
-//   is_login: boolean = false;
-//   currentUser: CloudUser | null = null;
-//   user: User = {
-//     username: '请登录',
-//     avatar: 'https://ionicframework.com/docs/img/demos/avatar.svg',
-//     age: 0,
-//     sex: '-',
-//     email: '-',
-//     phoneNumber: '-',
-//     fans: 0,
-//     likes: 0,
-//   };
-//   constructor() {
-//     let userCache = localStorage.getItem('userData');
-//     if (userCache) {
-//       let userData = JSON.parse(userCache);
-//       this.user.avatar = userData.avatar;
-//       this.user.username = userData.username;
-//       this.user.age = userData.age;
-//       this.user.sex = userData.sex;
-//       this.user.email = userData.email;
-//       this.user.phoneNumber = userData.phoneNumber;
-//       this.user.fans = userData.fans;
-//       this.user.likes = userData.likes;
-
-//       let is_loginCache = localStorage.getItem('is_login');
-//       this.is_login = is_loginCache === 'true' ? true : false;
-//     }
-//   }
-//   async login() {
-//     this.is_login = true;
-//     let user = new CloudUser();
-//     this.currentUser = await user.login('cyx', 'cyx123456');
-//     if (this.currentUser) {
-//       this.user.avatar = this.currentUser.data.avatar;
-//       this.user.username = this.currentUser.data.username;
-//       this.user.age = this.currentUser.data.age;
-//       this.user.sex = this.currentUser.data.sex;
-//       this.user.email = this.currentUser.data.email;
-//       this.user.phoneNumber = this.currentUser.data.phoneNumber;
-//       this.user.fans = this.currentUser.data.fans;
-//       this.user.likes = this.currentUser.data.likes;
-//       localStorage.setItem('userData', JSON.stringify(this.currentUser.data));
-//       localStorage.setItem('is_login', 'true');
-//     }
-//   }
-//   async logout() {
-//     this.is_login = false;
-//     let user = new CloudUser();
-//     let flag = await user.logout();
-//     localStorage.removeItem('user');
-//     localStorage.removeItem('is_login');
-//   }
-//   register() {}
-//   updateUser() {}
-  
-// }
-
-
-import { Component, OnInit } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
-import { IonContent, IonHeader, IonTitle, IonToolbar, 
-  IonButton, IonLabel, IonItem, IonList, IonBackButton,
-   IonButtons, IonIcon, IonItemDivider, IonAvatar, IonThumbnail,
-    IonItemOptions, IonItemOption, IonItemSliding, IonInput,
-     IonCheckbox, IonRadio, IonToggle, IonRadioGroup, IonSearchbar
-     , IonSegment, IonSegmentButton, IonDatetime, ModalController,
-      IonCardContent, IonCardSubtitle, IonCardTitle, IonCardHeader
-      ,IonCard } from '@ionic/angular/standalone';
-import { RouterModule } from '@angular/router';
-import { addIcons } from 'ionicons';
-import { add } from 'ionicons/icons';
-// import {FmodeChatCompletion} from "fmode-ng"
-import { CloudUser } from 'src/lib/ncloud';
-import { openUserLoginModal } from 'src/lib/user/modal-user-login/modal-user-login.component';
-import { openUserEditModal } from 'src/lib/user/modal-user-edit/modal-user-edit.component';
-
-addIcons({ add })
 @Component({
-  selector: 'app-me',
-  templateUrl: './tab4.page.html',
-  styleUrls: ['./tab4.page.scss'],
+  selector: 'app-tab4',
+  templateUrl: 'tab4.page.html',
+  styleUrls: ['tab4.page.scss'],
   standalone: true,
-  imports: [IonContent, IonHeader, IonTitle, 
-    IonToolbar, CommonModule, FormsModule, 
-    IonButton, RouterModule, IonLabel, IonLabel,
-     IonList, IonItem,  IonBackButton, IonButtons,
-      IonIcon, IonItemDivider, IonAvatar, IonThumbnail, 
-      IonItemOptions, IonItemSliding, IonItemOption,
-       IonItemOptions, IonInput, IonCheckbox, IonRadio,
-        IonToggle, IonRadioGroup, IonSearchbar,
-         IonSegment, IonSegmentButton, IonDatetime,
-         IonCardContent,IonCardSubtitle,IonCardTitle,
-         IonCardHeader,IonCardSubtitle,IonCard]
+  imports: [
+    IonHeader,
+    IonToolbar,
+    IonTitle,
+    IonContent,
+    IonCard,
+    IonGrid,
+    IonRow,
+    IonCol,
+    IonAvatar,
+    IonCardContent,
+    IonButton,
+  ],
 })
-<<<<<<< Updated upstream
-export class Tab4Page implements OnInit {
-=======
 export class Tab4Page {
   is_login: boolean = false;
   currentUser: CloudUser | null = null;
+  userChangeInfo: any = '';
   user: User = {
     avatar: 'https://ionicframework.com/docs/img/demos/avatar.svg',
     username: '请登录',
@@ -182,11 +59,13 @@ export class Tab4Page {
     sex: '-',
     email: '-',
     phoneNumber: '-',
+    height: 0,
+    weight: 0,
     fans: 0,
     likes: 0,
   };
 
-  constructor(private router: Router) {
+  constructor(private router: Router, private modalCtrl: ModalController) {
     let userCache = localStorage.getItem('userData');
     if (userCache) {
       let userData = JSON.parse(userCache);
@@ -196,156 +75,33 @@ export class Tab4Page {
       this.user.sex = userData.sex;
       this.user.email = userData.email;
       this.user.phoneNumber = userData.phoneNumber;
+      this.user.height = userData.height;
+      this.user.weight = userData.weight;
       this.user.fans = userData.fans;
       this.user.likes = userData.likes;
->>>>>>> Stashed changes
-
-  currentUser:CloudUser|undefined
-  constructor(private modalCtrl:ModalController) {
-    this.currentUser = new CloudUser();
+      let is_loginCache = localStorage.getItem('is_login');
+      this.is_login = is_loginCache === 'true' ? true : false;
+    }
   }
-<<<<<<< Updated upstream
-  ngOnInit() {
-    throw new Error('Method not implemented.');
+  navigateTo(path: string) {
+    this.router.navigate([`/${path}`]);
   }
-  // async login(){
-  //   // 弹出登录窗口
-  //   let user = await openUserLoginModal(this.modalCtrl);
-  //   if(user?.id){
-  //     this.currentUser = user
-  //   }
-  // }
-  // async signup(){
-  //   // 弹出注册窗口
-  //   let user = await openUserLoginModal(this.modalCtrl,"signup");
-  //   if(user?.id){
-  //     this.currentUser = user
-  //   }
-  // }
-  // logout(){
-  //   this.currentUser?.logout();
-  // }
-
-  async login() {
-        let user = await openUserLoginModal(this.modalCtrl);
-        if (user?.id) {
-          this.currentUser = user
-        }
-        window.location.reload();  // 登录后刷新页面
-        // this.loadPlanList()
-        // this.loadCoachList()
-        // this.loadPlanUser()
-      }
-      async signup() {
-        // 弹出注册窗口
-        let user = await openUserLoginModal(this.modalCtrl, "signup");
-        if (user?.id) {
-          this.currentUser = user
-        }
-    
-      }
-      async logout() {
-        await this.currentUser?.logout();
-        window.location.reload();  // 登录后刷新页面
-        // this.loadPlanList()
-        // this.loadCoachList()
-        // this.loadPlanUser()
-      }
-    
-      editUser() {
-        openUserEditModal(this.modalCtrl)
-      }
-
-  // editUser(){
-  //   openUserEditModal(this.modalCtrl)
-  // }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 
+  async openModal() {
+    const modal = await this.modalCtrl.create({
+      component: ModalEditPagePage,
+    });
+    modal.present();
 
+    const { data, role } = await modal.onWillDismiss();
 
-
-
-
-
-
-
-
-
-
-
-    // let bodyJson = {
-    //   "token": `Bearer ${token}`,
-    //   "messages": messageList,
-    //   "model": "fmode-4.5-128k",
-    //   "temperature": 0.5,
-    //   "presence_penalty": 0,
-    //   "frequency_penalty": 0,
-    //   "top_p": 1,
-    //   "stream": true
-    // };
-
-    // let response = await fetch("https://test.fmode.cn/api/apig/aigc/gpt/v1/chat/completions", {
-    //   "headers": {
-    //     "accept": "text/event-stream",
-    //   },
-    //   "body": JSON.stringify(bodyJson),
-    //   "method": "POST",
-    //   "mode": "cors",
-    //   "credentials": "omit"
-    // });
-    // let reader = response.body?.getReader()
-    // if (!reader) {
-    //   throw new Error("Failed to get the response reader.");
-    // }
-
-    // let decoder = new TextDecoder();
-    // let buffer = "";
-
-    // while (true) {
-    //   let { done, value } = await reader.read();
-    //   if (done) {
-    //     break;
-    //   }
-    //   let data = decoder.decode(value);
-    //   let messages = data.split("\n");
-    //   console.log(messages);
-
-    //   for (let i = 0; i < messages.length - 1; i++) {
-    //     let message = messages[i];
-    //     console.log(message);
-    //     let dataStr: string = message.split("data: ")[1]
-    //     if (dataStr && dataStr.startsWith("{")) {
-    //       try {
-    //         let json = JSON.parse(dataStr);
-    //         let content = json.choices[0].delta.content
-    //         this.gptre = this.gptre + content
-    //       } catch (err) { }
-    //     }
-
-
-    //   }
-    // }
-
-
-=======
-  navigateTo(path: string) {
-    this.router.navigate([`/${path}`]);
+    if (role === 'confirm') {
+      // this.message = `Hello, ${data}!`;
+      console.log(data);
+      this.userChangeInfo = data;
+      this.updateUser();
+    }
   }
-
   // async login() {
   //   this.is_login = true;
   //   let user = new CloudUser();
@@ -371,5 +127,29 @@ export class Tab4Page {
     let flag = await user.logout();
     localStorage.removeItem('user');
     localStorage.removeItem('is_login');
->>>>>>> Stashed changes
   }
+  async updateUser() {
+    // let userCache = localStorage.getItem('userData');
+    // if (userCache) {
+    //   let userData = JSON.parse(userCache);
+    //   console.log(userData);
+
+    //   this.currentUser = userData;
+    // }
+
+    Object.keys(this.userChangeInfo).forEach((key) => {
+      if (key == 'age') {
+        this.userChangeInfo[key] = Number(this.userChangeInfo[key]);
+      }
+      if (key == 'height') {
+        this.userChangeInfo[key] = Number(this.userChangeInfo[key]);
+      }
+      if (key == 'weight') {
+        this.userChangeInfo[key] = Number(this.userChangeInfo[key]);
+      }
+    });
+    let user = new CloudUser();
+    let res = await user.update(this.userChangeInfo);
+    console.log('成功更新用户信息');
+  }
+}

+ 44 - 19
TFPower-app/src/lib/cyxncloud.ts

@@ -88,25 +88,12 @@ export class CloudUser {
 
   // 获取当前用户信息
   async current() {
-    let url = 'http://1.94.237.145:1338/parsecyx/users/me';
-    return await fetch(url, {
-      method: 'GET',
-      headers: {
-        'X-Parse-Application-Id': 'cyx',
-        'X-Parse-Session-Token': this.sessionToken,
-      },
-    })
-      .then((response) => {
-        if (!response.ok) {
-          throw new Error('Invalid session token');
-        }
-        return response.json();
-      })
-      .then((data) => data)
-      .catch((error) => {
-        console.error('Error fetching user data:', error);
-        throw error;
-      });
+    let userCache = localStorage.getItem('userData');
+    if (userCache) {
+      let userData = JSON.parse(userCache);
+      this.objectId = userData.objectId;
+      this.sessionToken = userData.sessionToken;
+    }
   }
 
   // 用户登录
@@ -167,6 +154,44 @@ export class CloudUser {
     this.data = result;
     return this;
   }
+
+  // 修改用户信息
+  async update(userChangeInfo: any) {
+    console.log(userChangeInfo);
+
+    this.current();
+    let url =
+      `http://1.94.237.145:1338/parsecyx/classes/_User/` + this.objectId;
+    let response = await fetch(url, {
+      method: 'PUT',
+      headers: {
+        'X-Parse-Application-Id': 'cyx',
+        'X-Parse-Session-Token': this.sessionToken,
+        'Content-Type': 'application/json;charset=UTF-8',
+      },
+      body: JSON.stringify(userChangeInfo),
+      mode: 'cors',
+      credentials: 'omit',
+    });
+    console.log('update: ', this);
+
+    return this;
+  }
 }
+
+// fetch('http://1.94.237.145:1338/parsecyx/classes/_User/WBhghn8NuZ', {
+//   headers: {
+//     accept: '*/*',
+//     'accept-language':
+//       'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,zh-TW;q=0.5,ja;q=0.4',
+//     'content-type': 'text/plain',
+//   },
+//   referrer: 'http://127.0.0.1:4040/',
+//   referrerPolicy: 'strict-origin-when-cross-origin',
+//   body: '{"phoneNumber":"12345","_method":"PUT","_ApplicationId":"cyx","_ClientVersion":"js3.4.2","_MasterKey":"cyxmk","_InstallationId":"111053ea-8bfc-4dfc-8818-df34dd45d6b0"}',
+//   method: 'POST',
+//   mode: 'cors',
+//   credentials: 'omit',
+// });
 // module.exports.Query = Query;
 // module.exports.CloudUser = CloudUser;