HarmonyOS NEXT 实战之元服务:静态案例效果---查看国内航班服务

背景:

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

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

在这里插入图片描述

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

  • Index代码
import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { AddressExchangeViewComponent } from './AddressExchangeViewComponent';


export const DATA_CONFIG: Record<string, number> = {
  'NUMBER_LEN': 7,
  'DURATION_TIME': 200,
  'MILLENNIAL_LEN': 3
}

export const STYLE_CONFIG: Record<string, number> = {
  'ITEM_GUTTER': 12,
  'ITEM_HEIGHT': 26,
  'TEXT_MARGIN': 2,
  'PADDING_TOP': 32
}

@Entry
@Component
struct Index {
  build() {
    Column({ space: STYLE_CONFIG.ITEM_GUTTER }) {
      Text($r('app.string.EntryAbility_label')).fontColor(Color.White)
        .fontSize($r('sys.float.ohos_id_text_size_headline8'))
        .width($r('app.string.digital_scroll_animation_max_size'))
        .textAlign(TextAlign.Center)
      AddressExchangeViewComponent()
    }
    .padding({
      top: STYLE_CONFIG.PADDING_TOP
    })
    .margin({ top: 60 })
    .width($r('app.string.digital_scroll_animation_max_size'))
    .height($r('app.string.digital_scroll_animation_max_size'))
    .linearGradient({
      colors: [[$r('app.color.digital_scroll_animation_background_color'), 0.0],
        [$r('sys.color.ohos_id_color_background'), 0.3]]
    })

  }

  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

      }
    });
  }
}

  • AddressExchangeViewComponent 代码
import curves from '@ohos.curves';
import { promptAction } from '@kit.ArkUI';


@Preview
@Component
export struct AddressExchangeViewComponent {
  @State rotateAngle: number = 0;
  @State translateX: number = 0;
  @State swap: boolean = false;
  private JWidth: number = 300;


