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
相关文章:
HarmonyOS NEXT 实战之元服务:静态多案例效果(一)
背景: 前几篇学习了元服务,后面几期就让我们开发简单的元服务吧,里面丰富的内容大家自己加,本期案例 仅供参考 先上本期效果图 ,里面图片自行替换 效果图1代码案例如下: import { authentication } from…...
go下载依赖提示连接失败
1、现象 Go下载模块提示连接失败 dial tcp 142.251.42.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.…...
JS 异步 ( 二、Promise 的用法、手写模拟 Promise )
文章目录 一、Promise 基础Promise 作用Promise 语法Promise 内部状态值 和 链式调用Promise 是否为异步执行Promise 常用函数或属性 二、模拟 Promise,加深理解 一、Promise 基础 Promise 作用 1. 回调地狱 想知道 Promise 的作用, 需要先了解一个概念叫…...
五分钟学会如何在GitHub上自动化部署个人博客(hugo框架 + stack主题)
上一篇文章: 10分钟学会免费搭建个人博客(Hugo框架 stack主题) 前言 首先,想要实现这个功能的小伙伴需要完成几个前置条件: 有一个GitHub账号安装了git,并可以通过git推送commit到GitHub上完成第一篇文章…...
【ETCD】【实操篇(十五)】etcd集群成员管理:如何高效地添加、删除与更新节点
etcd 是一个高可用的分布式键值存储,广泛应用于存储服务发现、配置管理等场景。为了确保集群的稳定性和可扩展性,管理成员节点的添加、删除和更新变得尤为重要。本文将指导您如何在etcd集群中处理成员管理,帮助您高效地维护集群节点。 目录 …...
灵当CRM uploadfile.php 文件上传致RCE漏洞复现
0x01 产品简介 灵当CRM是一款专为中小企业打造的智能客户关系管理工具,由上海灵当信息科技有限公司开发并运营。广泛应用于金融、教育、医疗、IT服务、房地产等多个行业领域,帮助企业实现客户个性化管理需求,提升企业竞争力。无论是新客户开拓、老客户维护,还是销售过程管…...
Linux下Java通过JNI调用C++
以下为Demo流程 1.创建Java文件 public class HelloWord {// 声明本地方法public native void sayHello();static {// 加载本地库System.loadLibrary("hello");}public static void main(String[] args) {new HelloWord().sayHello();} } 2.编译生成.h头文件 在H…...
解决:excel鼠标滚动幅度太大如何调节?
在excel里为什么滚动一次跳过很多行呢?很不方便。。。 1. 问题: 一开始单元格从第1行开始: 鼠标轻轻滚动一下后,直接跳到第4行: 鼠标在word和浏览器里都是好好的。在excel里为什么不是滚动一次跳过一行呢ÿ…...
Git和SVN有什么区别?
Git和SVN是两种流行的版本控制系统,它们在实现方式、使用场景和特性上存在一些关键区别: 分布式 vs 集中式: Git:是分布式的版本控制系统。每个开发者都有一个完整的仓库副本,可以离线工作,并在本地进行所有…...
【深度学习基础|pip安装】pip 安装深度学习库常见错误及解决方案,附案例。
【深度学习基础|pip安装】pip 安装深度学习库常见错误及解决方案,附案例。 【深度学习基础|pip安装】pip 安装深度学习库常见错误及解决方案,附案例。 文章目录 【深度学习基础|pip安装】pip 安装深度学习库常见错误及解决方案,附案例。1. 错…...
【ES6复习笔记】解构赋值(2)
介绍 解构赋值是一种非常方便的语法,可以让我们更简洁地从数组和对象中提取值,并且可以应用于很多实际开发场景中。 1. 数组的解构赋值 数组的解构赋值是按照一定模式从数组中提取值,然后对变量进行赋值。下面是一个例子: con…...
Dockerfile的用法
Dockerfile的用法 示例 `Dockerfile`使用 `Dockerfile` 创建 Docker 镜像`Dockerfile` 指令详解其他常用指令总结Dockerfile 是一个文本文件,包含了用于创建 Docker 镜像的一系列指令。这些指令描述了镜像的基础、所安装的软件、文件的复制、环境变量的设置以及其他配置。下面…...
Docker 安装mysql ,redis,nacos
一、Mysql 一、Docker安装Mysql 1、启动Docker 启动:sudo systemctl start dockerservice docker start 停止:systemctl stop docker 重启:systemctl restart docker 2、查询mysql docker search mysql 3、安装mysql 3.1.默认拉取最新版…...
Axure RP 11 详细保姆级安装教程(附安装包)
文章目录 初识:Axure RP 11 安装推荐配置 一、下载安装包 二、安装步骤 1.运行安装程序 2.安装向导,点击【Next】 3.许可协议,勾选【I accept the terms in the License Agreement】,然后点击【Next】 4.确认安装位置&…...
Java处理视频思路
1.首先实现断点续传功能。 断点续传实现思路: 前端对文件分块。前端使用多线程一块一块上传,上传前给服务端发一个消息校验该分块是否上传,如果已上传则不再上传。如果从该断点处断网了,下次上传时,前面的分块已经存在…...
攻防世界 robots
开启场景 根据提示访问/robots.txt,发现了 f1ag_1s_h3re.php 拼接访问 /f1ag_1s_h3re.php 发现了 flag cyberpeace{d8b7025ed93ed79d44f64e94f2527a17}...
DBeaver 咋手动配置sqlite 驱动
目录 1 问题2 下载 1 问题 离线安装了DBeaver 数据库软件,现在需要使用这个数据库打开sqlite 数据库,但是提示没有 驱动,那么我们就需要手动下载驱动,在这个软件里面导入 2 下载 https://repo1.maven.org/maven2/org/xerial/sql…...
RestTemplate关于https的使用详解
RestTemplate关于https的使用详解 一、restTemplate注入到bean里面。 Configuration public class RestTempleConfig {BeanPrimarypublic RestTemplate restTemplate() {return new RestTemplate();}/*** https 请求的 restTemplate* return* throws Exception*/Beanpublic R…...
消息中间件RabbitMQ和kafka
一、RabbitMQ 1、RabbitMQ如何保证消息不丢失 2、RabbitMQ如何解决重复消费的问题 3、RabbitMQ中的死信交换机 4、RabbitMQ消息堆积怎么解决 5、RabbitMQ的高可用机制 二、kafka 1、kafka如何保证消息不丢失和重复消费的问题 2、kafka如何保证消费的顺序性 3、kafka高可用机制…...
学习C++:标识符命名规则
标识符命名规则: 作用:C规定给标识符(变量、常量)命名时,有一套自己的规则 标识符不能是关键字 标识符只能由字母、数字、下划线组成 第一个字符必须为字母或下划线 标识符中字母区分大小写 (给标识符命…...
基于算法竞赛的c++编程(28)结构体的进阶应用
结构体的嵌套与复杂数据组织 在C中,结构体可以嵌套使用,形成更复杂的数据结构。例如,可以通过嵌套结构体描述多层级数据关系: struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...
简易版抽奖活动的设计技术方案
1.前言 本技术方案旨在设计一套完整且可靠的抽奖活动逻辑,确保抽奖活动能够公平、公正、公开地进行,同时满足高并发访问、数据安全存储与高效处理等需求,为用户提供流畅的抽奖体验,助力业务顺利开展。本方案将涵盖抽奖活动的整体架构设计、核心流程逻辑、关键功能实现以及…...
CocosCreator 之 JavaScript/TypeScript和Java的相互交互
引擎版本: 3.8.1 语言: JavaScript/TypeScript、C、Java 环境:Window 参考:Java原生反射机制 您好,我是鹤九日! 回顾 在上篇文章中:CocosCreator Android项目接入UnityAds 广告SDK。 我们简单讲…...
【HTTP三个基础问题】
面试官您好!HTTP是超文本传输协议,是互联网上客户端和服务器之间传输超文本数据(比如文字、图片、音频、视频等)的核心协议,当前互联网应用最广泛的版本是HTTP1.1,它基于经典的C/S模型,也就是客…...
JVM 内存结构 详解
内存结构 运行时数据区: Java虚拟机在运行Java程序过程中管理的内存区域。 程序计数器: 线程私有,程序控制流的指示器,分支、循环、跳转、异常处理、线程恢复等基础功能都依赖这个计数器完成。 每个线程都有一个程序计数…...
GitHub 趋势日报 (2025年06月06日)
📊 由 TrendForge 系统生成 | 🌐 https://trendforge.devlive.org/ 🌐 本日报中的项目描述已自动翻译为中文 📈 今日获星趋势图 今日获星趋势图 590 cognee 551 onlook 399 project-based-learning 348 build-your-own-x 320 ne…...
Unity UGUI Button事件流程
场景结构 测试代码 public class TestBtn : MonoBehaviour {void Start(){var btn GetComponent<Button>();btn.onClick.AddListener(OnClick);}private void OnClick(){Debug.Log("666");}}当添加事件时 // 实例化一个ButtonClickedEvent的事件 [Formerl…...
Bean 作用域有哪些?如何答出技术深度?
导语: Spring 面试绕不开 Bean 的作用域问题,这是面试官考察候选人对 Spring 框架理解深度的常见方式。本文将围绕“Spring 中的 Bean 作用域”展开,结合典型面试题及实战场景,帮你厘清重点,打破模板式回答,…...
如何应对敏捷转型中的团队阻力
应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中,明确沟通敏捷转型目的尤为关键,团队成员只有清晰理解转型背后的原因和利益,才能降低对变化的…...
华为OD最新机试真题-数组组成的最小数字-OD统一考试(B卷)
题目描述 给定一个整型数组,请从该数组中选择3个元素 组成最小数字并输出 (如果数组长度小于3,则选择数组中所有元素来组成最小数字)。 输入描述 行用半角逗号分割的字符串记录的整型数组,0<数组长度<= 100,0<整数的取值范围<= 10000。 输出描述 由3个元素组成…...
