HarmonyOS NEXT 实战之元服务:静态案例效果---电动车电池健康状况

背景:

前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,里面丰富的内容大家自己加,本期案例 仅供参考

先上本期效果图 ,里面图片自行替换

效果图1完整代码案例如下:

复制代码
import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Image($r('app.media.diandongche')).width('60%')
        .height(200)
      Row() {
        Column({ space: 5 }) {
          Row() {
            Image($r('app.media.dianchi')).width(50).height(50)
            Text('50%').fontColor(Color.White).fontSize(20).fontWeight(FontWeight.Bold)
          }

          Image($r('app.media.diandongche')).width(80)
            .height(80)
        }
        .width('40%')
        .backgroundColor('#9571E9')
        .borderWidth(1)
        .borderColor('#FF7F00')
        .borderRadius(10)
        .padding(6)


        Row() {
          Column({ space: 5 }) {
            Image($r('app.media.dizhi')).width(50).height(50)
            Text('庞各庄地铁C口').fontColor(Color.Black).fontSize(12)
          }

          Column({ space: 5 }) {
            Image($r('app.media.xiang')).width(50).height(50)
            Text('响铃找车').fontColor(Color.Black).fontSize(12)
          }

        }
        .justifyContent(FlexAlign.SpaceBetween)
        .width('100%')
        .height(146)
        .backgroundColor('#70E07B')
        .borderWidth(1)
        .borderColor('#FF7F00')
        .borderRadius(10)
        .width('55%')
        .padding(6)

      }
      .justifyContent(FlexAlign.SpaceBetween)
      .width('100%')
      .margin({ top: 12 })
      .backgroundColor('#D8D8FB')
      .borderWidth(1)
      .borderColor('#FF7F00')
      .borderRadius(10)
      .padding(6)


      Row() {
        Column({ space: 5 }) {
          Text('450km').fontColor('#FF7F00').fontSize(18)
          Text('累计骑行')

        }


        Column({ space: 5 }) {
          Text('50km').fontColor('#FF7F00').fontSize(18)
          Text('预计续航')

        }
        Column({ space: 5 }) {
          Image($r('app.media.diandongche')).width(50).height(50)
          Text('VIP解锁更多功能')
        }

      }
      .justifyContent(FlexAlign.SpaceBetween)
      .width('100%')
      .margin({ top: 12 })
      .backgroundColor('#D8D8FB')
      .borderWidth(1)
      .borderColor('#FF7F00')
      .borderRadius(10)
      .padding(6)

    }
    .height('100%')
    .width('100%')
    .margin({ top: 60 })
    .padding(16)
  }

  aboutToAppear() {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    this.loginWithHuaweiID();
  }

  /**
   * Sample code for using HUAWEI ID to log in to atomic service.
   * According to the Atomic Service Review Guide, when a atomic service has an account system,
   * the option to log in with a HUAWEI ID must be provided.
   * The following presets the atomic service to use the HUAWEI ID silent login function.
   * To enable the atomic service to log in successfully using the HUAWEI ID, please refer
   * to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.
   */
  private loginWithHuaweiID() {
    // Create a login request and set parameters
    let loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();
    // Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI ID
    loginRequest.forceLogin = false;
    // Execute login request
    let controller = new authentication.AuthenticationController();
    controller.executeRequest(loginRequest).then((data) => {
      let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;
      let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;
      // Send authCode to the backend in exchange for unionID, session

    }).catch((error: BusinessError) => {
      hilog.error(0x0000, 'testTag', 'error: %{public}s', JSON.stringify(error));
      if (error.code == authentication.AuthenticationErrorCode.ACCOUNT_NOT_LOGGED_IN) {
        // HUAWEI ID is not logged in, it is recommended to jump to the login guide page

      }
    });
  }
}
相关推荐
爱笑的眼睛1117 分钟前
深入浅出 HarmonyOS ArkUI 3.0:基于声明式开发范式与高级状态管理构建高性能应用
华为·harmonyos
电手2 小时前
时隔4年麒麟重新登场!华为这8.8英寸新「手机」给我看麻了
华为·智能手机
程序员潘Sir3 小时前
鸿蒙应用开发从入门到实战(一):鸿蒙应用开发概述
harmonyos
敲代码的鱼哇7 小时前
跳转原生系统设置插件 支持安卓/iOS/鸿蒙UTS组件
android·ios·harmonyos
在下历飞雨7 小时前
Kuikly基础之状态管理与数据绑定:让“孤寡”计数器动起来
ios·harmonyos
在下历飞雨7 小时前
Kuikly基础之Kuikly DSL基础组件实战:构建青蛙主界面
ios·harmonyos
HarmonyOS小助手9 小时前
HEIF:更高质量、更小体积,开启 HarmonyOS 图像新体验
harmonyos·鸿蒙·鸿蒙生态
嘿嘿-g10 小时前
华为IP(9)
网络·华为
self_myth10 小时前
[特殊字符] 深入理解操作系统核心特性:从并发到分布式,从单核到多核的全面解析
windows·macos·wpf·harmonyos
安卓开发者19 小时前
鸿蒙NEXT主题设置指南:应用级与页面级主题定制详解
华为·harmonyos