소스 검색

drug:search

yf 4 달 전
부모
커밋
a684a69f73
2개의 변경된 파일21개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      wisdom-app/src/app/tab3/tab3.page.html
  2. 16 0
      wisdom-app/src/app/tab3/tab3.page.ts

+ 5 - 3
wisdom-app/src/app/tab3/tab3.page.html

@@ -10,9 +10,11 @@
 
 <ion-content [fullscreen]="true" class="content-background">
   <!-- 搜索栏 -->
-  <div class="search-container">
-    <ion-searchbar placeholder="搜索" class="custom-searchbar"></ion-searchbar>
-  </div>
+  <ion-searchbar 
+  placeholder="搜索" 
+  class="custom-searchbar" 
+  (ionInput)="searchProducts($event)">
+</ion-searchbar>
 
   <!-- 分类区域(可横向滑动) -->
   <div class="category-scroll">

+ 16 - 0
wisdom-app/src/app/tab3/tab3.page.ts

@@ -101,4 +101,20 @@ export class Tab3Page {
       console.error('复制失败', err);
     });
   }
+
+  //搜索功能
+  searchTerm: string = '';
+
+async searchProducts(event: any) {
+  this.searchTerm = event.detail.value.toLowerCase();
+  if (this.searchTerm) {
+    this.products = this.allProducts.filter(product =>
+      product.get('name').toLowerCase().includes(this.searchTerm) ||
+      product.get('function').toLowerCase().includes(this.searchTerm) ||
+      product.get('composition').toLowerCase().includes(this.searchTerm)
+    );
+  } else {
+    this.products = [...this.allProducts];
+  }
+}
 }