鴻蒙開發 之 健康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.pswp.cn/diannao/37149.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/37149.shtml
英文地址,請注明出處:http://en.pswp.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…