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

      }
    });
  }
}
相关推荐
思录Echo2 小时前
自助易AI数字人外挂技术剖析|如何解决政企智能客服的多端适配难题?
人工智能·华为·harmonyos
方白羽3 小时前
为什么 Android 非要用 Intent 传值?
android·ios·harmonyos
不爱吃糖的程序媛9 小时前
从 0 到 1:react-native-transformer-text-input 鸿蒙化适配实录
react native·transformer·harmonyos
不爱吃糖的程序媛9 小时前
React Native 三方库鸿蒙适配实战:react-native-emoji-popup(Fabric 自定义组件)从 0 到 1
react native·harmonyos·fabric
贾伟康9 小时前
【口算王|19】HarmonyOS ArkTS 回归测试实战:覆盖启动、空数据、异常输入和重复点击
软件测试·harmonyos·arkts·回归测试·hypium
贾伟康9 小时前
【句匠|09】HarmonyOS ArkTS 学习统计实战:汇总正确率、连续学习和薄弱类型
harmonyos·arkts·appstorage·学习统计·本地统计
贾伟康10 小时前
【口算王|17】HarmonyOS ArkTS 亮暗色与视觉令牌实战:集中颜色、间距和交互状态避免页面割裂
harmonyos·arkts·arkui·深色模式·ui设计
搬砖的kk10 小时前
从 0 到 1:react-native-screenshot-aware 鸿蒙适配实战(RNOH 0.84)
react native·华为·harmonyos
贾伟康10 小时前
【口算王|15】HarmonyOS ArkTS 本地状态持久化实战:让保存、删除和页面返回后的数据即时一致
harmonyos·arkts·数据持久化·状态管理·preferences
贾伟康10 小时前
【口算王|18】HarmonyOS ArkTS 权限与隐私实战:让 module.json5、功能说明和拒绝路径一致
harmonyos·arkts·权限管理·隐私合规·module.json5