Browse Source

任务管理

18079408532 1 year ago
parent
commit
6cc8f7e70c
2 changed files with 53 additions and 13 deletions
  1. 14 9
      src/app/tab1/tab1.page.html
  2. 39 4
      src/app/tab1/tab1.page.ts

+ 14 - 9
src/app/tab1/tab1.page.html

@@ -1,17 +1,22 @@
 <ion-header [translucent]="true">
   <ion-toolbar>
-    <ion-title>
-      Tab 1
-    </ion-title>
+    <ion-title>任务管理</ion-title>
   </ion-toolbar>
 </ion-header>
 
 <ion-content [fullscreen]="true">
-  <ion-header collapse="condense">
-    <ion-toolbar>
-      <ion-title size="large">Tab 1</ion-title>
-    </ion-toolbar>
-  </ion-header>
+  <ion-item>
+    <ion-input [(ngModel)]="newTaskTitle" placeholder="添加新任务"></ion-input>
+    <ion-button (click)="addTask()">添加</ion-button>
+  </ion-item>
+
+  <ion-list>
+    <ion-item *ngFor="let task of tasks">
+      <ion-checkbox [(ngModel)]="task.completed" (ionChange)="toggleTaskCompletion(task)"></ion-checkbox>
+      <ion-label [class.strikethrough]="task.completed">{{ task.title }}</ion-label>
+      <ion-button (click)="deleteTask(task.id)" slot="end" color="danger">删除</ion-button>
+    </ion-item>
+  </ion-list>
 
   <app-explore-container name="Tab 1 page"></app-explore-container>
-</ion-content>
+</ion-content>

+ 39 - 4
src/app/tab1/tab1.page.ts

@@ -1,14 +1,49 @@
 import { Component } from '@angular/core';
-import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonInput, IonButton, IonCheckbox } from '@ionic/angular/standalone';
 import { ExploreContainerComponent } from '../explore-container/explore-container.component';
+import { FormsModule } from '@angular/forms';
+import { CommonModule } from '@angular/common'; // 导入 CommonModule
+
+interface Task {
+  id: number;
+  title: string;
+  completed: boolean;
+}
 
 @Component({
   selector: 'app-tab1',
   templateUrl: 'tab1.page.html',
   styleUrls: ['tab1.page.scss'],
   standalone: true,
-  imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent],
+  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonInput, IonButton, IonCheckbox, ExploreContainerComponent, FormsModule, CommonModule], // 添加 CommonModule
 })
 export class Tab1Page {
-  constructor() {}
-}
+  tasks: Task[] = [];
+  newTaskTitle: string = '';
+
+  constructor() {
+    // 添加一些初始任务
+    this.tasks.push({ id: 1, title: '示例任务 1', completed: false });
+    this.tasks.push({ id: 2, title: '示例任务 2', completed: false });
+  }
+
+  addTask() {
+    if (this.newTaskTitle.trim()) {
+      const newTask: Task = {
+        id: this.tasks.length + 1,
+        title: this.newTaskTitle,
+        completed: false,
+      };
+      this.tasks.push(newTask);
+      this.newTaskTitle = '';
+    }
+  }
+
+  toggleTaskCompletion(task: Task) {
+    task.completed = !task.completed;
+  }
+
+  deleteTask(taskId: number) {
+    this.tasks = this.tasks.filter(task => task.id !== taskId);
+  }
+}