  build() {

    Column({ space: 15 }) {
      Row() {
        Text($r('app.string.address_exchange_address_left'))
          .translate({ x: this.translateX })
          .width("40%")
          .textAlign(this.swap ? TextAlign.End : TextAlign.Start)
          .onClick(() => {
            promptAction.showToast({
              message: '北京',
            });
          })

        Stack() {
          Image($r('app.media.address_exchange_airplane'))
            .size({
              height: 16,
              width: 16
            })
          Image($r('app.media.address_exchange_recycle'))
            .size({
              height: 38,
              width: 38
            })
            .rotate({ angle: this.rotateAngle })
            .animation({
              curve: Curve.EaseOut,
              playMode: PlayMode.Normal,
            })
        }
        .width("20%")
        .onClick(() => {
          this.swap = !this.swap
          animateTo({ curve: curves.springMotion() }, () => {
            if (this.swap) {
              this.translateX = this.JWidth * 0.5;
            } else {
              this.translateX = 0
            }
          })
          this.rotateAngle += 180;
        })

        Text('深圳')
          .translate({ x: -this.translateX })
          .width("40%")
          .textAlign(this.swap ? TextAlign.Start : TextAlign.End)
          .onClick(() => {
            promptAction.showToast({
              message: '点了'
            });
          })
      }
      .width(this.JWidth)
      .borderWidth(1)
      .borderRadius(8)
      .padding(8)
      .height(60)

      Row({ space: 15 }) {
        Text(this.getDate())
          .fontSize($r('app.string.ohos_id_text_size_headline'))
          .fontWeight(FontWeight.Medium)
          .height(30)
        Text($r('app.string.address_exchange_week'))
          .height(30)
      }
      .width(this.JWidth)
      .onClick(() => {
        promptAction.showToast({
          message: '点了'
        });
      })

      Button($r('app.string.address_exchange_search_ticket'))
        .fontColor(Color.White)
        .height(40)
        .backgroundColor('#6486FF')
        .width(this.JWidth)
        .onClick(() => {
          promptAction.showToast({
            message: '今日机器出现故障,请找工作室人员解决'
          });
        })
      Row({ space: 10 }) {
        Row() {
          Text('出差 返现').fontSize(13).fontColor('#222222')
          Toggle({ type: ToggleType.Checkbox, isOn: false })
        }

        Row() {
          Row() {
            Text('带儿童/婴儿').fontSize(13).fontColor('#222222')
            Toggle({ type: ToggleType.Checkbox, isOn: true })
          }

          Row() {
            Text('学生票').fontSize(13).fontColor('#222222')
            Toggle({ type: ToggleType.Checkbox, isOn: false })
          }
        }
      }.width('100%').justifyContent(FlexAlign.SpaceBetween)


      Row() {
        Text('每周特价机票')
          .fontSize(18)
          .fontColor(Color.Black)

        Text('查看更多>')
          .fontSize(15)
          .fontColor(Color.Black)
      }.justifyContent(FlexAlign.SpaceBetween).width('100%').padding(10).onClick(() => {
      })

      Row({ space: 20 }) {
        Column({ space: 10 }) {
          Text('上海   ->   深圳').fontWeight(FontWeight.Bold).fontSize(13).fontColor('#5A5A5A')
          Row() {
            Text('12月3日 | 周一').fontSize(10).fontColor('#CAC8C9')
            Text('¥600').fontSize(15).fontColor(Color.Red).fontWeight(FontWeight.Bold).margin({ left: 8 })
          }.width('100%').justifyContent(FlexAlign.SpaceBetween)

          Text() {
            Span('原价  ').fontColor('#222222').fontSize(15)
            Span('¥1000').fontColor(Color.Red).fontSize(15)
          }.fontWeight(FontWeight.Bold).margin({ left: 8 })

        }
        .width('100%')
        .borderRadius(4)
        .backgroundColor('#F5F9F8')
        .padding(8)
        .alignItems(HorizontalAlign.Start)

      }

      Row({ space: 20 }) {
        Column({ space: 10 }) {
          Text('北京   ->   天津').fontWeight(FontWeight.Bold).fontSize(13).fontColor('#5A5A5A')
          Row() {
            Text('12月5日 | 周四').fontSize(10).fontColor('#CAC8C9')
            Text('¥300').fontSize(15).fontColor(Color.Red).fontWeight(FontWeight.Bold).margin({ left: 8 })
          }.width('100%').justifyContent(FlexAlign.SpaceBetween)

          Text() {
            Span('原价  ').fontColor('#222222').fontSize(15)
            Span('¥400').fontColor(Color.Red).fontSize(15)
          }.fontWeight(FontWeight.Bold).margin({ left: 8 })

        }
        .width('100%')
        .borderRadius(4)
        .backgroundColor('#F5F9F8')
        .padding(8)
        .alignItems(HorizontalAlign.Start)

      }

    }
    .width($r('app.string.address_exchange_content_size'))
    .height(178)
    .margin($r('app.string.ohos_id_card_margin_start'))
  }

  private getDate() {
    const now = new Date();
    const year = now.getFullYear();
    const month = now.getMonth() + 1; // 注意:月份是从0开始计数的
    const day = now.getDate();
    const hours = now.getHours();
    const minutes = now.getMinutes();
    const seconds = now.getSeconds();
    return `${year} 年 ${month} 月 ${day} 日`
  }
}

最近文章>>>>>>>>>>>

HarmonyOS NEXT实战:元服务与应用 APP 发布应用市场的详细步骤与流程

若本文对您稍有帮助,诚望您不吝点赞,多谢。

有兴趣的同学可以点击查看源码

  • gitee:https://gitee.com/jiaojiaoone/explore-harmony-next/tree/case%2Fwanandroid/
  • github:https://github.com/JasonYinH/ExploreHarmonyNext.git

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/942786.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Java】Jackson序列化案例分析

1.Jackson介绍 Jackson 是一个流行的 Java 库&#xff0c;用于处理 JSON 数据。它提供了高效的序列化和反序列化功能&#xff0c;能够将 Java 对象转换为 JSON 格式&#xff0c;反之亦然。 它由 FasterXML 开发和维护。Jackson 的设计目标是提供高效、灵活且易于使用的 JSON 处…

