0210185 4 months ago
parent
commit
b529f0f095

+ 16 - 16
app/tab1/tab1-routing.module.ts

@@ -1,16 +1,16 @@
-import { NgModule } from '@angular/core';
-import { RouterModule, Routes } from '@angular/router';
-import { Tab1Page } from './tab1.page';
-
-const routes: Routes = [
-  {
-    path: '',
-    component: Tab1Page,
-  }
-];
-
-@NgModule({
-  imports: [RouterModule.forChild(routes)],
-  exports: [RouterModule]
-})
-export class Tab1PageRoutingModule {}
+import { NgModule } from '@angular/core';
+import { RouterModule, Routes } from '@angular/router';
+import { Tab1Page } from './tab1.page';
+
+const routes: Routes = [
+  {
+    path: '',
+    component: Tab1Page,
+  }
+];
+
+@NgModule({
+  imports: [RouterModule.forChild(routes)],
+  exports: [RouterModule]
+})
+export class Tab1PageRoutingModule {}

+ 20 - 20
app/tab1/tab1.module.ts

@@ -1,20 +1,20 @@
-import { IonicModule } from '@ionic/angular';
-import { NgModule } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
-import { Tab1Page } from './tab1.page';
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab1PageRoutingModule } from './tab1-routing.module';
-
-@NgModule({
-  imports: [
-    IonicModule,
-    CommonModule,
-    FormsModule,
-    ExploreContainerComponentModule,
-    Tab1PageRoutingModule
-  ],
-  declarations: [Tab1Page]
-})
-export class Tab1PageModule {}
+import { IonicModule } from '@ionic/angular';
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
+import { Tab1Page } from './tab1.page';
+import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
+
+import { Tab1PageRoutingModule } from './tab1-routing.module';
+
+@NgModule({
+  imports: [
+    IonicModule,
+    CommonModule,
+    FormsModule,
+    ExploreContainerComponentModule,
+    Tab1PageRoutingModule
+  ],
+  declarations: [Tab1Page]
+})
+export class Tab1PageModule {}

+ 23 - 17
app/tab1/tab1.page.html

@@ -1,17 +1,23 @@
-<ion-header [translucent]="true">
-  <ion-toolbar>
-    <ion-title>
-      Tab 1
-    </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>
-
-  <app-explore-container name="Tab 1 page"></app-explore-container>
-</ion-content>
+<ion-header [translucent]="true">
+  <ion-toolbar>
+    <ion-searchbar placeholder="搜索..." debounce="500" (ionInput)="onSearch($event)"></ion-searchbar>
+  </ion-toolbar>
+</ion-header>
+
+<ion-content [fullscreen]="true">
+  <ion-grid>
+    <ion-row>
+      <ion-col size="12">
+        <ion-list>
+          <ion-item *ngFor="let result of searchResults">
+            <!-- 显示搜索结果内容 -->
+            {{ result.title }}
+          </ion-item>
+          <ion-item *ngIf="searchResults.length === 0 && searchTerm">
+            没有找到匹配结果
+          </ion-item>
+        </ion-list>
+      </ion-col>
+    </ion-row>
+  </ion-grid>
+</ion-content>

+ 10 - 0
app/tab1/tab1.page.scss

@@ -0,0 +1,10 @@
+ion-searchbar {
+    position: sticky;
+    top: 0;
+    z-index: 100;
+  }
+  
+  ion-content {
+    --ion-background-color: #f2f2f2;
+  }
+  

+ 26 - 26
app/tab1/tab1.page.spec.ts

@@ -1,26 +1,26 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { IonicModule } from '@ionic/angular';
-
-import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
-
-import { Tab1Page } from './tab1.page';
-
-describe('Tab1Page', () => {
-  let component: Tab1Page;
-  let fixture: ComponentFixture<Tab1Page>;
-
-  beforeEach(async () => {
-    await TestBed.configureTestingModule({
-      declarations: [Tab1Page],
-      imports: [IonicModule.forRoot(), ExploreContainerComponentModule]
-    }).compileComponents();
-
-    fixture = TestBed.createComponent(Tab1Page);
-    component = fixture.componentInstance;
-    fixture.detectChanges();
-  });
-
-  it('should create', () => {
-    expect(component).toBeTruthy();
-  });
-});
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { IonicModule } from '@ionic/angular';
+
+import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
+
+import { Tab1Page } from './tab1.page';
+
+describe('Tab1Page', () => {
+  let component: Tab1Page;
+  let fixture: ComponentFixture<Tab1Page>;
+
+  beforeEach(async () => {
+    await TestBed.configureTestingModule({
+      declarations: [Tab1Page],
+      imports: [IonicModule.forRoot(), ExploreContainerComponentModule]
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(Tab1Page);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 72 - 12
app/tab1/tab1.page.ts

@@ -1,12 +1,72 @@
-import { Component } from '@angular/core';
-
-@Component({
-  selector: 'app-tab1',
-  templateUrl: 'tab1.page.html',
-  styleUrls: ['tab1.page.scss']
-})
-export class Tab1Page {
-
-  constructor() {}
-
-}
+import { Component } from '@angular/core';
+
+@Component({
+  selector: 'app-tab1',
+  templateUrl: 'tab1.page.html',
+  styleUrls: ['tab1.page.scss'],
+})
+export class Tab1Page {
+
+  searchResults: { title: string }[] = []; // 存储搜索结果
+  searchTerm: string = ''; // 存储当前搜索词
+  slides: { imgUrl: string }[] = []; // 存储轮播图数据
+  slideOpts = {
+    initialSlide: 0,
+    speed: 400,
+    autoplay: {
+      delay: 3000
+    },
+    loop: true
+  };
+
+  isSearchFocused: boolean = false; // 跟踪搜索框的聚焦状态
+  showCarousel: boolean = true; // 控制轮播图的显示
+  showContent: boolean = true; // 控制内容的显示
+
+  constructor() {
+    this.initializeSlides(); // 初始化轮播图数据
+  }
+
+  onSearch(event: any) {
+    this.searchTerm = event.target.value.trim(); // 获取搜索词并去除首尾空格
+
+    if (this.searchTerm !== '') {
+      // 模拟简单的搜索结果
+      this.searchResults = [
+        { title: '搜索结果1' },
+        { title: '搜索结果2' },
+        // 根据搜索逻辑添加更多搜索结果
+      ];
+    } else {
+      this.searchResults = []; // 清空搜索结果数组
+    }
+  }
+
+  initializeSlides() {
+    // 初始化轮播图数据,使用 assets 文件夹下的图片
+    this.slides = [
+      { imgUrl: 'assets/carousel-item1.jpg' },
+      { imgUrl: 'assets/carousel-item2.jpg' },
+      { imgUrl: 'assets/carousel-item3.jpg' },
+      { imgUrl: 'assets/carousel-item4.jpg' },
+      { imgUrl: 'assets/carousel-item5.jpg' },
+      { imgUrl: 'assets/carousel-item6.jpg' },
+    ];
+  }
+
+  onSearchFocus() {
+    // 当搜索框聚焦时,隐藏轮播图和其他内容
+    this.isSearchFocused = true;
+    this.showCarousel = false;
+    this.showContent = false;
+  }
+
+  onSearchBlur() {
+    // 当搜索框失去焦点时,根据搜索词的存在情况显示轮播图或内容
+    this.isSearchFocused = false;
+    if (this.searchTerm === '') {
+      this.showCarousel = true;
+    }
+    this.showContent = true;
+  }
+}