当前位置: 首页 > article >正文

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

      }
    });
  }
}

http://www.kler.cn/a/456525.html

相关文章:

  • 按照人们阅读Excel习惯来格式化BigDecimal
  • FOC控制原理-ADC采样时机
  • VITUREMEIG | AR眼镜 算力增程
  • STM32学习之 按键/光敏电阻 控制 LED/蜂鸣器
  • 如何修改pip全局缓存位置和全局安装包存放路径
  • 安装了python,环境变量也设置了,但是输入python不报错也没反应是为什么?window的锅!
  • Linux第99步_Linux之点亮LCD
  • MySQL和HBase的对比
  • ubuntu虚拟机中搭建python开发环境
  • Yocto 项目 - 共享状态缓存 (Shared State Cache) 机制
  • STM32 + 移远EC800 4G通信模块数传
  • 数据可视化-16. 日历图
  • java根据Word模板实现动态填充导出
  • 【阅读记录-章节7】Build a Large Language Model (From Scratch)
  • 基于submitit实现Python函数的集群计算
  • 【计组】例题课后题
  • AduSkin、WPF-UI、Prism:WPF 框架全解析与应用指南
  • 使用 OpenCV 绘制线条和矩形
  • 导师让你给实验室搭服务器?不会?我教你
  • jangow-01-1.0.1
  • Java 中 Stream 流的使用详解
  • Linux下shell基本命令之vi用法及示例
  • AI for Science
  • 如何在鸿蒙本地模拟器中使用HDC工具
  • JAVA学习笔记第二阶段开始 Day11 五种机制---机制1:泛型机制
  • Java和Go语言的优劣势对比