From 98618ca0e7aa9400d10ed5224d346bd7c74e1c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=A4=E9=9B=A8=E9=98=B3?= <13287882+ryantyy@user.noreply.gitee.com> Date: Mon, 8 Jan 2024 05:43:13 +0000 Subject: [PATCH] add healthylife_f21010727_mainpage. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 汤雨阳 <13287882+ryantyy@user.noreply.gitee.com> --- healthylife_f21010727_mainpage | 129 +++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 healthylife_f21010727_mainpage diff --git a/healthylife_f21010727_mainpage b/healthylife_f21010727_mainpage new file mode 100644 index 0000000..f45aa89 --- /dev/null +++ b/healthylife_f21010727_mainpage @@ -0,0 +1,129 @@ +import router from '@ohos.router'; +import common from '@ohos.app.ability.common'; +import notificationManager from '@ohos.notificationManager'; +import Logger from '../common/utils/Logger'; +import { ITaskItem } from '../model/TaskInitList'; +import { CommonConstants as Const } from '../common/constants/CommonConstants'; +import { NavList, TabId } from '../model/NavItemModel'; +import HomeIndex from '../view/HomeComponent'; +import { AchievementIndex } from '../view/AchievementComponent'; +import { MineIndex } from './MinePage'; +import { HomeStore } from '../viewmodel/HomeViewModel'; +import GlobalInfoApi from '../common/database/tables/GlobalInfoApi'; +import GlobalInfo from '../viewmodel/GlobalInfo'; +import { GlobalContext } from '../common/utils/GlobalContext'; + +@Styles function allSize() { + .width(Const.THOUSANDTH_1000) + .height(Const.THOUSANDTH_1000) +} + +@Entry +@Component +struct Index { + @State currentPage: number = 0; + @State editedTaskInfo: ITaskItem = router.getParams() ? (router.getParams() as Record).editTask as ITaskItem : {} as ITaskItem; + @State editedTaskID: string = '0'; + @State homeStore: HomeStore = new HomeStore(new Date()); + private tabController: TabsController = new TabsController(); + + aboutToAppear() { + notificationManager.requestEnableNotification().then(() => { + Logger.info('onPageShow', `requestEnableNotification success`); + }).catch((err: Error) => { + Logger.error('onPageShow', `requestEnableNotification failed, message is ${err.message}`); + }); + } + + onPageShow() { + Logger.info('onPageShow', JSON.stringify(router.getParams())); + let params = (router.getParams() ? router.getParams() : {}) as Record; + let result = params.editTask ? params.editTask as string : '{}'; + this.editedTaskInfo = JSON.parse(result); + this.editedTaskID = JSON.stringify(this.editedTaskInfo); + if ((GlobalContext.getContext().getObject('isForeground') as boolean)) { + GlobalContext.getContext().setObject('isForeground', false); + if (this.homeStore.currentDate.getDate() !== (new Date()).getDate()) { + GlobalContext.getContext().setObject('taskListChange', true); + this.homeStore = new HomeStore(new Date()); + } + this.checkCurrentTime(); + } + } + + checkCurrentTime() { + GlobalInfoApi.query((result: GlobalInfo) => { + let predate = new Date(result.lastDate); + let date = new Date(); + if (result && date.getTime() < predate.getTime()) { + AlertDialog.show( + { + title: $r('app.string.alert'), + message: $r('app.string.alert_message'), + autoCancel: false, + alignment: DialogAlignment.Bottom, + offset: { dx: 0, dy: -20 }, + gridCount: 3, + confirm: { + value: $r('app.string.alert_button'), + action: () => { + (getContext(this) as common.UIAbilityContext).terminateSelf(); + console.info('Button-clicking callback'); + } + }, + cancel: () => { + console.info('Closed callbacks'); + } + }); + } else { + this.homeStore.initData(); + } + }); + } + + @Builder TabBuilder(index: number) { + Column() { + //Image(index === this.currentPage ? NavList[index].icon_selected : NavList[index].icon) + //.width($r('app.float.default_24')) + //.height($r('app.float.default_24')) + //.objectFit(ImageFit.Contain); + Text(NavList[index].text) + .fontSize($r('app.float.default_10')) + .fontWeight(Const.FONT_WEIGHT_500) + .fontColor(this.currentPage === index ? $r('app.color.blueColor') : $r('app.color.tabTitleColor')) + .margin({ top: $r('app.float.default_4') }) + }.justifyContent(FlexAlign.Center).allSize() + } + + build() { + Tabs({ barPosition: BarPosition.Start, controller: this.tabController }) { + TabContent() { + HomeIndex({ homeStore: $homeStore, editedTaskInfo: $editedTaskInfo, editedTaskID: $editedTaskID }) + .borderWidth({ bottom: 1 }) + .borderColor($r('app.color.primaryBgColor')) + } + .tabBar(this.TabBuilder(TabId.HOME)) + .align(Alignment.Start) + + TabContent() { + AchievementIndex() + } + .tabBar(this.TabBuilder(TabId.ACHIEVEMENT)) + + TabContent() { + MineIndex() + .borderWidth({ bottom: 1 }) + .borderColor($r('app.color.primaryBgColor')) + } + .tabBar(this.TabBuilder(TabId.MINE)) + } + .scrollable(false) + .allSize() + .barWidth(Const.THOUSANDTH_940) + .barMode(BarMode.Fixed) + .vertical(false) + .onChange((index) => { + this.currentPage = index; + }) + } +} \ No newline at end of file -- Gitee