class TabBarBase {
|
title: string = ''
|
}
|
class Classification {
|
title: string = ''
|
icon: ResourceStr = ''
|
}
|
class Activity {
|
title: string = ''
|
timeScope: string = ''
|
signupCount: number = 0
|
statusText: string = ''
|
}
|
@Entry
|
@Component
|
export struct Home {
|
@State pageHeight: number = 0
|
@State activeIndex:number = 0
|
@State tabList: TabBarBase[] = [
|
{ title: '首页' },
|
{ title: '课程' }
|
]
|
private tabController: TabsController = new TabsController()
|
@State swiperList: ResourceStr[] = [
|
$r('app.media.image1'),
|
$r('app.media.image1'),
|
$r('app.media.image1'),
|
]
|
@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') },
|
]
|
@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: '已结束' },
|
]
|
|
@Builder tabBarItem(name:string,index: number){
|
Row(){
|
Text(name)
|
.fontSize(this.activeIndex == index ? 16 : 14)
|
.fontWeight(700)
|
.fontColor(this.activeIndex == index ? '#1756f4' : '#666666')
|
.margin(index == 0 ? { left: '50%' } : { right: '50%' } )
|
}
|
.onClick(() => {
|
this.activeIndex = index
|
this.tabController.changeIndex(index)
|
})
|
}
|
|
getTagFontColor(statusText: string) {
|
switch (statusText) {
|
case '报名中':
|
return '#10920e'
|
case '进行中':
|
return '#ffa100'
|
default :
|
return '#666666'
|
}
|
}
|
|
getTagBgColor(statusText: string) {
|
switch (statusText) {
|
case '报名中':
|
return '#d5f2db'
|
case '进行中':
|
return '#fff0cc'
|
default :
|
return '#ebebeb'
|
}
|
}
|
|
build() {
|
Column() {
|
Text('鸿蒙实训首页')
|
.width('100%')
|
.textAlign(TextAlign.Center)
|
.fontWeight(800)
|
.fontSize(18)
|
Tabs({controller:this.tabController}){
|
ForEach(this.tabList, (item: TabBarBase, index: number) => {
|
// 首页 ------------
|
if (item.title == '首页') {
|
TabContent() {
|
Column({ space: 10 }){
|
Swiper() {
|
ForEach(this.swiperList, (item: Resource) => {
|
Image(item)
|
.width('100%')
|
.height(120)
|
.backgroundColor(0xAFEEEE)
|
})
|
}
|
.borderRadius(10)
|
.interval(3000)
|
.autoPlay(true)
|
.indicator(
|
Indicator.dot()
|
.itemWidth(8)
|
.itemHeight(8)
|
.selectedItemWidth(16)
|
.selectedItemHeight(8)
|
.color(Color.White)
|
)
|
.onChange((index) => {
|
this.swiperIndex = index;
|
})
|
|
Grid() {
|
ForEach(this.classificationList, (item: Classification ) => {
|
GridItem() {
|
Column({ space: 6 }) {
|
Image(item.icon)
|
.width(26)
|
.height(26)
|
Text(item.title)
|
.fontSize(12)
|
.fontWeight(500)
|
}
|
}
|
})
|
}
|
.columnsTemplate('1fr 1fr 1fr 1fr 1fr')
|
.columnsGap(14)
|
.rowsGap(14)
|
.width('100%')
|
.height(110)
|
|
Row() {
|
Image($r('app.media.title_decoration_icon'))
|
.width(4)
|
Text('热门培训')
|
.margin({ left: 8 })
|
.fontSize(16)
|
.fontWeight(700)
|
|
}
|
.alignItems(VerticalAlign.Center)
|
.width('100%')
|
|
List({ space: 10, initialIndex: 0 }) {
|
ForEach(this.activityList, (item: Activity, index: number) => {
|
ListItem() {
|
Row() {
|
Column({ space: 6 }) {
|
Text(item.title)
|
.fontSize(12)
|
.fontWeight(500)
|
Row() {
|
Image($r('app.media.date_icon'))
|
.width(12)
|
.height(12)
|
Text(item.timeScope)
|
.fontSize(10)
|
.fontColor('#676767')
|
.margin({ left: 4 })
|
}
|
Text(`${item.signupCount || 0}人已报名`)
|
.fontSize(10)
|
.fontColor('#676767')
|
Text(item.statusText)
|
.fontSize(10)
|
.fontWeight(500)
|
.padding(6)
|
.borderRadius(10)
|
.fontColor(this.getTagFontColor(item.statusText))
|
.backgroundColor(this.getTagBgColor(item.statusText))
|
}
|
.height('100%')
|
.justifyContent(FlexAlign.Start)
|
.alignItems(HorizontalAlign.Start)
|
Image($r('app.media.active_list_img'))
|
.aspectRatio(16/9)
|
.height('100%')
|
}
|
.width('100%')
|
.height(100)
|
.padding(10)
|
.justifyContent(FlexAlign.SpaceBetween)
|
}
|
}, (index: number) => index.toString())
|
}
|
.listDirection(Axis.Vertical) // 排列方向
|
.scrollBar(BarState.Off)
|
.friction(0.6)
|
.divider({ strokeWidth: 1, color: '#e8e8e8' }) // 每行之间的分界线
|
.edgeEffect(EdgeEffect.Spring)
|
.width('100%')
|
.height(300)
|
}
|
.height('100%')
|
}
|
.tabBar(this.tabBarItem(item.title, index))
|
.height('100%')
|
}
|
|
// 课程------------
|
if (item.title == '课程') {
|
TabContent() {
|
Text('课程content')
|
|
}.tabBar(this.tabBarItem(item.title, index))
|
}
|
})
|
}
|
.barHeight(40)
|
.margin({ top: 6 })
|
.width('100%')
|
.height('100%')
|
.padding({ left: 14, right: 14, bottom: 14 })
|
.onChange((index: number) => {
|
this.activeIndex = index
|
})
|
}
|
.width('100%')
|
.height('100%')
|
|
}
|
}
|