HarmonyOS Next 办公应用:信息展示页面的开发实现(二)

3. 主要业务功能区域构建

buildMainBusiness 方法构建主要业务功能区域,使用 ForEach 动态渲染多个业务功能项。点击不同的业务功能项会触发不同的操作,如点击第二个功能项会调用 call.makeCall 进行拨打电话。

typescript 复制代码
@Builder
buildMainBusiness() {
  Row() {
    ForEach( HomeViewModel.getMainBusinessBuild(), (item: BusinessInfo,index: number) => {
      Column() {
        Image(item.icon)
          .width(24)
          .height(24)
          .margin({bottom: 3})
        Text(item.text)
          .fontSize(14)
          .fontColor(Color.White)
      }
      .onClick(()=> {
        if (index===1) {
          call.makeCall((this.phone).toString(), (err: BusinessError) => {});
        } else {
          promptAction.showToast({
            message: '可自行添加模板',
            duration: AppStorage.get('dialogTime')
          });
        }
      })
    }, (item: BusinessInfo, index: number) => index + JSON.stringify(item))
  }
  .justifyContent(FlexAlign.SpaceEvenly)
  .margin({top: 10})
  .padding({top:5, bottom:5})
  .width('100%')
  .backgroundColor($r('app.color.liabilities_title'))
}
4. 样式扩展

通过 @Extend 装饰器扩展 RowColumnText 组件的样式,提高代码的复用性。

typescript 复制代码
@Extend(Row) function rowStyle(){
  .margin({top:5,bottom:5})
  .padding({top: 5, right: 30,bottom: 5, left: 10})
}
@Extend(Column) function columnStyle(){
  .margin({top:5,bottom:5})
}
@Extend(Text) function textStyle(){
  .fontColor($r('app.color.tab_un_image'))
  .fontSize(12)
}

总结

通过上述核心代码,我们在 HarmonyOS Next 中成功构建了一个信息展示页面。该页面利用 @Consume 装饰器实现页面导航,在 onReady 中获取并解析导航参数以初始化用户信息。使用 ForEach 动态渲染业务功能项,支持点击操作进行拨打电话等功能。同时,通过 @Extend 装饰器扩展组件样式,提高了代码的复用性。开发者可以根据实际需求进一步扩展和优化该页面,如增加更多的业务功能项、完善信息展示内容等,以满足更多办公场景的需求。

相关推荐
ZZZMMM.zip2 小时前
基于鸿蒙HarmonyOS NEXT开发AI英语口语应用:智能口语练习新体验与鸿蒙Flutter框架跨端实
人工智能·flutter·华为·harmonyos·鸿蒙·鸿蒙系统
心中有国也有家2 小时前
AtomGit Flutter 鸿蒙客户端:白噪音场景的视觉设计
学习·flutter·华为·harmonyos
心中有国也有家3 小时前
AtomGit Flutter 鸿蒙客户端:呼吸练习的完整生命周期
学习·flutter·华为·harmonyos
绝世番茄4 小时前
登录表单布局:从 Column 到完整表单 —— 鸿蒙 HarmonyOS ArkTS 原生学习指南
华为·list·harmonyos·鸿蒙
不才难以繁此生4 小时前
HarmonyOS ArkTS 实战|中式美食用户行为数据:Preferences 持久化、搜索缺口与候选排序
harmonyos·arkts·用户行为分析·preferences·中式美食·arkui v2
智塑未来4 小时前
鸿蒙系统对比安卓、iOS,核心优势是什么?
android·ios·harmonyos
心中有国也有家5 小时前
AtomGit Flutter 鸿蒙客户端:呼吸球动画
学习·flutter·华为·harmonyos
ZZZMMM.zip5 小时前
信息压缩站-长文智能摘要的HarmonyOS开发实践
人工智能·华为·harmonyos·鸿蒙·鸿蒙系统
绝世番茄6 小时前
VisualEffect 视觉特效鸿蒙HarmonyOS ArkTS原生学习
学习·华为·harmonyos·鸿蒙
爱吃大芒果6 小时前
领域驱动视角下的情绪追踪底座:打造高内聚、零耦合的鸿蒙应用模型
华为·harmonyos