HarmonyOS Next 办公应用:邮件详情页的开发实现(二)

3. 自定义弹窗控制器

使用 CustomDialogController 创建自定义弹窗,用于展示更多操作选项。

typescript 复制代码
//自定义弹窗
dialogController: CustomDialogController | null = new CustomDialogController({
  builder: BottomDialog({}),
  autoCancel: true,
  offset: { dx: 0, dy: 0 },
  customStyle: true,
  alignment: DialogAlignment.Bottom,
})
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
  this.dialogController = null
}
4. 底部操作按钮构建器

bottomItem 方法用于构建底部操作按钮,点击按钮会触发相应的操作并显示提示信息。

typescript 复制代码
//底部按钮
@Builder
bottomItem(image:string,title:string,btnClick?:(()=>void)) {
  Column(){
    Image($r(image))
      .width(20)
      .height(20)
      .margin({top:5,bottom:5})
    Text(title)
      .fontColor(Color.Gray)
      .fontSize(13)
      .margin({bottom:5})
  }
  .onClick(()=>{
    if(btnClick) {
      btnClick()
    }
    promptAction.showToast({
      message: '可自行添加模板',
      duration: AppStorage.get('dialogTime')
    });
  })
  .width('25%')
}
5. 页面构建与数据获取

build 方法构建整个邮件详情页面,包括头部导航、邮件详细信息展示和底部操作按钮。在 onReady 生命周期函数中获取导航传递的邮件信息。

typescript 复制代码
build() {
  NavDestination(){
    Column() {
      Column() {
        //头部
        EmailDetailNavHeader('详情',this.pageInfos)

        Scroll() {
          Column(){
            // 显示邮件时间
            Row(){
              Text(this.infoList.getData(this.index).time)
                .fontSize(12)
                .fontColor(Color.Gray)
                .width('100%')
                .layoutWeight(1)
                .margin({left:$r('app.float.padding'),right:$r('app.float.padding'),top:$r('app.float.padding')})
            }
            // 显示发件人信息
            Flex({justifyContent:FlexAlign.SpaceBetween}) {
              Row(){
                Text('发件人:')
                  .fontSize(12)
                  .fontColor(Color.Gray)
                  .margin({left:$r('app.float.padding'),right:$r('app.float.padding'),top:$r('app.float.padding')})
                Text(' '+this.infoList.getData(this.index).sender+' ')
                  .height(20)
                  .borderRadius(3)
                  .backgroundColor('#efefef')
              }
              Text('展开')
                .fontColor('#1296db')
                .margin({right:$r('app.float.padding')})
            }
            // 显示收件人信息
            Flex({justifyContent:FlexAlign.SpaceBetween}) {
              Row(){
                Text('收件人:')
                  .fontSize(12)
                  .fontColor(Color.Gray)
                  .margin({left:$r('app.float.padding'),right:$r('app.float.padding')})
                Text(' '+'menghaoran'+' ')
                  .height(20)
                  .borderRadius(3)
                  .backgroundColor('#efefef')
              }
              Text('10人未显示')
                .fontColor('#dddddd')
                .fontSize(12)
                .margin({right:$r('app.float.padding')})
            }
            .margin({top:$r('app.float.padding')})
            // 显示邮件内容
            Row() {
              Text(this.infoList.getData(this.index).content)
            }
            .width('100%')
            .margin({top:$r('app.float.padding')})
            .padding({left:$r('app.float.margin'),right:$r('app.float.margin')})
          }
        }
      }
      .layoutWeight(1)

      Flex(){
        ForEach(this.itemList,(item:ItemInfo,index:number)=>{
          this.bottomItem(item.image,item.title,()=>{
              if(index===3) {
                if (this.dialogController != null) {
                  this.dialogController.open()
                }
              }
          })
        })
      }
      .backgroundColor('#ececec')
      .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
    }
    .width('100%')
    .height('100%')
  }
  .hideTitleBar(true)
  .onReady((ctx: NavDestinationContext) => {
    // 在NavDestination中能够拿到传来的NavPathInfo和当前所处的NavPathStack
    try {
      this.infoList = (ctx?.pathInfo?.param as EmailInfoParam).infoList;
      this.index = (ctx?.pathInfo?.param as EmailInfoParam).index;
    } catch (e) {
      hilog.error(0x0001, 'showToast error: %{public}s ', JSON.stringify(e));
    }
  })
}

总结

通过上述核心代码,我们在 HarmonyOS Next 中成功构建了一个邮件详情页面。该页面利用 LazyDataSource 管理邮件信息,使用 CustomDialogController 实现自定义弹窗,通过 ForEach 动态渲染底部操作按钮。同时,在 onReady 生命周期函数中获取导航传递的邮件信息,实现了邮件详细信息的展示和底部操作按钮的交互。开发者可以根据实际需求进一步扩展和优化该页面,如完善底部操作按钮的具体功能、优化邮件信息展示样式等,以满足更多办公场景的需求。

相关推荐
小雨下雨的雨42 分钟前
Flutter鸿蒙共赢——墨染算法:柏林噪声与鸿蒙生态中的数字水墨意境
算法·flutter·华为·交互·harmonyos·鸿蒙
奋斗的小青年!!3 小时前
鸿蒙使用Flutter粒子效果实战
flutter·harmonyos·鸿蒙
AlbertZein6 小时前
HarmonyOS下饭菜时间 -- @Monitor
harmonyos
AlbertZein6 小时前
HarmonyOS一杯冰美式的时间 -- UIUtils基础功能
harmonyos
行者968 小时前
Flutter与OpenHarmony跨平台分享组件深度实践
flutter·harmonyos·鸿蒙
行者968 小时前
Flutter跨平台开发在OpenHarmony上的评分组件实现与优化
开发语言·flutter·harmonyos·鸿蒙
90后的晨仔10 小时前
HarmonyOS 多模块项目中的公共库治理与最佳实践
harmonyos
lili-felicity13 小时前
React Native 鸿蒙跨平台开发:LayoutAnimation 实现鸿蒙端按钮点击的缩放反馈动画
react native·react.js·harmonyos
哈__15 小时前
React Native 鸿蒙跨平台开发:Dimensions 屏幕尺寸获取
react native·华为·harmonyos
奋斗的小青年!!16 小时前
Flutter跨平台开发适配OpenHarmony:手势识别实战应用
flutter·harmonyos·鸿蒙