Przeglądaj źródła

login and register

18879852299-202226701057 3 miesięcy temu
rodzic
commit
682f32241d

+ 46 - 1
TFPower-app/src/app/tab4/tab4.page.html

@@ -1,4 +1,4 @@
-<ion-header [translucent]="true">
+<!-- <ion-header [translucent]="true">
   <ion-toolbar>
     <ion-title>
       我的
@@ -48,4 +48,49 @@
 
 
   </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>

+ 278 - 95
TFPower-app/src/app/tab4/tab4.page.ts

@@ -1,102 +1,285 @@
-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 {
+//   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;
+// }
 
+// @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-tab4',
-  templateUrl: 'tab4.page.html',
-  styleUrls: ['tab4.page.scss'],
+  selector: 'app-me',
+  templateUrl: './tab4.page.html',
+  styleUrls: ['./tab4.page.scss'],
   standalone: true,
-  imports: [
-    IonHeader,
-    IonToolbar,
-    IonTitle,
-    IonContent,
-    IonCard,
-    IonGrid,
-    IonRow,
-    IonCol,
-    IonAvatar,
-    IonCardContent,
-    IonButton,
-  ],
+  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]
 })
-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;
-    }
+export class Tab4Page implements OnInit {
+
+  currentUser:CloudUser|undefined
+  constructor(private modalCtrl:ModalController) {
+    this.currentUser = new CloudUser();
   }
-  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');
-    }
+  ngOnInit() {
+    throw new Error('Method not implemented.');
   }
-  async logout() {
-    this.is_login = false;
-    let user = new CloudUser();
-    let flag = await user.logout();
-    localStorage.removeItem('user');
-    localStorage.removeItem('is_login');
+  // 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)
+  // }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    // 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) { }
+    //     }
+
+
+    //   }
+    // }
+
+
   }
-  register() {}
-  updateUser() {}
-}