鸿蒙开发 之 健康App案例
1.项目介绍
该项目是记录用户日常饮食情况,以及针对不同食物摄入营养不同会有对应的营养摄入情况和日常运动消耗情况,用户可以自己添加食品以及对应的热量。
1.1登陆页
1.2饮食统计页
1.3 食物列表页
2.登陆页
2.1自定义弹框
import preferences from '@ohos.data.preferences';
import { CommonConstants } from '../constants/CommonConstants';
import Logger from './Logger';class PreferenceUtil{private pref: preferences.Preferencesasync loadPreference(context){try { // 加载preferencesthis.pref = await preferences.getPreferences(context, CommonConstants.H_STORE)Logger.debug(`加载Preferences[${CommonConstants.H_STORE}]成功`)} catch (e) {Logger.debug(`加载Preferences[${CommonConstants.H_STORE}]失败`, JSON.stringify(e))}}async putPreferenceValue(key: string, value: preferences.ValueType){if (!this.pref) {Logger.debug(`Preferences[${CommonConstants.H_STORE}]尚未初始化!`)return}try {// 写入数据await this.pref.put(key, value)// 刷盘await this.pref.flush()Logger.debug(`保存Preferences[${key} = ${value}]成功`)} catch (e) {Logger.debug(`保存Preferences[${key} = ${value}]失败`, JSON.stringify(e))}}async getPreferenceValue(key: string, defaultValue: preferences.ValueType){if (!this.pref) {Logger.debug(`Preferences[${CommonConstants.H_STORE}]尚未初始化!`)return}try {// 读数据let value = await this.pref.get(key, defaultValue)Logger.debug(`读取Preferences[${key} = ${value}]成功`)return value} catch (e) {Logger.debug(`读取Preferences[${key}]失败`, JSON.stringify(e))}}
}const preferenceUtil = new PreferenceUtil()export default preferenceUtil as PreferenceUtil
export class CommonConstants {static readonly RDB_NAME: string = 'HealthyLife.db'; // db name// THOUSANDTHstatic readonly THOUSANDTH_15: string = '1.5%'; // ‘1.5%’static readonly THOUSANDTH_12: string = '2.2%'; // ‘2.2%’static readonly THOUSANDTH_33: string = '3.3%'; // ‘3.3%’static readonly THOUSANDTH_50: string = '5%'; // ‘5%’static readonly THOUSANDTH_66: string = '6.6%'; // ‘6.6%’static readonly THOUSANDTH_80: string = '8%'; // ‘8%’static readonly THOUSANDTH_100: string = '10%'; // ‘10%’static readonly THOUSANDTH_120: string = '12%'; // ‘12%’static readonly THOUSANDTH_160: string = '16%'; // ‘16%’static readonly THOUSANDTH_400: string = '40%'; // ‘40%’static readonly THOUSANDTH_420: string = '42%'; // ‘42%’static readonly THOUSANDTH_500: string = '50%'; // ‘50%’static readonly THOUSANDTH_560: string = '56%'; // ‘56%’static readonly THOUSANDTH_800: string = '80%'; // ‘80%’static readonly THOUSANDTH_830: string = '83%'; // ‘83%’static readonly THOUSANDTH_880: string = '88%'; // ‘88%’static readonly THOUSANDTH_900: string = '90%'; // ‘90%’static readonly THOUSANDTH_940: string = '94%'; // ‘90%’static readonly THOUSANDTH_1000: string = '100%'; // ‘100%’static readonly DEFAULT_2: number = 2;static readonly DEFAULT_6: number = 6;static readonly DEFAULT_8: number = 8;static readonly DEFAULT_12: number = 12;static readonly DEFAULT_10: number = 10;static readonly DEFAULT_16: number = 16;static readonly DEFAULT_18: number = 18;static readonly DEFAULT_20: number = 20;static readonly DEFAULT_24: number = 24;static readonly DEFAULT_28: number = 28;static readonly DEFAULT_32: number = 32;static readonly DEFAULT_48: number = 48;static readonly DEFAULT_56: number = 56;static readonly DEFAULT_60: number = 60;static readonly DEFAULT_100: number = 100;static readonly DEFAULT_180: number = 180;// fontWeightstatic readonly FONT_WEIGHT_400: number = 400;static readonly FONT_WEIGHT_500: number = 500;static readonly FONT_WEIGHT_600: number = 600;static readonly FONT_WEIGHT_700: number = 700;static readonly FONT_WEIGHT_900: number = 900;// opacitystatic readonly OPACITY_4: number = 0.4;static readonly OPACITY_6: number = 0.6;// radiusstatic readonly BORDER_RADIUS_PERCENT_50: string = '50%';// durationstatic readonly DURATION_1000: number = 1000; // 1000msstatic readonly DURATION_800: number = 800; // 700msstatic readonly DURATION_100: number = 100; // 100ms// spacestatic readonly SPACE_2: number = 2;static readonly SPACE_4: number = 4;static readonly SPACE_6: number = 6;static readonly SPACE_8: number = 8;static readonly SPACE_10: number = 10;static readonly SPACE_12: number = 12;// global data keystatic readonly H_STORE: string = 'HeimaHealthyStore';static readonly RECORD_DATE: string = 'selectedDate';static readonly PACKAGE_NAME: string = 'com.itheima.healthylife';static readonly ENTRY_ABILITY: string = 'EntryAbility';/*** 当前用户推荐的每日摄入热量上限,单位:卡路里*/static readonly RECOMMEND_CALORIE: number = 1962/*** 当前用户推荐的每日摄入碳水上限,单位:克*/static readonly RECOMMEND_CARBON: number = 237/*** 当前用户推荐的每日摄入蛋白质上限,单位:克*/static readonly RECOMMEND_PROTEIN: number = 68/*** 当前用户推荐的每日摄入脂肪上限,单位:克*/static readonly RECOMMEND_FAT: number = 53
}
import { CommonConstants } from '../../common/constants/CommonConstants'
@CustomDialog
export default struct UserPrivacyDialog {controller: CustomDialogControllerconfirm: () => voidcancel: () => voidbuild() {Column({space: CommonConstants.SPACE_10}){// 1.标题Text($r('app.string.user_privacy_title')).fontSize(20).fontWeight(CommonConstants.FONT_WEIGHT_700)// 2.内容Text($r('app.string.user_privacy_content'))// 3.按钮Button($r('app.string.agree_label')).width(150).backgroundColor($r('app.color.primary_color')).onClick(() => {this.confirm()this.controller.close()})Button($r('app.string.refuse_label')).width(150).backgroundColor($r('app.color.lightest_primary_color')).fontColor($r('app.color.light_gray')).onClick(() => {this.cancel()this.controller.close()})}.width('100%').padding(10)}
}
import common from '@ohos.app.ability.common'
import router from '@ohos.router'
import PreferenceUtil from '../common/utils/PreferenceUtil'
import UserPrivacyDialog from '../view/welcome/UserPrivacyDialog'
@Extend(Text) function opacityWhiteText(opacity: number, fontSize: number = 10) {.fontSize(fontSize).opacity(opacity).fontColor(Color.White)
}
const PREF_KEY = 'userPrivacyKey'
@Entry
@Component
struct WelcomePage {context = getContext(this) as common.UIAbilityContextcontroller: CustomDialogController = new CustomDialogController({builder: UserPrivacyDialog({confirm: () => this.onConfirm(),cancel: () => this.exitApp()})})async aboutToAppear(){// 1.加载首选项let isAgree = await PreferenceUtil.getPreferenceValue(PREF_KEY, false)// 2.判断是否同意if(isAgree){// 2.1.同意,跳转首页this.jumpToIndex()}else{// 2.2.不同意,弹窗this.controller.open()}}jumpToIndex(){setTimeout(() => {router.replaceUrl({url: 'pages/Index'})}, 1000)}onConfirm(){// 1.保存首选项PreferenceUtil.putPreferenceValue(PREF_KEY, true)// 2.跳转到首页this.jumpToIndex()}exitApp(){// 退出APPthis.context.terminateSelf()}build() {Column({ space: 10 }) {Row() {Text('健康支持').opacityWhiteText(0.8, 12)Text('IPv6').opacityWhiteText(0.8).border({ style: BorderStyle.Solid, width: 1, color: Color.White, radius: 15 }).padding({ left: 5, right: 5 })Text('网络').opacityWhiteText(0.8, 12)}Text(`'减更多'帮助更多用户实现身材管理`).opacityWhiteText(0.6)Text('备****号').opacityWhiteText(0.4).margin({ bottom: 35 })}.width('100%').height('100%').backgroundColor($r('app.color.welcome_page_background'))}
}
相关文章:

鸿蒙开发 之 健康App案例
1.项目介绍 该项目是记录用户日常饮食情况,以及针对不同食物摄入营养不同会有对应的营养摄入情况和日常运动消耗情况,用户可以自己添加食品以及对应的热量。 1.1登陆页 1.2饮食统计页 1.3 食物列表页 2.登陆页 2.1自定义弹框 import preferences from oh…...
umi3项目axios 请求参数序列化参数
由于get 请求中有一个日期参数 dates 是一个数组类型。 未处理参数时请求地址是这样的:/api/list?page1&pageSize10&keyWord&dates[]2024-06-10&dates[]2024-06-24 会发现dates后面有中括号,所以前端需要将参数格式处理变成如下:/api…...
js实现数据去重合并
应用场景,一个list,包含已经选择的数据和未选择的数据,新增数据到已选择的数据中。 要考虑到二次选择的数据和已经选择的数据有重复的可能,所以,第一步先从二次选择的数据中进行去重,然后再将两个list进行数…...

[ios逆向]查看ios安装包ipa签名证书embedded.mobileprovision解密 附带解密环境openssl
openssl smime -inform der -verify -noverify -in embedded.mobileprovision 解密embedded.mobileprovision文件 链接:https://pan.baidu.com/s/1UwNOWONKV1SNj5aX_ZZCzQ?pwdglco 提取码:glco –来自百度网盘超级会员V8的分享 可以使用everything 查看…...

tr、cut、split、grep -E
目录 tr命令:替换和删除 cut命令:快速裁剪 split命令:文件拆分 文件合并 面试题 1.现在有一个日志文件,有5个G,能不能快速的打开 2.cat合并和paste合并之间的区别? 3.统计当前主机的连接状态&#…...

《分析模式》漫谈08-单继承不是“唯一继承”
DDD领域驱动设计批评文集 做强化自测题获得“软件方法建模师”称号 《软件方法》各章合集 《分析模式》第2章这一段: 划线处的single inheritance,2004中译本的翻译: 翻译为“单继承”,是正确的。 2020中译本的翻译:…...
c++字典
在C中,“字典”通常指的是std::map或std::unordered_map,它们是标准库中提供的关联容器,用于存储键值对。以下是一些常见的操作示例,包括插入、访问、删除和遍历元素。 使用 std::map std::map 是一种有序的关联容器,键…...

rga_mm: RGA_MMU unsupported Memory larger than 4G!解决
目录 报错完整log如下:解决方案:报错完整log如下: [ 3668.824164] rga_mm: RGA_MMU unsupported Memory larger than 4G! [ 3668.824305] rga_mm: scheduler core[4] unsupported mm_flag[0x0]! [ 3668.824320] rga_mm: rga_mm_map_buffer map dma_buf err...

构建个人文件上传服务:Python Flask实现上传和下载完整指南
介绍 在本教程中,我们将学习如何使用Python Flask框架将文件上传到服务器,并使用SQLite数据库来跟踪上传的文件。我们将提供后端代码和一个示例项目的Git链接,以便您可以轻松地跟随本教程。 准备工作 首先,您需要安装Python和F…...

瓦罗兰特新赛季更新资讯 瓦罗兰特新赛季免费加速器
瓦罗兰特新赛季来喽,这是一款由拳头开发的免费第一人称射击游戏,游戏凭借其独特的玩法和丰富的英雄选择吸引了大量玩家。 我们可以在游戏中选择自己喜欢的角色出场与敌人进行对战,而且每一个角色都有自己独特的道具以及技能,使用好…...
希尔排序的实现
引言 排序在我们生活中十分常见,无论是购物软件中的商品推荐还是名次、排名都与排序算法息息相关。希尔排序是排序中较快的一种,而希尔排序实现的基础是插入排序。 排序的实现 插入排序(以升序为例) 插入排序的原理是从第二个数…...

使用Python selenium爬虫领英数据,并进行AI岗位数据挖掘
随着OpenAI大火,从事AI开发的人趋之若鹜,这次使用Python selenium抓取了领英上几万条岗位薪资数据,并使用Pandas、matplotlib、seaborn等库进行可视化探索分析。 但领英设置了一些反爬措施,对IP进行限制封禁,因此会用到…...
如何在Android应用程序中实现高效的图片加载和缓存机制。
在Android应用程序中实现高效的图片加载和缓存机制 一、技术难点 在Android应用程序中实现高效的图片加载和缓存机制,主要面临以下几个技术难点: 内存管理:Android设备的内存资源有限,如果加载大量高清图片而不进行适当的内存管…...

【机器学习项目实战(二)】基于朴素贝叶斯的中文垃圾短信分类
完整代码、数据集和相应的报告 链接已经放在了正文最下方, 供大家参考学习 摘要 本文探讨了中文垃圾短信分类的问题,通过收集实际数据集,运用多种机器学习算法进行分类,并对比了不同算法在垃圾短信分类任务上的性能。本研究旨在提高中文垃圾短信的识别准确率,为构建更…...

当用户需求不详细时,如何有效应对
在项目沟通时,用户对需求说明不详细,可能是由于多种原因。以下是一些可能的原因及如何应对这些问题的建议: 1. 用户不完全理解自己的需求 原因: 用户对技术细节不了解,不知道如何具体描述需求。 用户对项目的全局和…...

最新AI智能聊天对话问答系统源码(图文搭建部署教程)+AI绘画,文生图,TTS语音识别输入,文档分析
一、人工智能语言模型和AI绘画在多个领域广泛应用 人工智能语言模型和AI绘画在多个领域都有广泛的应用。以下是一些它们的主要用处: 人工智能语言模型 内容生成 写作辅助:帮助撰写文章、博客、报告、剧本等。 代码生成:自动生成或补全代码&…...

[图解]SysML和EA建模住宅安全系统-02-现有运营领域-块定义图
1 00:00:00,840 --> 00:00:02,440 首先我们来看画在哪里 2 00:00:02,570 --> 00:00:08,310 你看,这是图的类型,图里面内容 3 00:00:08,320 --> 00:00:10,780 这是元素类型 4 00:00:10,790 --> 00:00:14,900 这是位置,哪个包 …...
【vuejs】首次页面加载时触发那些声明周期钩子函数
1. 首次页面加载触发的钩子 在Vue.js中,页面或组件的首次加载会触发一系列预定义的生命周期钩子函数,这些钩子函数按照特定的顺序执行,允许开发者在组件的不同阶段执行代码。以下是首次页面加载时触发的钩子及其作用: 2.1 befor…...
adb热更新
模拟器连接AndroidStudio 解决:adb server version (36) doesnt match this client (40); killing... 1.G:\ProgramFils\android-sdk\platform-tools adb --version 2.H:\yeshen\Nox\bin adb --version 3.把G:\ProgramFils\android-sdk\platform-…...
Nuxt 的路由结构系统(七)
基本路由配置 在 Nuxt.js 中,每个 .vue 文件在 pages/ 目录下都会自动成为一个路由。文件名决定了路由的路径。例如: pages/ |-- index.vue # 映射到根路径 / |-- about.vue # 映射到路径 /about |-- contact.vue # 映射到路径 /conta…...
在rocky linux 9.5上在线安装 docker
前面是指南,后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...
GitHub 趋势日报 (2025年06月08日)
📊 由 TrendForge 系统生成 | 🌐 https://trendforge.devlive.org/ 🌐 本日报中的项目描述已自动翻译为中文 📈 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...
Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信
文章目录 Linux C语言网络编程详细入门教程:如何一步步实现TCP服务端与客户端通信前言一、网络通信基础概念二、服务端与客户端的完整流程图解三、每一步的详细讲解和代码示例1. 创建Socket(服务端和客户端都要)2. 绑定本地地址和端口&#x…...

HarmonyOS运动开发:如何用mpchart绘制运动配速图表
##鸿蒙核心技术##运动开发##Sensor Service Kit(传感器服务)# 前言 在运动类应用中,运动数据的可视化是提升用户体验的重要环节。通过直观的图表展示运动过程中的关键数据,如配速、距离、卡路里消耗等,用户可以更清晰…...

客户案例 | 短视频点播企业海外视频加速与成本优化:MediaPackage+Cloudfront 技术重构实践
01技术背景与业务挑战 某短视频点播企业深耕国内用户市场,但其后台应用系统部署于东南亚印尼 IDC 机房。 随着业务规模扩大,传统架构已较难满足当前企业发展的需求,企业面临着三重挑战: ① 业务:国内用户访问海外服…...
初级程序员入门指南
初级程序员入门指南 在数字化浪潮中,编程已然成为极具价值的技能。对于渴望踏入程序员行列的新手而言,明晰入门路径与必备知识是开启征程的关键。本文将为初级程序员提供全面的入门指引。 一、明确学习方向 (一)编程语言抉择 编…...

多模态学习路线(2)——DL基础系列
目录 前言 一、归一化 1. Layer Normalization (LN) 2. Batch Normalization (BN) 3. Instance Normalization (IN) 4. Group Normalization (GN) 5. Root Mean Square Normalization(RMSNorm) 二、激活函数 1. Sigmoid激活函数(二分类&…...
从0开始一篇文章学习Nginx
Nginx服务 HTTP介绍 ## HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议。 ## HTTP工作在 TCP/IP协议体系中的TCP协议上&#…...
【中间件】Web服务、消息队列、缓存与微服务治理:Nginx、Kafka、Redis、Nacos 详解
Nginx 是什么:高性能的HTTP和反向代理Web服务器。怎么用:通过配置文件定义代理规则、负载均衡、静态资源服务等。为什么用:提升Web服务性能、高并发处理、负载均衡和反向代理。优缺点:轻量高效,但动态处理能力较弱&am…...
NamedParameterJdbcTemplate 使用方法及介绍
NamedParameterJdbcTemplate是 Spring 框架中用于数据库操作的核心类之一,它拓展了JdbcTemplate,通过封装实现命名参数特性,相比传统占位符?,命名参数可读性和维护性更强,能有效避免参数顺序混淆问题。 一、核心支持…...