HarmonyOS NEXT 实战之元服务:静态多案例效果(一)

背景:

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

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

在这里插入图片描述
在这里插入图片描述

效果图1代码案例如下:

import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { promptAction } from '@kit.ArkUI';@Entry
@ComponentV2
struct Index {build() {Column() {Column() {//用户信息this.userInfo()}.backgroundColor('#4487EF').borderRadius(4)Row() {Text($r('app.string.EntryAbility_label')).fontSize(18).fontColor(Color.Black)Text('查看更多>').fontSize(15).fontColor(Color.Black)}.justifyContent(FlexAlign.SpaceBetween).width('100%').padding(10).onClick(() => {})Column() {Row() {this.msgRelated($r('app.media.1'), '新能源导航', () => {promptAction.showToast({ message: '新能源导航' })})this.msgRelated($r('app.media.j2'), '货车', () => {})this.msgRelated($r('app.media.j3'), '摩托车', () => {})this.msgRelated($r('app.media.j4'), '骑行', () => {})}.width('95%').height(80).margin({top: 10,left: 12,right: 12}).backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)Row() {this.msgRelated($r('app.media.j5'), '卫星求救', () => {})this.msgRelated($r('app.media.j7'), '打车', () => {})this.msgRelated($r('app.media.j6'), '实时公交', () => {})}.width('95%').height(80).margin({bottom: 4,left: 12,right: 12}).backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)}.width('95%').height(200).margin({top: 10,bottom: 4,left: 12,right: 12}).borderRadius(10).borderWidth(1).borderColor("#F0F0F0").backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)}.margin({ top: 48 })}//消息相关@BuildermsgRelated(src: Resource, title: string, onClick?: () => void) {Column() {Image(src).width(24)Text(title).fontSize(11).fontColor('#222222').margin({ top: 8 })}.onClick(() => {onClick?.()})}@BuilderuserInfo() {Row() {Image($r('app.media.ic_my_avatar')).width(44)Column() {Text('张三').fontSize(18).fontColor(Color.White)Text('VIP标识').fontSize(10).margin({ top: 5 }).fontColor(Color.Yellow)}.alignItems(HorizontalAlign.Start).layoutWeight(1).margin({ left: 8 })Text() {Span('会员剩余')Span(' 9 ').fontSize(18).fontColor("#FEDB9B")Span('天')}.height(32).fontColor("#FEDB9B").fontSize(10).padding({ left: 16, right: 12 }).borderRadius({ topLeft: 20, bottomLeft: 20 })//渐变色.linearGradient({angle: 135,colors: [["#1D2432", 0.2], ['#3E4A61', 0.8]]})}.padding({ bottom: 10 }).width('100%').margin({ top: 46, left: 12 }).onClick(() => {})}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 parameterslet loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();// Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI IDloginRequest.forceLogin = false;// Execute login requestlet 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}});}
}

效果图2代码案例如下:

import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { promptAction } from '@kit.ArkUI';@Entry
@ComponentV2
struct Index {build() {Column() {Column() {Text($r('app.string.EntryAbility_label')).margin({ left: 12 }).fontSize(18).fontColor(Color.White)//用户信息this.userInfo()}.backgroundColor('#35B6BD').borderRadius(4).alignItems(HorizontalAlign.Start).padding({ top: 8 })Row() {Text('机动车出行').fontSize(18).fontColor(Color.Black)Text('查看更多 >').fontSize(15).fontColor(Color.Black)}.justifyContent(FlexAlign.SpaceBetween).width('100%').padding(10).onClick(() => {})Column() {Row() {this.msgRelated($r('app.media.j1'), '城市道路', () => {promptAction.showToast({ message: '城市道路' })})this.msgRelated($r('app.media.j2'), '高速公路', () => {})this.msgRelated($r('app.media.j3'), '乡村道路', () => {})this.msgRelated($r('app.media.j4'), '山区道路', () => {})}.width('95%').height(80).margin({top: 10,left: 12,right: 12}).backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)}.width('95%').height(80).margin({top: 10,bottom: 4,left: 12,right: 12}).borderRadius(10).borderWidth(1).borderColor('#35B6BD').backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)Row() {Text('非机动车出行').fontSize(18).fontColor(Color.Black)Text('查看更多 >').fontSize(15).fontColor(Color.Black)}.justifyContent(FlexAlign.SpaceBetween).width('100%').padding(10).onClick(() => {})Column() {Row() {this.msgRelated($r('app.media.j5'), '自行车道', () => {})this.msgRelated($r('app.media.j6'), '电动自行车道', () => {})this.msgRelated($r('app.media.j7'), '人行车道', () => {})}.width('95%').height(80).margin({bottom: 4,left: 12,right: 12}).backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)}.width('95%').height(80).margin({top: 10,bottom: 4,left: 12,right: 12}).borderRadius(10).borderWidth(1).borderColor('#AEEA00').backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)Row() {Text('特种车辆出行').fontSize(18).fontColor(Color.Black)Text('查看更多 >').fontSize(15).fontColor(Color.Black)}.justifyContent(FlexAlign.SpaceBetween).width('100%').padding(10).onClick(() => {})Column() {Row() {this.msgRelated($r('app.media.j8'), '应急救援车辆', () => {})this.msgRelated($r('app.media.j9'), '工程作业车辆', () => {})}.width('95%').height(80).margin({bottom: 4,left: 12,right: 12}).backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)}.width('95%').height(80).margin({top: 10,bottom: 4,left: 12,right: 12}).borderRadius(10).borderWidth(1).borderColor('RGB(255, 255, 0)').backgroundColor(Color.White).justifyContent(FlexAlign.SpaceAround)}.margin({ top: 48 })}//消息相关@BuildermsgRelated(src: Resource, title: string, onClick?: () => void) {Column() {Image(src).width(24)Text(title).fontSize(11).fontColor('#222222').margin({ top: 8 })}.onClick(() => {onClick?.()})}@BuilderuserInfo() {Row() {Image($r('app.media.ic_my_avatar')).width(44)Column() {Text('小明').fontSize(18).fontColor(Color.White)Text('150****1178').fontSize(10).margin({ top: 5 }).fontColor(Color.Yellow)}.alignItems(HorizontalAlign.Start).layoutWeight(1).margin({ left: 8 })}.padding({ bottom: 10 }).width('100%').margin({ top: 46, left: 12 }).onClick(() => {})}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 parameterslet loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();// Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI IDloginRequest.forceLogin = false;// Execute login requestlet 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}});}
}

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

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

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

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

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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端(Ajax)

1.客户端请求 向https://jsonplaceholder.typicode.com/users发送get请求 const xhr new XMLHttpRequest(); console.log(xhr.readyState); xhr.open(‘get’, ‘https://jsonplaceholder.typicode.com/users’) console.log(xhr.readyState); xhr.send(); console.log(xhr.…

java高频面试之SE-05

面试官:java中为什么有多态? 面试官你好!Java 中有多态主要是为了实现灵活性和可扩展性。通过多态,可以用统一的接口处理不同的对象,从而提高代码的可维护性和可复用性。以下是多态的几个关键原因: 1. 代…

DP83848以太网移植流程,可以TCP通信

DP83848-EP 是一款高度可靠、功能丰富的强大器件,包含了增强型 ESD 保护、MII 和 RMII,从而在 MPU 选择方面实现最大的灵活性,所有这些特性都融入于 48 引脚 PQFP 封装中。 DP83848-EP 配备 集成子层以支持 10BASE-T 和 100BASE-TX 以太网协议,这些协议确保了与基于其他标…

波动理论、传输线和S参数网络

波动理论、传输线和S参数网络 传输线 求解传输线方程 对于传输线模型,我们通常用 R L G C RLGC RLGC 来表示: 其中 R R R 可以表示导体损耗,由于电子流经非理想导体而产生的能量损耗。 G G G 表示介质损耗,由于非理想电介质…

基于pytorch的深度学习基础3——模型创建与nn.Module

三 模型创建与nn.Module 3.1 nn.Module 模型构建两要素: 构建子模块——__init()__拼接子模块——forward() 一个module可以有多个module; 一个module相当于一个运算,都必须实现forward函数; 每一个mod…

Android--java实现手机亮度控制

文章目录 1、开发需求2、运行环境3、主要文件4、布局文件信息5、手机界面控制代码6、debug 1、开发需求 需求:开发一个Android apk实现手机亮度控制 2、运行环境 Android studio最新版本 3、主要文件 app\src\main\AndroidManifest.xml app\src\main\res\layou…

Matlab 和 R 语言的数组索引都是从 1 开始,并且是左闭右闭的

文章目录 一、前言二、主要内容三、小结 🍉 CSDN 叶庭云:https://yetingyun.blog.csdn.net/ 一、前言 在早期的计算机科学中,数组索引从 1 开始是很常见的。例如,Fortran 和 Pascal 等编程语言也采用了从 1 开始的索引。 这种索引…

【优选算法】复写零

链接:1089. 复写零 - 力扣(LeetCode) 算法原理: 解法:双指针算法 根据“异地”操作,然后优化成双指针下的“就地”操作 1.先找到最后一个“复写”的数 1.先判断 cur 位置的值 2.决定 dest 向后移动一步或…

鸿蒙之路的坑

1、系统 Windows 10 家庭版不可用模拟器 对应的解决方案【坑】 升级系统版本 直接更改密钥可自动升级系统 密钥找对应系统的(例:windows 10专业版) 升级完之后要激活 坑1、升级完后事先创建好的模拟器还是无法启动 解决:删除模拟…

大模型应用—IOPaint 图片去水印

IOPaint 是由 SOTA AI 模型提供支持的免费开源修复和修复工具,可以轻松实现图片去水印,去除图片不需要的部分,是目前效果最好的一个项目!完全免费开源 IOPaint 已经托管到 hugging face上,打开就可以直接免费使用,需要外网环境! 在线免费使用:【链接直达】 如果你需要…

SpringBoot项目的5种搭建方式(以idea2017为例)

目录 1. idea中使用官方API 2. idea中使用阿里云API 3. 在spring官网创建 4. 在阿里云官网创建 5. Maven项目改造成springboot项目 SpringBoot项目的创建细分一共有5种,其实主要分为以下三种: ①使用开发工具idea创建springboot项目( Sp…

【Java 学习】详细讲解---包和导包、Scanner类、输入源

1. 包 1.1 什么是包? 举个例子,你和你的同学有不同的家庭,你们都有自己的爸爸妈妈,都有自己的家。在自己的家中你们可以按照自己爱好摆放东西,都互不干扰。但是,假如你们的家都在一起,你们就不…

某科技局国产服务器PVE虚拟化技术文档

环境介绍 硬件配置 服务器品牌:黄河 型号:Huanghe 2280 V2 Cpu型号:kunpeng-920 磁盘信息 :480SSD * 2 ,4T*4 网卡:板载四口千兆 如下表 四台服务器同等型号配置,均做单节点虚拟化,数据保护采用底层r…

汽车免拆诊断案例 | 2011 款奔驰 S400L HYBRID 车发动机故障灯异常点亮

故障现象 一辆2011款奔驰 S400L HYBRID 车,搭载272 974发动机和126 V高压电网系统,累计行驶里程约为29万km。车主反映,行驶中发动机故障灯异常点亮。 故障诊断 接车后试车,组合仪表上的发动机故障灯长亮;用故障检测…

手把手教你安装配置『Oracle Database 19c』

前言 本文将会讲解如何在 Windows 系统上安装 Oracle Database 19c 数据库,适合初学者学习 Oracle 快速入门和实践练习,比较方便快捷 官方安装文档:Preinstallation Considerations for Installing Oracle Database 对于企业级的数据库&am…

学习solid works第七课------装配体

一、新建装配体 一、文件→新建,然后选择装配体 二、界面介绍 二、添加零件 装配体→插入零部件→选择零件再确定。 如果已经打开了零件,在添加零件的时候可以直接点击打开文档直接添加。 有时候一个零件需要多个地方使用,我们可以直接按住…

嵌入式驱动开发详解21(网络驱动开发)

文章目录 前言以太网框架ENET 接口简介MAC接口MII \ RMII 接口MDIO 接口RJ45 接口 PHY芯片以太网驱动驱动挂载wifi模块挂载后续 前言 linux驱动主要是字符设备驱动、块设备驱动还有网络设备驱动、字符设备驱动在本专栏前面已经详细将解了,网络设备驱动本文会做简要…

漏洞扫描:网络安全的 “体检” 与 “防护指南”

在当今数字化时代,网络安全如同守护城堡的坚固城墙,而漏洞扫描则是检查城墙是否存在缝隙与薄弱环节的重要手段。那么,究竟什么是漏洞扫描?又该如何进行呢? 什么是漏洞扫描? 漏洞扫描是一种安全检测过程&a…

Flutter 实现文本缩放学习

Flutter 如何实现一个简单的文本缩放应用程序,其中包含一个可以增加或减少文本大小的功能。 前置知识点学习 TextScaler TextScaler 是一个用于控制文本缩放的工具或机制,不过需要注意的是,TextScaler 并不是 Flutter 框架中内置的类。在 …

接口自动化测试框架(pytest+allure+aiohttp+用例自动生成)

🍅 点击文末小卡片,免费获取软件测试全套资料,资料在手,涨薪更快 近期准备优先做接口测试的覆盖,为此需要开发一个测试框架,经过思考,这次依然想做点儿不一样的东西。 接口测试是比较讲究效…