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语言)
目录 1. 栈的定义 2. 代码实现 1. 栈的定义 栈属于线性表,具有后进先出的特点,存储结构类似羽毛球桶,可以依次取出最后放入栈中的数据。实现:栈一般采用数组 / 链表实现,但是推荐程度:数组 > 单链表 …...
SMUDebugTool:深度控制AMD Ryzen硬件参数的系统调试解决方案
SMUDebugTool:深度控制AMD Ryzen硬件参数的系统调试解决方案 【免费下载链接】SMUDebugTool A dedicated tool to help write/read various parameters of Ryzen-based systems, such as manual overclock, SMU, PCI, CPUID, MSR and Power Table. 项目地址: http…...
华硕笔记本终极优化指南:用GHelper彻底释放硬件潜能
华硕笔记本终极优化指南:用GHelper彻底释放硬件潜能 【免费下载链接】g-helper Lightweight, open-source control tool for ASUS laptops and ROG Ally. Manage performance modes, fans, GPU, battery, and RGB lighting across Zephyrus, Flow, TUF, Strix, Scar…...
18年产品经理生涯精华:从交付到规划,项目管理、解决方案、业务理解深度解析!
本期访谈只有1位老师,大海老师,18年工作经验,从干交付,到项目管理,再到资深技术专家、解决方案专家,目前做的更多的是业务规划、产品规划,是从一线实战走到真正的专家层面,老师分享的…...
Phi-4-mini-reasoning vLLM部署避坑指南:日志排查、加载失败诊断与修复步骤
Phi-4-mini-reasoning vLLM部署避坑指南:日志排查、加载失败诊断与修复步骤 1. 模型简介与环境准备 Phi-4-mini-reasoning 是一个基于合成数据构建的轻量级开源模型,专注于高质量、密集推理的数据,并进一步微调以提高更高级的数学推理能力。…...
OpenClaw浏览器扩展:Kimi-VL-A3B-Thinking网页图文即时分析工具
OpenClaw浏览器扩展:Kimi-VL-A3B-Thinking网页图文即时分析工具 1. 为什么需要浏览器增强工具 作为一个经常需要从网页获取信息的技术写作者,我长期被两个问题困扰:一是网页内容过于冗长,需要手动筛选关键信息;二是遇…...
别再只跑Demo了!手把手教你用TensorFlow训练自己的谷物分类模型(11类数据集)
从零构建高精度谷物分类模型:TensorFlow实战指南 当你第一次接触深度学习时,可能已经运行过MNIST手写数字识别或CIFAR-10这样的标准Demo。但真正要解决实际问题时,这些玩具数据集远远不够。本文将带你用TensorFlow处理一个真实的11类谷物图像…...
2026年,行业内热门GEO搜索优化公司口碑究竟如何?
你是否在为提升品牌在搜索引擎上的排名而烦恼?是否因高昂的优化成本和复杂的操作望而却步?又或者担心优化效果不佳,无法实现询盘转化?今天,我们就来深入探讨一下2026年热门的GEO优化软件,看看哪款能真正解决…...
引爆企业降本增效的AI革命!生成式AI应用专家亲授,从字节跳动到华为的数字化转型实战秘籍!
本文介绍了资深AI专家Mr. Li在生成式AI应用与数字化转型领域的丰富经验,涵盖其在华为、字节跳动等企业的实践经历,以及在多个国家级标准制定和央企数字化转型项目中的参与。Mr. Li提供了一系列关于生成式AI和企业数字化转型的精品课程,旨在帮…...
机器人双目视觉定位系统设计与开发
机器人双目视觉定位系统设计与开发 摘要 双目视觉定位技术是机器人感知环境、实现自主导航和精准操作的核心技术之一。本系统基于双目立体视觉原理,利用Matlab平台完成了从相机标定、图像采集、立体匹配到三维坐标解算的完整流程。系统采用张正友标定法获取相机内外参数,通…...
