From 23fa268f56dcd99c8dcd46f50f3ffcaa4cdcbc49 Mon Sep 17 00:00:00 2001 From: wwf <1971391498@qq.com> Date: 星期五, 10 十月 2025 17:25:53 +0800 Subject: [PATCH] 功能完善 --- entry/src/main/ets/pages/home/Home.ets | 63 +++++++++++++++++-------------- 1 files changed, 35 insertions(+), 28 deletions(-) diff --git a/entry/src/main/ets/pages/home/Home.ets b/entry/src/main/ets/pages/home/Home.ets index e97d195..6a3bf19 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 { ROMAIN } 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", + `${ROMAIN}/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", + `${ROMAIN}/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", + `${ROMAIN}/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,7 +339,7 @@ router.pushUrl({ url: 'pages/home/ActiveDetail', params: { - index: index + id: item.id } }) }) @@ -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') @@ -436,8 +444,7 @@ .friction(0.6) .edgeEffect(EdgeEffect.Spring) .width('100%') - .height(530) - + .height(580) } .height('100%') }.tabBar(this.tabBarItem(item.title, index)) -- Gitblit v1.8.0