Java反射学习(2)(“反射“机制获取构造方法及内部信息(Constructor类))

目录 一、"Class"对象实例化的常见三种方式以及使用时机。 &#xff08;1&#xff09;源代码(编写)阶段——使用全限定类名.forName()。 &#xff08;2&#xff09;加载阶段——使用类名.class。 &#xff08;3&#xff09;运行阶段——使用对象.getClass()。 二、Ja…

洛谷 P1595 信封问题 C语言dp

题目描述 某人写了 n 封信和 n 个信封&#xff0c;如果所有的信都装错了信封。求所有信都装错信封共有多少种不同情况。 输入格式 一个信封数 n&#xff0c;保证 n≤20。 输出格式 一个整数&#xff0c;代表有多少种情况。 输入输出样例 输入 #1 2 输出 #1 1 输入 #2 3 输…

【LuaFramework】服务器模块相关知识

目录 一、客户端代码 二、本地服务器代码 三、解决服务器无法多次接收客户端消息问题 一、客户端代码 连接本地服务器127.0.0.1:2012端口&#xff08;如何创本地服务器&#xff0c;放最后说&#xff09;&#xff0c;连接成功后会回调 协议号Connect是101&#xff0c;其他如下…

解决Ascend上vllm运行时出现urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED]

背景 尝试使用vllm模型&#xff0c;脚本代码如下&#xff1a; from vllm import LLM, SamplingParamsprompts ["Hello, my name is","The president of the United States is","The capital of France is","The future of AI is", …

【卷积神经网络】常用评价指标总结

评估指标 概述 该评价指标适合分类任务与目标检测&#xff0c;主要用于评估模型的性能。该文章对相关指标进行总结&#xff0c;同时对输出的图片进行学习分析 混淆矩阵的组成 TP&#xff08;True Positives&#xff0c;真正例&#xff09;&#xff1a;实际为正例&#xff0c;…

HarmonyOS NEXT 的技术发展和市场趋势:打造1+8+N的万物互联新世界

随着5G、AI、物联网等技术的飞速发展&#xff0c;全球智能设备和操作系统的竞争也日益激烈。在这一背景下&#xff0c;华为推出的HarmonyOS NEXT正逐渐成为智能设备生态中一个重要的参与者&#xff0c;其独特的18N战略布局以及跨设备、跨平台的互联互通理念&#xff0c;正在塑造…

免费 IP 归属地接口

免费GEOIP&#xff0c;查询IP信息&#xff0c;支持IPV4 IPV6 ,包含国家地理位置&#xff0c;维度&#xff0c;asm,邮编 等&#xff0c;例如 例如查询1.1.1.1 http://geoip.91hu.top/?ip1.1.1.1 返回json 对象

以太网通信--读取物理层PHY芯片的状态

PHY芯片通过MDIO接口进行读写&#xff0c;框图如下所示&#xff1a; 原理很简单&#xff0c;就是按照时序将PHY芯片的指定寄存器信息读出或者写入。 MDC时钟需要输出到PHY芯片&#xff0c;一般不低于80MHz。 MDIO是双向接口&#xff0c;FPGA读出状态信息时为输入&#xff0c;FP…

Docker服务发现新纪元:探索Consul的无限魅力

作者简介&#xff1a;我是团团儿&#xff0c;是一名专注于云计算领域的专业创作者&#xff0c;感谢大家的关注 •座右铭&#xff1a; 云端筑梦&#xff0c;数据为翼&#xff0c;探索无限可能&#xff0c;引领云计算新纪元个人主页&#xff1a;团儿.-CSDN博客 目录 前言&…

OpenHarmony-6.IPC/RPC组件

IPC/RPC组件机制 1.基本概念 IPC&#xff1a;设备内的进程间通信&#xff08;Inter-Process Communication&#xff09;。 RPC&#xff1a;设备间的进程间通信&#xff08;Remote Procedure Call&#xff09;。 IPC/RPC用于实现跨进程通信&#xff0c;不同的是前者使用Binder驱…

