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 装饰器扩展组件样式,提高了代码的复用性。开发者可以根据实际需求进一步扩展和优化该页面,如增加更多的业务功能项、完善信息展示内容等,以满足更多办公场景的需求。

相关推荐
Jackson_Li42 分钟前
鸿蒙 Tab 中的 WebView 如何优雅地拦截侧滑返回?
harmonyos
0xCode 小新1 小时前
【鸿蒙心迹】参加ICT大赛对我的影响和帮助
harmonyos
程序员潘Sir2 小时前
鸿蒙应用开发从入门到实战(十八):组件编程思想之代码复用
harmonyos·鸿蒙
安卓开发者1 天前
鸿蒙NEXT跨设备通信:掌握URPC,实现远程程序调用
华为·harmonyos
程序员潘Sir1 天前
鸿蒙应用开发从入门到实战(十七):ArkUI组件List&列表布局
harmonyos·鸿蒙
bst@微胖子1 天前
鸿蒙实现滴滴出行项目之侧边抽屉栏以及权限以及搜索定位功能
android·华为·harmonyos
爱笑的眼睛112 天前
深入浅出 HarmonyOS 应用开发:ArkTS 语法精要与实践
华为·harmonyos
爱笑的眼睛112 天前
HarmonyOS应用开发深度解析:ArkTS语法精要与UI组件实践
华为·harmonyos