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

相关推荐
No Silver Bullet42 分钟前
HarmonyOS NEXT开发进阶(十四):HarmonyOS应用开发者基础认证试题集汇总及答案解析
华为·harmonyos
鸿蒙布道师11 小时前
鸿蒙NEXT开发Base64工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
The 旺12 小时前
《HarmonyOS Next开发实战:从零构建响应式Todo应用的基石》
华为·harmonyos
Industio_触觉智能12 小时前
鸿蒙北向开发OpenHarmony5.0 DevEco Studio开发工具安装与配置
harmonyos·鸿蒙系统·openharmony·开源鸿蒙·鸿蒙开发·嵌入式开发板
秋叶先生_17 小时前
HarmonyOS NEXT——【鸿蒙监听网络状态变化】
华为·harmonyos·鸿蒙
东林知识库17 小时前
鸿蒙NEXT小游戏开发:围住神经猫
harmonyos
zacksleo17 小时前
鸿蒙Flutter开发故事:不,你不需要鸿蒙化
flutter·harmonyos
别说我什么都不会19 小时前
OpenHarmony解读之设备认证:sts协议-客户端发起sts end请求
物联网·嵌入式·harmonyos
悬空八只脚1 天前
React-Native开发鸿蒙NEXT-本地与沙盒加载bundle
harmonyos
鸿蒙布道师1 天前
鸿蒙NEXT开发日志工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei