Bläddra i källkod

fit:user login

悦 陈 1 vecka sedan
förälder
incheckning
bc811972b0

+ 17 - 0
myapp/src/app/tab5/mine/mine-routing.module.ts

@@ -0,0 +1,17 @@
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { MinePage } from './mine.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: MinePage
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class MinePageRoutingModule {}

+ 20 - 0
myapp/src/app/tab5/mine/mine.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+
+import { IonicModule } from '@ionic/angular';
+
+import { MinePageRoutingModule } from './mine-routing.module';
+
+import { MinePage } from './mine.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    MinePageRoutingModule
+  ],
+  declarations: [MinePage]
+})
+export class MinePageModule {}

+ 52 - 0
myapp/src/app/tab5/mine/mine.page.html

@@ -0,0 +1,52 @@
+<ion-header [translucent]="true">
+  <ion-toolbar>
+    <ion-title>mine</ion-title>
+  </ion-toolbar>
+</ion-header>
+
+<ion-content [fullscreen]="true" class="ion-padding">
+  <div class="login-container">
+    @if(currentUser?.id) {
+      <!-- 已登录状态 -->
+      <div class="user-card">
+        <ion-avatar class="user-avatar">
+          <img [src]="currentUser?.get('avatar') || 'assets/icon/default-avatar.png'" />
+        </ion-avatar>
+        <h2 class="username">{{ currentUser?.get("username") || "未设置用户名" }}</h2>
+        <ion-button expand="block" color="danger" (click)="logout()">
+          <ion-icon slot="start" name="log-out-outline"></ion-icon>
+          退出登录
+        </ion-button>
+      </div>
+    } @else {
+      <!-- 未登录状态 -->
+      <div class="login-card">
+        <ion-avatar class="login-avatar">
+          <img src="assets/icon/default-avatar.png" />
+        </ion-avatar>
+        <h2 class="welcome-text">欢迎登录</h2>
+        
+        <ion-button expand="block" (click)="login()">
+          <ion-icon slot="start" name="log-in-outline"></ion-icon>
+          使用测试账号登录 (Clym/1234)
+        </ion-button>
+        
+        <div class="divider">
+          <span class="divider-line"></span>
+          <span class="divider-text">或</span>
+          <span class="divider-line"></span>
+        </div>
+        
+        <ion-button expand="block" fill="outline">
+          <ion-icon slot="start" name="logo-google"></ion-icon>
+          Google登录
+        </ion-button>
+        
+        <ion-button expand="block" fill="outline">
+          <ion-icon slot="start" name="logo-wechat"></ion-icon>
+          微信登录
+        </ion-button>
+      </div>
+    }
+  </div>
+</ion-content>

+ 59 - 0
myapp/src/app/tab5/mine/mine.page.scss

@@ -0,0 +1,59 @@
+.login-container {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  height: 100%;
+}
+
+.user-card, .login-card {
+  width: 100%;
+  max-width: 400px;
+  text-align: center;
+  padding: 20px;
+  background: var(--ion-card-background, #fff);
+  border-radius: 12px;
+  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
+}
+
+.user-avatar, .login-avatar {
+  width: 100px;
+  height: 100px;
+  margin: 0 auto 16px;
+}
+
+.username {
+  font-size: 1.5rem;
+  font-weight: bold;
+  margin-bottom: 24px;
+  color: var(--ion-text-color);
+}
+
+.welcome-text {
+  font-size: 1.5rem;
+  margin-bottom: 32px;
+  color: var(--ion-text-color);
+}
+
+.divider {
+  display: flex;
+  align-items: center;
+  margin: 20px 0;
+  
+  &-line {
+    flex: 1;
+    height: 1px;
+    background: var(--ion-color-medium);
+  }
+  
+  &-text {
+    padding: 0 10px;
+    color: var(--ion-color-medium);
+    font-size: 0.9rem;
+  }
+}
+
+ion-button {
+  margin-bottom: 12px;
+  --border-radius: 8px;
+}

+ 17 - 0
myapp/src/app/tab5/mine/mine.page.spec.ts

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

+ 36 - 0
myapp/src/app/tab5/mine/mine.page.ts

@@ -0,0 +1,36 @@
+import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
+import { IonRouterOutlet, ModalController } from '@ionic/angular';
+import { CloudUser } from 'src/lib/ncloud';
+
+@Component({
+  selector: 'app-mine',
+  templateUrl: './mine.page.html',
+  styleUrls: ['./mine.page.scss'],
+})
+export class MinePage implements OnInit {
+
+  currentUser:CloudUser|undefined
+  constructor(
+    private router:Router,
+    private modalCrtl:ModalController,
+    private routerOutlet:IonRouterOutlet
+  ) { 
+    
+    this.currentUser=new CloudUser()
+  }
+  async login(){
+    let user:any=new CloudUser();
+    user=await this.currentUser?.login("Clym","1234")
+    if(user?.id){
+      this.currentUser=user;
+      this.router.navigate(['/tabs/tab5']);
+    }
+  }
+  async logout(){
+    this.currentUser?.logout();
+    this.currentUser=undefined
+  }
+
+  ngOnInit() {}
+}

+ 19 - 15
myapp/src/app/tab5/tab5-routing.module.ts

@@ -1,17 +1,21 @@
-import { NgModule } from '@angular/core';
-import { Routes, RouterModule } from '@angular/router';
-
-import { Tab5Page } from './tab5.page';
-
-const routes: Routes = [
-  {
-    path: '',
-    component: Tab5Page
+import { NgModule } from '@angular/core';
+import { Routes, RouterModule } from '@angular/router';
+
+import { Tab5Page } from './tab5.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: Tab5Page
+  },
  {
+    path: 'mine',
+    loadChildren: () => import('./mine/mine.module').then( m => m.MinePageModule)
   }
-];
 
-@NgModule({
-  imports: [RouterModule.forChild(routes)],
-  exports: [RouterModule],
-})
-export class Tab5PageRoutingModule {}
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule],
+})
+export class Tab5PageRoutingModule {}

