实现课程安排模板鸿蒙示例代码

鸿蒙场景化示例代码技术工程师
发布于 2025-3-11 19:08
935浏览
0收藏

本文原创发布在华为开发者社区

介绍

本示例基于Tabs容器组件、Scroll组件、Grid组件实现了上课模块的排版、下半部分使用List组件实现了第一天、第二天的任务列表、班级群界面中使用List组件实现消息的通知。

实现课程安排模板源码链接

效果预览

实现课程安排模板鸿蒙示例代码-鸿蒙开发者社区

使用说明

如果在运行该示例代码时,出现运行不了的情况,可尝试选择DevEco Studio菜单栏Build里面的Clean Project选项,来清理工程。

实现思路

  1. 上课模块的排版
 // popup构造器定义弹框内容
@Builder popupBuilder() {
  Column() {
    ForEach(selectedList, (model: typeModel,index:number) => {
      ListItem() {
        TypeCell({ model:model,index:index,selectedBlock:(selectedIndex:number) => {
          console.log('selectedIndex = ' + selectedIndex)
          for (let i = 0; i < selectedList.length; i++) {
            let item = selectedList[i]
            item.isSelected = selectedIndex === i ? true : false
            if (selectedIndex === i) {
              this.type = item.type
              this.title = item.content
              this.study = item.study
            }
          }
          this.customPopup = false
        }})
      }
    })
  }
  .width('100%')
}

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  1. List组件实现了第一天、第二天的任务列表
 @Builder
  listBuilder(index:number) {
    List({scroller: this.scrollerForList }) {
      if (this.selectedIndex === 0) {
        ForEach(ItemList1, (model: itemModel,index:number) => {
          ListItem() {
            ListCell1({ model:model,type:1 })
          }
        }, (index: number) => JSON.stringify(index))
      }else if (this.selectedIndex === 1) {
        ForEach(ItemList2, (model: listModel,index:number) => {
          ListItem() {
            ListCell2({ model:model })
          }
        }, (index: number) => JSON.stringify(index))
      }else  {
        ForEach(ItemList3, (model: itemModel,index:number) => {
          ListItem() {
            ListCell1({ model:model,type:2  })
          }
        }, (index: number) => JSON.stringify(index))
      }
    }
    .nestedScroll({
      scrollForward: NestedScrollMode.PARENT_FIRST,
      scrollBackward: NestedScrollMode.SELF_FIRST
    })
    .edgeEffect(EdgeEffect.None)
    .friction(0.6)
    .height('calc(100% - 50vp)') // 滚动到scroll area还剩50时 就定格了
    .backgroundColor('#f5f5f5')
  }
  • 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.

分类
收藏
回复
举报


回复
    相关推荐