HarmonyOS NEXT 实战之元服务:静态案例效果---电动车助手

背景:

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

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

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

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

@Entry
@ComponentV2
struct Index {


  build() {
    Column() {
      Image($r('app.media.diandongche')).width('100%')
        .height(300)

      Row() {
        Column({ space: 5 }) {
          Image($r('app.media.dizhi')).width(50).height(50)
          Text('中关村一号')
        }
        .backgroundColor('#D8D8FB')
        .borderWidth(1)
        .borderColor('#FF7F00')
        .borderRadius(10)
        .width('49%')
        .padding(6)

        Column({ space: 5 }) {
          Image($r('app.media.xiangling')).width(50).height(50)
          Text('响铃找车')
        }
        .backgroundColor('#D8D8FB')
        .borderWidth(1)
        .borderColor('#FF7F00')
        .borderRadius(10)
        .width('49%')
        .padding(6)
      }.justifyContent(FlexAlign.SpaceBetween).width('100%')

      Row() {
        Column({ space: 5 }) {
          Image($r('app.media.shezhi')).width(50).height(50)
          Text('车辆设置')
        }
        .backgroundColor('#D8D8FB')
        .borderWidth(1)
        .borderColor('#FF7F00')
        .borderRadius(10)
        .width('49%')
        .padding(6)

        Column({ space: 5 }) {
          Image($r('app.media.diandongche')).width(50).height(50)
          Text('VIP解锁更多功能')
        }
        .backgroundColor('#D8D8FB')
        .borderWidth(1)
        .borderColor('#FF7F00')
        .borderRadius(10)
        .width('49%')
        .padding(6)
      }.justifyContent(FlexAlign.SpaceBetween).width('100%').margin({ top: 12 })


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


        Column({ space: 5 }) {
          Text('剩余里程')
          Text('50km').fontColor('#FF7F00').fontSize(18)
        }
      }
      .justifyContent(FlexAlign.SpaceBetween)
      .width('100%')
      .height(80)
      .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

      }
    });
  }
}
相关推荐
程序猿追6 小时前
HarmonyOS 7 阅读页换一套配色后怎样记住上次选择
华为·harmonyos
程序猿追7 小时前
HarmonyOS 7 本机书签里,两篇同名文章怎样在重启后各自打开
大数据·数据分析·harmonyos
程序猿追7 小时前
HarmonyOS 7 待办桌面卡片,划掉一项后谁来更新桌面
华为·harmonyos
默 语7 小时前
HarmonyOS7 组件通用事件(三):onAreaChange 区域变化事件——位置动了它知道,offset 动了它装没看见
harmonyos
钉先生贾8 小时前
HarmonyOS 7.0 工程升级实战 49:发布候选与正式配置分叉时,怎样保证可逆回退
华为·harmonyos
OH_TPC10 小时前
@ohos/grpc 源码解读(一):一次 RPC 调用的三层之旅——ArkTS、NAPI 与 nghttp2 帧处理全链路
harmonyos
NJPJI_Yang10 小时前
鸿蒙操作系统使用 Navigation 实现页面路由与栈管理实战(本文已在AtomGit仓库开源)
华为·开源·harmonyos
程序猿追11 小时前
HarmonyOS 7 饮水倒计时归零以后,怎样核对系统收到提醒
华为·harmonyos
黑臂麒麟11 小时前
【鸿蒙心迹】React Native 鸿蒙平板形态适配实战:键盘避让、挖孔安全区与主从栏切换
react native·harmonyos·响应式设计·平板·rnon
黑臂麒麟11 小时前
React Native 鸿蒙升级 RNOH 0.84 实战:TurboModule 注册方式怎么迁
react native·harmonyos·rnoh·turbomodule