From 7f2343d38fa048f6ce179ea0ab2c1a04f41a213c Mon Sep 17 00:00:00 2001 From: wwf <1971391498@qq.com> Date: 星期四, 09 十月 2025 18:05:11 +0800 Subject: [PATCH] 功能完善 --- entry/src/main/ets/pages/home/Home.ets | 311 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 269 insertions(+), 42 deletions(-) diff --git a/entry/src/main/ets/pages/home/Home.ets b/entry/src/main/ets/pages/home/Home.ets index 4f6cbe7..e97d195 100644 --- a/entry/src/main/ets/pages/home/Home.ets +++ b/entry/src/main/ets/pages/home/Home.ets @@ -1,16 +1,40 @@ +import { promptAction, router } from "@kit.ArkUI" +import http from '@ohos.net.http'; +import { HttpResponseResult } from "../../data/HttpResponse"; +import { JSON } from "@kit.ArkTS"; + class TabBarBase { title: string = '' } +class SwiperItem { + pic: string = '' + id: string = '' + sort: number = 0 +} + class Classification { title: string = '' + value: string = '' icon: ResourceStr = '' } class Activity { - title: string = '' - timeScope: string = '' - signupCount: number = 0 - statusText: string = '' + id: string = '' + name: string = '' + pic: string = '' + startDate: string = '' + endTime: string = '' + signupCount: string = '' + status: string = '' } +class Course { + name: string = '' + pic: string = '' + description: string = '' + playCount: number = 0 + duration: number = 0 + difficulty: number = 0 +} + @Entry @Component export struct Home { @@ -21,31 +45,40 @@ { title: '璇剧▼' } ] private tabController: TabsController = new TabsController() - @State swiperList: ResourceStr[] = [ - $r('app.media.image1'), - $r('app.media.image1'), - $r('app.media.image1'), - ] + @State swiperList: SwiperItem[] = [] @State swiperIndex: number = 0 //TabBar鏍峰紡 @State classificationList: Classification[] = [ - { title: '鏁伴��', icon: $r('app.media.classification_shutong') }, - { title: '瀹夊叏', icon: $r('app.media.classification_safety') }, - { title: '浜戣绠�', icon: $r('app.media.classification_cloudcalc') }, - { title: '瀛樺偍', icon: $r('app.media.classification_storage') }, - { title: '椴查箯', icon: $r('app.media.classification_roc') }, - { title: 'AI', icon: $r('app.media.classification_AI') }, - { title: '杩炴帴', icon: $r('app.media.classification_link') }, - { title: '澶ф暟鎹�', icon: $r('app.media.classification_bigdata') }, - { title: '浜戞湇鍔�', icon: $r('app.media.classification_cloudservice') }, - { title: '鏇村', icon: $r('app.media.classification_more') }, + { title: '鏁伴��', value: 'shutong', icon: $r('app.media.classification_shutong') }, + { title: '瀹夊叏', value: 'safety', icon: $r('app.media.classification_safety') }, + { title: '浜戣绠�', value: 'cloudcalc', icon: $r('app.media.classification_cloudcalc') }, + { title: '瀛樺偍', value: 'storage', icon: $r('app.media.classification_storage') }, + { title: '椴查箯', value: 'roc', icon: $r('app.media.classification_roc') }, + { title: 'AI', value: 'AI', icon: $r('app.media.classification_AI') }, + { title: '杩炴帴', value: 'link', icon: $r('app.media.classification_link') }, + { title: '澶ф暟鎹�', value: 'bigdata', icon: $r('app.media.classification_bigdata') }, + { title: '浜戞湇鍔�', value: 'cloudservice', icon: $r('app.media.classification_cloudservice') }, + { title: '鏇村', value: '', icon: $r('app.media.classification_more') }, ] - @State activityList: Activity[] = [ - { title: '鍖椾含浜哄伐鏅鸿兘IE', timeScope: '20250520-20250620', signupCount: 80, statusText: '鎶ュ悕涓�' }, - { title: '鍖椾含浜哄伐鏅鸿兘IE', timeScope: '20250520-20250620', signupCount: 80, statusText: '杩涜涓�' }, - { title: '鍖椾含浜哄伐鏅鸿兘IE', timeScope: '20250520-20250620', signupCount: 80, statusText: '宸茬粨鏉�' }, - { title: '鍖椾含浜哄伐鏅鸿兘IE', timeScope: '20250520-20250620', signupCount: 80, statusText: '鎶ュ悕涓�' }, - { title: '鍖椾含浜哄伐鏅鸿兘IE', timeScope: '20250520-20250620', signupCount: 80, statusText: '宸茬粨鏉�' }, + @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: '绠�鍗�' }, + ] @Builder tabBarItem(name:string,index: number){ @@ -64,24 +97,110 @@ getTagFontColor(statusText: string) { switch (statusText) { - case '鎶ュ悕涓�': + case 'signup': return '#10920e' - case '杩涜涓�': + case 'training': return '#ffa100' default : return '#666666' } } - getTagBgColor(statusText: string) { - switch (statusText) { - case '鎶ュ悕涓�': + getTagBgColor(status: string) { + switch (status) { + case 'signup': return '#d5f2db' - case '杩涜涓�': + case 'training': return '#fff0cc' default : return '#ebebeb' } + } + + getStatusText(status: string) { + if (status == 'signup') { + return '鎶ュ悕涓�' + } else if (status == 'training') { + return '杩涜涓�' + } else if (status == 'finished') { + return '宸茬粨鏉�' + } + return '' + } + + aboutToAppear(): void { + this.getBannerList() + this.getActivityList() + this.getCourseList() + } + + getBannerList() { + let httpRequest = http.createHttp(); + httpRequest.request( + "http://192.168.20.70:8080/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')}` }, + }, + (err, data) => { + console.log('response', '/home/slideshows') + console.log(JSON.stringify(data.result)) + if (data.responseCode == 200) { + const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<SwiperItem[]> + if (resData.code == 200) { + this.swiperList = resData.data || [] + } else { + promptAction.showToast({ message: resData.msg }) + } + } + } + ) + } + + getActivityList() { + let httpRequest = http.createHttp(); + httpRequest.request( + "http://192.168.20.70:8080/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')}` }, + }, + (err, data) => { + console.log('response', '/home/hotTraining') + console.log(JSON.stringify(data.result)) + if (data.responseCode == 200) { + const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<Activity[]> + if (resData.code == 200) { + this.activityList = resData.data || [] + } else { + promptAction.showToast({ message: resData.msg }) + } + } + } + ) + } + + getCourseList() { + let httpRequest = http.createHttp(); + httpRequest.request( + "http://192.168.20.70:8080/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')}` }, + }, + (err, data) => { + console.log('response', '/home/courses') + console.log(JSON.stringify(data.result)) + 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 || [] + } else { + promptAction.showToast({ message: resData.msg }) + } + } + } + ) } build() { @@ -94,15 +213,23 @@ Tabs({controller:this.tabController}){ ForEach(this.tabList, (item: TabBarBase, index: number) => { // 棣栭〉 ------------ - if (item.title == '棣栭〉') { + if (this.activeIndex == 0) { TabContent() { Column({ space: 10 }){ Swiper() { - ForEach(this.swiperList, (item: Resource) => { - Image(item) + ForEach(this.swiperList, (item: SwiperItem) => { + Image(item.pic) .width('100%') .height(120) .backgroundColor(0xAFEEEE) + .onClick(() => { + router.push({ + url: 'pages/home/BannerDetail', + params: { + bannerId: item.id + } + }) + }) }) } .borderRadius(10) @@ -131,6 +258,15 @@ .fontSize(12) .fontWeight(500) } + .onClick(() => { + if (!item.value) return + router.pushUrl({ + url: 'pages/home/ClassificationDetail', + params: { + moduleName: item.value + } + }) + }) } }) } @@ -157,14 +293,14 @@ ListItem() { Row() { Column({ space: 6 }) { - Text(item.title) + Text(item.name) .fontSize(12) .fontWeight(500) Row() { Image($r('app.media.date_icon')) .width(12) .height(12) - Text(item.timeScope) + Text(`${item.startDate}-${item.endTime}`) .fontSize(10) .fontColor('#676767') .margin({ left: 4 }) @@ -172,13 +308,13 @@ Text(`${item.signupCount || 0}浜哄凡鎶ュ悕`) .fontSize(10) .fontColor('#676767') - Text(item.statusText) + Text(this.getStatusText(item.status)) .fontSize(10) .fontWeight(500) .padding(6) .borderRadius(10) - .fontColor(this.getTagFontColor(item.statusText)) - .backgroundColor(this.getTagBgColor(item.statusText)) + .fontColor(this.getTagFontColor(item.status)) + .backgroundColor(this.getTagBgColor(item.status)) } .height('100%') .justifyContent(FlexAlign.Start) @@ -191,6 +327,14 @@ .height(100) .padding(10) .justifyContent(FlexAlign.SpaceBetween) + .onClick(() => { + router.pushUrl({ + url: 'pages/home/ActiveDetail', + params: { + index: index + } + }) + }) } }, (index: number) => index.toString()) } @@ -200,7 +344,7 @@ .divider({ strokeWidth: 1, color: '#e8e8e8' }) // 姣忚涔嬮棿鐨勫垎鐣岀嚎 .edgeEffect(EdgeEffect.Spring) .width('100%') - .height(300) + .height(360) } .height('100%') } @@ -209,10 +353,93 @@ } // 璇剧▼------------ - if (item.title == '璇剧▼') { + if (this.activeIndex == 1) { TabContent() { - Text('璇剧▼content') + Column({ space: 10 }) { + Row() { + Image($r('app.media.search_icon')) + .width(14) + .height(14) + TextInput({ placeholder: '鎼滅储鎯宠鏌ユ壘鐨勫唴瀹�' }) + .placeholderFont({ size: 14}) + .placeholderColor('#999999') + .backgroundColor('#f3f7fe') + } + .borderRadius(30) + .padding({ left: 20, right: 20 }) + .backgroundColor('#f3f7fe') + .width('100%') + List({ space: 10, initialIndex: 0 }) { + ForEach(this.courseList, (item: Course, index: number) => { + ListItem() { + Row({ space: 10 }) { + Column() { + Text(item.name) + .fontSize(14) + .fontWeight(800) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Text(item.description) + .fontSize(12) + .fontColor('#666666') + .maxLines(2) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Row() { + Row({ space: 2 }) { + Image($r('app.media.person_icon')) + .width(10) + .height(10) + Text(`${item.playCount}`) + .fontSize(10) + .fontColor('#666666') + } + Row({ space: 2 }) { + Image($r('app.media.video_icon')) + .width(10) + .height(10) + Text(`${item.duration}`) + .fontSize(10) + .fontColor('#666666') + } + Text() { + Span('璇剧▼闅惧害: ') + Span(`${item.difficulty}`) + } + .fontSize(10) + .fontColor('#666666') + } + .width('100%') + .justifyContent(FlexAlign.SpaceBetween) + } + .layoutWeight(0) + .width(170) + .height('100%') + .justifyContent(FlexAlign.SpaceBetween) + .alignItems(HorizontalAlign.Start) + Image($r('app.media.active_list_img')) + .aspectRatio(16/9) + .height('100%') + .layoutWeight(1) + } + .width('100%') + .height(100) + .padding(10) + .justifyContent(FlexAlign.SpaceBetween) + .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('100%') }.tabBar(this.tabBarItem(item.title, index)) } }) -- Gitblit v1.8.0