0225221 4 mesiacov pred
rodič
commit
9f5bff6d57
5 zmenil súbory, kde vykonal 99 pridanie a 0 odobranie
  1. 20 0
      login.module.ts
  2. 28 0
      login.page.html
  3. 7 0
      login.page.scss
  4. 17 0
      login.page.spec.ts
  5. 27 0
      login.page.ts

+ 20 - 0
login.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 { LoginPageRoutingModule } from './login-routing.module';
+
+import { LoginPage } from './login.page';
+
+@NgModule({
+  imports: [
+    CommonModule,
+    FormsModule,
+    IonicModule,
+    LoginPageRoutingModule
+  ],
+  declarations: [LoginPage]
+})
+export class LoginPageModule {}

+ 28 - 0
login.page.html

@@ -0,0 +1,28 @@
+<ion-header [translucent]="true">
+    <ion-toolbar>
+      <ion-title>login</ion-title>
+    </ion-toolbar>
+  </ion-header>
+  <ion-content class="ion-text-center">
+    <ion-card>
+      <ion-card-header>
+        登录
+      </ion-card-header>
+      <ion-card-content>
+        <ion-item>
+          <ion-label position="floating">用户名</ion-label>
+          <ion-input type="text" [(ngModel)]="username"></ion-input>
+        </ion-item>
+        <ion-item>
+          <ion-label position="floating">密码</ion-label>
+          <ion-input type="password" [(ngModel)]="password"></ion-input>
+        </ion-item>
+        <ion-button expand="full" (click)="goToFirst()">登录</ion-button>
+        <ion-button expand="full" (click)="goToRegister()">注册</ion-button>
+        <ion-text *ngIf="loginFailed" color="danger">登录失败</ion-text>
+      </ion-card-content>
+    </ion-card>
+  </ion-content>
+  
+  
+  

+ 7 - 0
login.page.scss

@@ -0,0 +1,7 @@
+ion-content {
+     display: flex;
+      justify-content: center;
+     align-items: center;
+     height: 100vh;
+    }
+    

+ 17 - 0
login.page.spec.ts

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

+ 27 - 0
login.page.ts

@@ -0,0 +1,27 @@
+import { Component } from '@angular/core';
+import { Router } from '@angular/router';
+import { RegisterPage } from '../register/register.page';
+
+@Component({
+  selector: 'app-login',
+  templateUrl: 'login.page.html',
+  styleUrls: ['login.page.scss']
+})
+export class LoginPage {
+  username: string='';
+  password: string='';
+  loginFailed: boolean = false;
+
+  constructor(private router: Router) {}
+
+  goToFirst() {
+    // 真实项目中应该调用后端API验证用户名和密码
+    
+    // 这里简单模拟登录成功
+    this.router.navigate(['/tabs']);
+  }
+
+  goToRegister() {
+    this.router.navigate(['/register']);
+  }
+}