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

      }
    });
  }
}
相关推荐
免费gpt4分享15 分钟前
我主动放弃了一半用户,只为了给剩下的人做一个95分的功能
harmonyos
世人万千丶2 小时前
鸿蒙 PC 避坑:DevEco Studio运行hdc命令执行异常完全指南
华为·开源·harmonyos·鸿蒙·鸿蒙系统
Latte Moments开发2 小时前
Harmony鸿蒙6.0实战开发项目--鸿蒙记账本(登录、注册、记账、图表)【代码在文末】
华为·harmonyos
Swift社区2 小时前
鸿蒙 App 集成 AI 助手:架构设计 + 实战代码
人工智能·华为·harmonyos
Dream-Y.ocean3 小时前
鸿蒙PC平台 Carnac 按键显示适配实战:从 Windows 到 HarmonyOS 的 Electron 迁移指南
windows·electron·harmonyos
●VON3 小时前
AtomGit Flutter鸿蒙客户端:仓库详情页
flutter·华为·跨平台·harmonyos·鸿蒙
小雨青年3 小时前
鸿蒙 HarmonyOS 6 | Pura X Max 鸿蒙原生适配 19:设置页在 Pura X Max 上改成分组布局
华为·harmonyos
浮芷.4 小时前
鸿蒙PC端 TTS 并发调用问题详解:资源竞争与队列管理
算法·华为·开源·harmonyos·鸿蒙·鸿蒙系统
nashane4 小时前
HarmonyOS 6学习:句柄泄漏(Fd Leak)从“崩溃现场”到“代码行”的精准狙击指南
学习·华为·音视频·harmonyos
坚果派·白晓明4 小时前
[鸿蒙PC三方库移植适配] 使用 AtomCode + Skills 自动完成Protobuf鸿蒙化适配
c语言·c++·华为·harmonyos