鸿蒙开发 之 健康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'))}
}

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

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

相关文章

IP地址查询和代理服务器:双重保护隐私

随着网络应用的日益普及,我们的个人信息和数据安全面临前所未有的挑战。在此背景下,IP地址查询和代理服务器成为保护个人隐私和网络安全的两大关键工具。本文将从IP地址查询的原理和应用出发,深入剖析代理服务器在网络隐私保护中的作用&#…

掌握批处理的高级技巧:使用正则表达式

掌握批处理的高级技巧:使用正则表达式 在Windows批处理脚本编写中,正则表达式是一个强大的工具,它可以帮助我们进行复杂的字符串匹配和处理。虽然批处理脚本本身并不直接支持正则表达式,但我们可以通过一些技巧和外部工具来实现正…

AI视频教程下载-数据分析中的提示工程:Python、Pandas、ChatGPT

Prompt Engineering for Data Analysis Python, Pandas, ChatGPT ChatGPT与Python:无需编程。借助ChatGPT、Python、Pandas及提示工程进行数据分析与数据可视化 "利用Python、Pandas和ChatGPT进行数据分析的提示工程"是一门开创性的课程,它通…

SpringBoot(二)SpringBoot多环境配置

Spring框架常用注解简单介绍 SpringMVC常用注解简单介绍 SpringBoot(一)创建一个简单的SpringBoot工程 SpringBoot(二)SpringBoot多环境配置 SpringBoot(三)SpringBoot整合MyBatis SpringBoot(四…

vue-advanced-chat 聊天控件的使用

测试代码:https://github.com/robinfoxnan/vue-advanced-chat-test0 控件源码:https://github.com/advanced-chat/vue-advanced-chat 先上个效果图: 这个控件就是专门为聊天而设计的,但是也有一些不足: 1&#xf…

【层序遍历】个人练习-Leetcode-102. Binary Tree Level Order Traversal

题目链接&#xff1a;https://leetcode.cn/problems/binary-tree-level-order-traversal/description/ 题目大意&#xff1a;给一棵树的根&#xff0c;要求以vector<vector<int>>形式给出层序遍历结果。 思路&#xff1a;层序遍历并不难&#xff0c;tricky的点在…

Python学习笔记26:进阶篇(十五)常见标准库使用之性能测试cProfile模块学习使用

前言 本文是根据python官方教程中标准库模块的介绍&#xff0c;自己查询资料并整理&#xff0c;编写代码示例做出的学习笔记。 根据模块知识&#xff0c;一次讲解单个或者多个模块的内容。 教程链接&#xff1a;https://docs.python.org/zh-cn/3/tutorial/index.html 本文主要…

【vuejs】首次页面加载时触发那些声明周期钩子函数

1. 首次页面加载触发的钩子 在Vue.js中&#xff0c;页面或组件的首次加载会触发一系列预定义的生命周期钩子函数&#xff0c;这些钩子函数按照特定的顺序执行&#xff0c;允许开发者在组件的不同阶段执行代码。以下是首次页面加载时触发的钩子及其作用&#xff1a; 2.1 befor…

.net core 的 winform 的 浏览器控件 WebView2

在.NET Core WinForms应用程序中&#xff0c;没有直接的“浏览器控件”&#xff0c;因为WinForms不支持像WebBrowser控件那样的功能。但是&#xff0c;你可以使用WebView2控件&#xff0c;它是一个基于Chromium的浏览器内核&#xff0c;可以在WinForms应用程序中嵌入Web内容。 …

R语言 | 使用ggplot绘制柱状图,在柱子中显示数值和显著性

原文链接&#xff1a;使用ggplot绘制柱状图&#xff0c;在柱子中显示数值和显著性 本期教程 获得本期教程示例数据&#xff0c;后台回复关键词&#xff1a;20240628。&#xff08;PS&#xff1a;在社群中&#xff0c;可获得往期和未来教程所有数据和代码&#xff09; 往期教程…

搭建ASPP:多尺度信息提取网络

文章目录 介绍代码实现 介绍 ASPP&#xff08;Atrous Spatial Pyramid Pooling&#xff09;&#xff0c;空洞空间卷积池化金字塔。简单理解就是个至尊版池化层&#xff0c;其目的与普通的池化层一致&#xff0c;尽可能地去提取特征。ASPP 的结构如下&#xff1a; 如图所示&…

Nuxt框架 和 Vite框架比较(四)

共同点 基于 Vue.js&#xff1a;Nuxt 和 Vite 都是围绕 Vue.js 构建的&#xff0c;这意味着它们可以利用 Vue.js 的响应式数据绑定和组件系统。 现代前端开发&#xff1a;两者都支持现代前端开发实践&#xff0c;如组件化、模块化和单文件组件&#xff08;SFCs&#xff09;。 V…

十二、Yocto集成ROS2 app程序(package)

文章目录 Yocto集成ROS2 app程序1. 添加一个ros2 package应用程序2. 添加bb文件集成app应用程序 Yocto集成ROS2 app程序 本篇文章为基于raspberrypi 4B单板的yocto实战系列的第十二篇文章&#xff1a; 一、yocto 编译raspberrypi 4B并启动 二、yocto 集成ros2(基于raspberrypi…

【MotionCap】DROID-SLAM 1 :介绍及安装

DROID-SLAM :DROID-SLAM: Deep Visual SLAM for Monocular DROID-SLAM:适用于单目、立体和 RGB-D 相机的深度视觉 SLAM Stereo, and RGB-D Cameras https://arxiv.org/abs/2108.10869DROID-SLAM: Deep Visual SLAM for Monocular, Stereo, and RGB-D Camerasfile:///X:/04_mo…

GuLi商城-前端启动命令npm run dev

由于这里配置了dev&#xff0c;所以启动命令是npm run dev

柯桥在职学历提升|专科本科之自考本科哪些专业不考数学

一、管理类专业 这类专业综合性和理论性比较强&#xff0c;除了涉及到管理学相关的理论知识外&#xff0c;还有相应的专业知识&#xff0c;目前比较典型的专业有&#xff1a;行政管理、人力资源管理、工商管理&#xff08;现代企业管理&#xff09;、工商管理&#xff08;商务管…

高通410-linux棒子设置网络驱动

1.首先打开设备管理器 2.看到其他设备下的RNDIS&#xff0c;右键更新驱动程序 3.点击浏览我的电脑… 最后一个

Sentinel实现区分来源

要区分来源就要写代码实现RequestOriginParser接口 ,注意是要实现com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser 接口,别搞错接口了。 MyRequestOriginParser.java package com.codex.terry.sentinel.origin;import com.alibaba.csp.sentinel.ad…

Linux操作系统--软件包管理(保姆级教程)

RPM软件包的管理 大多数linux的发行版本都是某种打包系统。软件包可以用来发布应用软件&#xff0c;有时还可以发布配置文件。他们比传统结构的.tar和.gz存档文件有几个优势。如它们能让安装过程尽可能成为不可分割的原子操作。 软件包的安装程序会备份它们改动过的文件。如果…

2024-6-28 石群电路-32

2024-6-28&#xff0c;星期五&#xff0c;20:05&#xff0c;天气&#xff1a;雨&#xff0c;心情&#xff1a;晴。今天没有什么事情发生&#xff0c;继续学习&#xff0c;加油&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; 1. 对称三相电路的计算&#xff08…