HarmonyOS NEXT 实战之元服务:静态案例效果---咖啡制作实况窗

背景:

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

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

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

import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Entry
@ComponentV2
struct Index {


  build() {
    Column() {


      Column() {
        Row() {
          Row() {
            Image($r('app.media.kefei')).width(50).height(50)
            Column({ space: 4 }) {
              Text('制作完成').fontColor(Color.White).fontSize(18)
              Text('冰美式 | 中关村店铺').fontColor(Color.White)
            }.alignItems(HorizontalAlign.Start).margin({ left: 6 })
          }

          Button('取餐码')


        }.width('100%').justifyContent(FlexAlign.SpaceBetween)

        Row() {
          Column({ space: 4 }) {
            Text('取餐号:').fontSize(16).fontColor(Color.White)
            Text('1236').fontSize(24).fontColor(Color.White).fontWeight(FontWeight.Bold)
          }.alignItems(HorizontalAlign.Start).margin({ left: 6 })

          Image($r('app.media.img')).width(70).height(70).borderRadius(8)
        }.width('100%').justifyContent(FlexAlign.SpaceBetween).margin({ top: 28 })

      }
      .height(180)
      .margin({ top: 60, left: 8 })
      .padding(16)
      .width('96%')

      .backgroundColor('#816A66')
      .borderRadius(12)


      Row() {

        Text('订单号:').fontSize(16).fontColor(Color.White)
        Text('12364946145641').fontSize(19).fontColor(Color.Black).fontWeight(FontWeight.Bold)

      }
      .width('100%')
      .height(54)
      .padding(5)
      .borderRadius(10)
      .justifyContent(FlexAlign.SpaceBetween)
      .margin({ top: 28, left: 8 })
      .backgroundColor('#837D79')

      Row() {

        Text('制作完成时间:').fontSize(16).fontColor(Color.White)
        Text(this.getDate()).fontSize(19).fontColor(Color.Black).fontWeight(FontWeight.Bold)

      }
      .width('100%')
      .height(54)
      .padding(5)
      .borderRadius(10)
      .justifyContent(FlexAlign.SpaceBetween)
      .margin({ top: 1, left: 8 })
      .backgroundColor('#9EC1D4')
    }.width('96%').height('100%')
  }

  private getDate(): string {
    const now = new Date();

    const year = now.getFullYear(); // 获取年份
    const month = now.getMonth() + 1; // 获取月份,注意月份是从0开始的,所以需要加1
    const day = now.getDate(); // 获取日期
    const hour = now.getHours(); // 获取小时
    const minute = now.getMinutes(); // 获取分钟
    return `${year}-${month}-${day} ${hour}:${minute}`


  }

  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

      }
    });
  }
}
相关推荐
VVVVWeiYee2 小时前
ISIS(中间系统到中间系统)——基础
运维·网络·华为·信息与通信
谢宁华为战略管理研发管理3 小时前
华为对流程认知的三个层次(重新认识流程)
华为
坚果的博客4 小时前
开发 picgo-plugin-huawei 插件,解决华为云社区外链限制问题
华为·华为云
塞尔维亚大汉4 小时前
OpenHarmony(鸿蒙南向)——平台驱动指南【HDMI】
harmonyos·领域驱动设计
行十万里人生8 小时前
Qt 对象树详解:从原理到运用
开发语言·数据库·qt·华为od·华为·华为云·harmonyos
ax一号街阿楠8 小时前
华为AP 4050DN-HD的FIT AP模式改为FAT AP,家用FAT基本配置
网络·华为·信息与通信
电子小子洋酱9 小时前
ESP32移植Openharmony外设篇(9)NB-IOT
单片机·物联网·华为·harmonyos·鸿蒙
北京迅为9 小时前
【北京迅为】itop-3568 开发板openharmony鸿蒙烧写及测试-第1章 体验OpenHarmony—烧写镜像
人工智能·单片机·嵌入式硬件·harmonyos·鸿蒙
以山河作礼。11 小时前
极速探索 HarmonyOS NEXT:开启国产操作系统开发的新篇章
华为·harmonyos