0.机顶盒晶晨s905l3b芯片--刷入第三方系统+安卓9 root教程+armbian写入EMMC教程

机顶盒s905l3b芯片刷第三方系统安卓9 root教程刷armbian写入EMMC教程 声明&#xff1a; 由于固件、软件、镜像等持续更新&#xff0c;本文仅代表当前所使用版本的流畅安装记录。行文略长&#xff0c;关键代码处会配以截图展示&#xff0c;请自行对比是否存在差异导致安装失败…

视频监控平台:Liveweb视频汇聚融合平台智慧安防视频监控应用方案

Liveweb是一款功能强大、灵活部署的安防视频监控平台&#xff0c;支持多种主流标准协议&#xff0c;包括GB28181、RTSP/Onvif、RTMP等&#xff0c;同时兼容海康Ehome、海大宇等厂家的私有协议和SDK接入。该平台不仅提供传统安防监控功能&#xff0c;还支持接入AI智能分析&#…

汇编语言学习

想要理解栈溢出的最基本原理&#xff0c;汇编和栈是必不可少的&#xff0c;不然想我之前学了也是白学&#xff0c;原理都不知道 一、准备 1.安装gcc sudo apt-get build-dep gcc 这里显示版本不对&#xff0c;我用的是国内镜像源&#xff0c;需要换一下配置 sudo nano /e…

“乡村探索者”:村旅游网站的移动应用开发

3.1 可行性分析 从三个不同的角度来分析&#xff0c;确保开发成功的前提是有可行性分析&#xff0c;只有进行提前分析&#xff0c;符合程序开发流程才不至于开发过程的中断。 3.1.1 技术可行性 在技术实现层次&#xff0c;分析了好几种技术实现方法&#xff0c;并且都有对应的成…

Python + 深度学习从 0 到 1(02 / 99)

希望对你有帮助呀&#xff01;&#xff01;&#x1f49c;&#x1f49c; 如有更好理解的思路&#xff0c;欢迎大家留言补充 ~ 一起加油叭 &#x1f4a6; 欢迎关注、订阅专栏 【深度学习从 0 到 1】谢谢你的支持&#xff01; ⭐ Keras 快速入门&#xff1a; 神经网络的基本数据结…

MySQL用户授权

什么是数据库 数据库概述&#xff1a;数据库是按照一定的数据结构将数据存储在存储器的集合常见数据库软件 软件名开源跨平台厂 商Oracle否是甲骨文MySQL是是甲骨文SQL Server否否微软DB2否是IBMMongoDB是是MongoDB Inc.Redis是是开源软件Memcached是是开源软件 DB (DataBas…

2025年我国网络安全发展形势展望

展望2025年&#xff0c;我国网络安全产业有望迎来新的快速增长阶段&#xff0c;零信任安全架构将在各行各业加快应用落地&#xff0c;数据安全技术攻关和应用进程加快&#xff0c;关键基础设施安全能力不断提升。同时&#xff0c;也应关注国家级网络对抗风险加剧、网络安全产业…

GitPuk安装配置指南

GitPuk是一款开源免费的代码管理工具&#xff0c;上篇文章已经介绍了Gitpuk的功能与优势&#xff0c;这篇文章将为大家讲解如何快速安装和配置GitPuk&#xff0c;助力你快速的启动GitPuk管理代码 1. 安装 支持 Windows、Mac、Linux、docker 等操作系统。 1.1 Windows安装 下载…

ArcGIS+MIKE21 洪水淹没分析、溃坝分析,洪水淹没动态效果

洪水淹没分析过程&#xff1a; 一、所需数据&#xff1a; 1.分析区域DEM数据 二、ArcGIS软件 1.提取分析区域DEM&#xff08;水库坝下区域&#xff09; 2.DEM栅格转点 3.计算转换后几何点的x和y坐标值&#xff08;精度20、小数位3&#xff09; 4.导出属性表&#xff0c;形式…