From 791a96ae03cf92478244127b294c1fe520d31e89 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期六, 11 十月 2025 11:17:10 +0800
Subject: [PATCH] 优化

---
 entry/src/main/ets/pages/home/Home.ets |   67 ++++++++++++++++++---------------
 1 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/entry/src/main/ets/pages/home/Home.ets b/entry/src/main/ets/pages/home/Home.ets
index e97d195..f4369e9 100644
--- a/entry/src/main/ets/pages/home/Home.ets
+++ b/entry/src/main/ets/pages/home/Home.ets
@@ -2,6 +2,7 @@
 import http from '@ohos.net.http';
 import { HttpResponseResult } from "../../data/HttpResponse";
 import { JSON } from "@kit.ArkTS";
+import { DOMAIN } from "../../utils/config";
 
 class TabBarBase {
   title: string = ''
@@ -61,25 +62,9 @@
     { title: '鏇村', value: '', icon: $r('app.media.classification_more') },
   ]
   @State activityList: Activity[] = []
-  @State courseList: Course[] = [
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: 'Java楂樼骇锛欽VM娣卞害璋冧紭涓嶫VM娣卞害璋冧紭', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-    // { title: '闆跺熀纭�鍒颁紒涓氱骇椤圭洰瀹炴垬', 'desc': '閽堝闆跺熀纭�灏忕櫧鎴栨兂鍗囩骇鎶�鏈爤鐨勫墠绔粠涓氳�咃紝浠庢牳蹇冭娉曞叆鎵嬶紝閫愭娣卞叆Vue3缁勪欢寮�鍙戞墦浠跺紑鍙戜欢寮�鍙�', count: '800', time: '01:30:23', difficult: '绠�鍗�' },
-
-  ]
+  @State origCourseList: Course[] = []
+  @State courseList: Course[] = []
+  @State @Watch('filterCourseList') searchKeyword: string = ''
 
   @Builder tabBarItem(name:string,index: number){
     Row(){
@@ -128,6 +113,28 @@
     return ''
   }
 
+  getDifficultText(difficult: number) {
+    if (difficult == 1) {
+      return '绠�鍗�'
+    } else if (difficult == 2) {
+      return '涓瓑'
+    } else if (difficult == 3) {
+      return '鍥伴毦'
+    }
+    return ''
+  }
+
+  filterCourseList() {
+    if (this.searchKeyword) {
+      let list = this.origCourseList.filter((ele: Course) => {
+        return ele.name.includes(this.searchKeyword) || ele.description.includes(this.searchKeyword)
+      })
+      this.courseList = list
+    } else {
+      this.courseList = this.origCourseList
+    }
+  }
+
   aboutToAppear(): void {
     this.getBannerList()
     this.getActivityList()
@@ -137,7 +144,7 @@
   getBannerList() {
     let httpRequest = http.createHttp();
     httpRequest.request(
-      "http://192.168.20.70:8080/quiz-community/public/v1.0/home/slideshows",
+      `${DOMAIN}/quiz-community/public/v1.0/home/slideshows`,
       {
         method: http.RequestMethod.GET,
         header: { 'Content-Type': 'application/json', 'x-jwt-token': `Bearer ${AppStorage.get('x-jwt-token')}` },
@@ -160,7 +167,7 @@
   getActivityList() {
     let httpRequest = http.createHttp();
     httpRequest.request(
-      "http://192.168.20.70:8080/quiz-community/public/v1.0/home/hotTraining",
+      `${DOMAIN}/quiz-community/public/v1.0/home/hotTraining`,
       {
         method: http.RequestMethod.GET,
         header: { 'Content-Type': 'application/json', 'x-jwt-token': `Bearer ${AppStorage.get('x-jwt-token')}` },
@@ -183,7 +190,7 @@
   getCourseList() {
     let httpRequest = http.createHttp();
     httpRequest.request(
-      "http://192.168.20.70:8080/quiz-community/public/v1.0/home/courses",
+      `${DOMAIN}/quiz-community/public/v1.0/home/courses`,
       {
         method: http.RequestMethod.GET,
         header: { 'Content-Type': 'application/json', 'x-jwt-token': `Bearer ${AppStorage.get('x-jwt-token')}` },
@@ -194,7 +201,8 @@
         if (data.responseCode == 200) {
           const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<Course[]>
           if (resData.code == 200) {
-            this.courseList = resData.data || []
+            this.origCourseList = resData.data || []
+            this.filterCourseList()
           } else {
             promptAction.showToast({ message: resData.msg })
           }
@@ -331,12 +339,12 @@
                         router.pushUrl({
                           url: 'pages/home/ActiveDetail',
                           params: {
-                            index: index
+                            id: item.id
                           }
                         })
                       })
                     }
-                  }, (index: number) => index.toString())
+                  })
                 }
                 .listDirection(Axis.Vertical) // 鎺掑垪鏂瑰悜
                 .scrollBar(BarState.Off)
@@ -360,7 +368,7 @@
                   Image($r('app.media.search_icon'))
                     .width(14)
                     .height(14)
-                  TextInput({ placeholder: '鎼滅储鎯宠鏌ユ壘鐨勫唴瀹�' })
+                  TextInput({ placeholder: '鎼滅储鎯宠鏌ユ壘鐨勫唴瀹�', text: $$this.searchKeyword })
                     .placeholderFont({ size: 14})
                     .placeholderColor('#999999')
                     .backgroundColor('#f3f7fe')
@@ -404,7 +412,7 @@
                             }
                             Text() {
                               Span('璇剧▼闅惧害: ')
-                              Span(`${item.difficulty}`)
+                              Span(this.getDifficultText(item.difficulty))
                             }
                             .fontSize(10)
                             .fontColor('#666666')
@@ -429,15 +437,14 @@
                       .border({ width: 1, style: BorderStyle.Solid, color: '#f2f2f2' })
                       .borderRadius(10)
                     }
-                  }, (index: number) => index.toString())
+                  })
                 }
                 .listDirection(Axis.Vertical) // 鎺掑垪鏂瑰悜
                 .scrollBar(BarState.Off)
                 .friction(0.6)
                 .edgeEffect(EdgeEffect.Spring)
                 .width('100%')
-                .height(530)
-
+                .height(580)
               }
               .height('100%')
             }.tabBar(this.tabBarItem(item.title, index))

--
Gitblit v1.8.0