wwf
2025-10-01 1ce875be27d9011c3944c6b975d9f817947ecdf8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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%')
 
  }
}