鸿蒙开发 之 健康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.Preferences

  async loadPreference(context){
    try { // 加载preferences
      this.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

  // THOUSANDTH
  static 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;

  // fontWeight
  static 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;

  // opacity
  static readonly OPACITY_4: number = 0.4;

  static readonly OPACITY_6: number = 0.6;

  // radius
  static readonly BORDER_RADIUS_PERCENT_50: string = '50%';

  // duration
  static readonly DURATION_1000: number = 1000; // 1000ms
  static readonly DURATION_800: number = 800; // 700ms
  static readonly DURATION_100: number = 100; // 100ms

  // space
  static 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 key
  static 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: CustomDialogController
  confirm: () => void
  cancel: () => void

  build() {
    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.UIAbilityContext
  controller: 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(){
    // 退出APP
    this.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'))
  }
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

当用户需求不详细时,如何有效应对

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

支持WebDav的网盘infiniCloud(静读天下,Zotero 等挂载)

前言 WebDav是一种基于HTTP的协议,允许用户在Web上直接编辑和管理文件,如复制、移动、删除等。 尽管有一些网盘支持WebDav,但其中大部分都有较多的使用限制。这些限制可能包括:上传文件的大小限制、存储空间的限制、下载速度的限…

met和set的特性及区别

1、关联式容器 在c初阶阶段,我们已经接触了STL的部分容器,比如:vector,list,deque,forward_list等。 这些容器统称为序列式容器,因为其底层为线性序列的数据结构,里面存储的就是数据本身。 而关联式容器…

Qt的入门

Qt的入门 1.Qt的配置2.介绍Qt的使用2.1 Qt 5.14.22.2 Linguist 5.14.22.3Designer 5.14.22.4 Assistant 5.14.22.5 Qt Creator 4.11.1 3.创建第一个项目3.1点击文件来新建一个新的文件或项目3.2选择项目路径和名称3.3选择构建工具3.4类信息3.5翻译文件3.6选择编译器3.7项目管理…

Redis 内存碎片是什么?如何清理?

Redis 内存碎片相关的问题在得物、美团、阿里、字节、携程等公司的后端面试中都曾出现过,还是建议认真准备一下。即使不是准备面试,日常开发也是能够用到的! 什么是内存碎片? 你可以将内存碎片简单地理解为那些不可用的空闲内存。 举个例子&…

Python文件匹配技巧详解

概要 在日常的文件操作和数据处理中,文件匹配是一个非常常见的任务。Python 提供了丰富的库和工具来实现文件匹配,这些工具不仅功能强大,还易于使用。本文将详细介绍如何使用 Python 实现文件匹配,包括基本的文件操作、通配符匹配、正则表达式匹配以及实际应用场景,帮助更…

NewspaceGPT带你玩系列之美人鱼图表(思维导图)

目录 注册一个账号,用qq邮箱,然后登录选一个可用的Plus,不要选3.5探索GPT今天的主角是开始寻梦美人鱼图表我选第四个试一下问答 自定义问题:问答叙述文六要素:示例: 结论关注我,不迷路&#xff…

服务器安装JDK,Maven等常用环境

生产环境部署服务器需要安装一些常用工具,下面我就把常用的jdk,maven,node,git的安装方法和步骤演示 一、安装JDK环境 执行如下命令,安装JDK,所有命令都是 复制,粘贴,回车 yum install -y jav…

vue uniapp MEQX JWT认证

1.下载依赖 npm install mqttimport * as mqtt from "mqtt/dist/mqtt.min" ​ 我是用的uniapp vue3 vite这里尝试了很多方式,都导入不进去后来我就采用的本地引入方式, 把mqtt.min.js下载到本地然后在index.html 中导入<script src"./MEQX/mqtt.js" typ…

同三维T908转换器 SDI转DVI/HDMI/VGA/色差分量/AV转换器

同三维T908转换器 SDI转DVI/HDMI/VGA/色差分量/AV转换器 1路SDI进&#xff0c;1路DVI(可转HDMI/VGA/色差分量/AV)3.5音频1路SDI出,可以支持音频解嵌&#xff0c;也可把3.5音频加嵌转换输出&#xff0c;输出分辨率可调&#xff0c;支持图像翻转180度 一、产品简介 SDI转万能转…

新能源行业必会基础知识-----电力市场概论笔记-----经济学基础

新能源行业知识体系-------主目录-----持续更新(进不去说明我没写完)&#xff1a;https://blog.csdn.net/grd_java/article/details/139946830 目录 1. 什么是市场2. 电力市场机制设计的基本要求 1. 什么是市场 经济学定义 市场是供需双方交易并决定商品价格和产量的机制市场可…

【阅读论文】-- IDmvis:面向1型糖尿病治疗决策支持的时序事件序列可视化

IDMVis: Temporal Event Sequence Visualization for Type 1 Diabetes Treatment Decision Support 摘要1 引言2 1 型糖尿病的背景3 相关工作3.1 时间事件序列可视化3.2 电子健康记录可视化3.3 1 型糖尿病可视化3.4 任务分析与抽象 4 数据抽象5 层次化任务抽象5.1 临床医生工作…

华为BGP路由实验基础1------用物理口建立对等体

1.用物理口做BGP建立对等体建立BGP连接 实验拓扑&#xff1a; 实验步骤&#xff1a; 1.完成基本配置 sys [Huawei]sys AR1 [AR1]undo in e [AR1]int g0/0/0 [AR1-GigabitEthernet0/0/0]ip add 1.1.1.1 24 [AR1-GigabitEthernet0/0/0]q [AR1] sys [Huawei]sys AR2 [AR2]undo i…

用自己电脑部署大模型,私有化,很香!

这段时间一直在研究大语言模型私有部署的相关内容&#xff0c;相信大家也非常的感兴趣。 到目前为止&#xff0c;其实还是有很多的开源模型&#xff0c;其实大家去 GitHub Trending 上看看&#xff0c;就能够发现很多。 今天也是手把手地教大家怎么在自己的电脑上部署一个大语…

Qt—贪吃蛇项目(由0到1实现贪吃蛇项目)

用Qt实现一个贪吃蛇项目 一、项目介绍二、游戏大厅界面实现2.1完成游戏大厅的背景图。2.2创建一个按钮&#xff0c;给它设置样式&#xff0c;并且可以跳转到别的页面 三、难度选择界面实现四、 游戏界面实现五、在文件中写入历史战绩5.1 从文件里提取分数5.2 把贪吃蛇的长度存入…

如何断点调试opencv源码

分几个步骤&#xff1a; 1、下载opencv-4.10.0-windows.exe https://opencv.org/releases/ 2、想要调试opencv的源码&#xff0c;只需要将这两个文件拷贝到我们自己项目的可执行文件的同级目录内即可。 完成拷贝后&#xff0c;直接在vs工程中打断点F11进行单步调试&#xff…

ASP.NET MVC-简单例子-配置日志文件-log4net

环境&#xff1a; win10&#xff0c;SQL Server 2008 R2 安装 使用NuGet 安装时发现报错并无法安装&#xff1a; 现有 packages.config 文件中检测到一个或多个未解析包依赖项约束。必须解析所有依赖项约束以添加或更新包。如果正在更新这些包&#xff0c;则可忽略此消息&am…

2024-6-28 石群电路-32

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

算法基础--------【图论】

图论&#xff08;待完善&#xff09; DFS:和回溯差不多 BFS:进while进行层序遍历 定义: 图论&#xff08;Graph Theory&#xff09;是研究图及其相关问题的数学理论。图由节点&#xff08;顶点&#xff09;和连接这些节点的边组成。图论的研究范围广泛&#xff0c;涉及路径、…

学习笔记——动态路由——OSPF(OSPF协议的工作原理)

八、OSPF协议的工作原理 1、原理概要 (1)相邻路由器之间周期性发送HELLO报文&#xff0c;以便建立和维护邻居关系 (2)建立邻居关系后&#xff0c;给邻居路由器发送数据库描述报文(DBD)&#xff0c;也就是将自己链路状态数据库中的所有链路状态项目的摘要信息发送给邻居路由器…