+ 4 - 0
myapp/src/app/tab5/tab5.page.html

@@ -15,6 +15,10 @@
                 <div class="identity">鸟类保护志愿者</div>
                 <div class="signature">用镜头记录每一片羽翼的美丽</div>
             </div>
+            <!-- 新增的登录按钮 -->
+            <ion-button class="login-btn" fill="outline" size="small" (click)="goMine()">
+              登录
+            </ion-button>
         </div>
         
         <!-- 粉丝数量卡片 -->

+ 13 - 0
myapp/src/app/tab5/tab5.page.scss

@@ -187,4 +187,17 @@ body {
 
 .highlight {
     color: #67c23a;
+}
+.profile-content {
+  display: flex;
+  align-items: center;
+  position: relative; /* 为绝对定位的按钮提供参考 */
+}
+
+.login-btn {
+  position: absolute;
+  right: 16px; /* 距离右侧的距离 */
+  --border-radius: 20px; /* 圆角 */
+  --padding-start: 16px;
+  --padding-end: 16px;
 }

+ 8 - 1
myapp/src/app/tab5/tab5.page.ts

@@ -1,4 +1,5 @@
 import { Component, OnInit } from '@angular/core';
+import { NavController } from '@ionic/angular';
 
 @Component({
   selector: 'app-tab5',
@@ -7,10 +8,16 @@ import { Component, OnInit } from '@angular/core';
   standalone: false,
 })
 export class Tab5Page implements OnInit {
+  
 
-  constructor() { }
+  constructor(
+    private navCtrl:NavController,
+  ) { }
 
   ngOnInit() {
   }
+  goMine(mine?:string){
+    this.navCtrl.navigateForward(["tabs","tab5","mine"])
+  }
 
 }

+ 9 - 0
myapp/src/lib/user/page-mine/page-mine.component.html

@@ -0,0 +1,9 @@
+@if(currentUser?.id){
+  <!-- 已登录 -->
+  <h1>{{currentUser?.get("username")}}</h1>
+  <button (click)="logout()">登出</button>
+}
+@if(!currentUser?.id){
+  <!-- 未登录 -->
+  <button (click)="login()">登录用户 Clym 1234</button>
+}

+ 0 - 0
myapp/src/lib/user/page-mine/page-mine.component.scss


+ 22 - 0
myapp/src/lib/user/page-mine/page-mine.component.spec.ts

@@ -0,0 +1,22 @@
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+
+import { PageMineComponent } from './page-mine.component';
+
+describe('PageMineComponent', () => {
+  let component: PageMineComponent;
+  let fixture: ComponentFixture<PageMineComponent>;
+
+  beforeEach(waitForAsync(() => {
+    TestBed.configureTestingModule({
+      imports: [PageMineComponent],
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(PageMineComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  }));
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 29 - 0
myapp/src/lib/user/page-mine/page-mine.component.ts

@@ -0,0 +1,29 @@
+import { Component, OnInit } from '@angular/core';
+import { CloudUser } from 'src/lib/ncloud';
+
+@Component({
+  selector: 'app-page-mine',
+  templateUrl: './page-mine.component.html',
+  styleUrls: ['./page-mine.component.scss'],
+  standalone: true,
+})
+export class PageMineComponent  implements OnInit {
+
+  currentUser:CloudUser|undefined
+  constructor() { 
+    this.currentUser=new CloudUser()
+  }
+  async login(){
+    let user=await this.currentUser?.login("Clym","1234")
+    if(user?.id){
+      this.currentUser=user
+    }
+  }
+  async logout(){
+    this.currentUser?.logout();
+    this.currentUser=undefined
+  }
+
+  ngOnInit() {}
+
+}