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 装饰器扩展 Row、Column 和 Text 组件的样式,提高代码的复用性。

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

相关推荐
熊猫钓鱼>_>2 小时前
从零手写 2048:HarmonyOS ArkTS 声明式游戏的工程化实战【鸿蒙心迹】
华为·ai·华为云·ai编程·harmonyos·openharmony·鸿蒙心迹
程序猿追7 小时前
HarmonyOS 7 月历翻页后,月底的便签该跟哪一天
harmonyos
程序猿追7 小时前
HarmonyOS 7 ArkUI 四则计算器:优先级、括号与除零修正
华为·harmonyos
leon_teacher9 小时前
HarmonyOS 7 Health Service Kit 实战:打通手表健康数据授权
华为·harmonyos
NJPJI_Yang10 小时前
鸿蒙操作系统使用 Gesture 实现手势识别与冲突处理实战(本文已在AtomGit仓库开源)
华为·开源·harmonyos
程序猿追11 小时前
HarmonyOS 7 模拟时钟的秒针怎样跨过 12 点
harmonyos
黑臂麒麟14 小时前
React Native 鸿蒙安全存储实战(下):HUKS 密钥托管的加解密与签名验签,四个真机差异实录
安全·react native·harmonyos·加密
程序猿追14 小时前
HarmonyOS 7 ArkUI 新闻阅读器:返回列表与再次打开时,怎样接上阅读位置
harmonyos
ovenslove17 小时前
网络请求:@ohos.net.http 从零封装到可用
harmonyos·arkts