From a5c9ede4bd0a1bb62310cf36641dc5e328784a45 Mon Sep 17 00:00:00 2001 From: Hacker_DL Date: Thu, 17 Jul 2025 04:45:25 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=A0=81=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E3=80=81=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hacker_DL --- entry/src/main/ets/pages/LauncherPage.ets | 32 +++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/pages/LauncherPage.ets b/entry/src/main/ets/pages/LauncherPage.ets index 8dde1aa..bd8f186 100644 --- a/entry/src/main/ets/pages/LauncherPage.ets +++ b/entry/src/main/ets/pages/LauncherPage.ets @@ -31,7 +31,9 @@ import { GlobalContext } from '../common/utils/GlobalContext'; struct LauncherPage { private context?: common.UIAbilityContext; private timerId: number = 0; + // 在启动页的隐私协议弹窗中,当用户点击同意按钮后。在回调函数onConfirm内,调用jumpToAdvertisingPage方法开启3秒倒计时,倒计时结束后跳转到广告页。 private isJumpToAdvertising: boolean = false; + // 当用户点击隐私协议弹窗同意按钮时,回调onConfirm方法,调用saveIsPrivacy保存隐私协议状态。 dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialogComponent( { @@ -69,6 +71,7 @@ struct LauncherPage { } /** + * 跳转到广告页 * Jump to advertising page. */ jumpToAdvertisingPage() { @@ -85,6 +88,7 @@ struct LauncherPage { saveIsPrivacy() { let preferences: Promise = this.getDataPreferences(this); preferences.then((result: preferences.Preferences) => { + // 保存隐私协议状态 let privacyPut = result.put(CommonConstants.PREFERENCES_KEY_PRIVACY, false); result.flush(); privacyPut.then(() => { @@ -99,6 +103,8 @@ struct LauncherPage { onPageShow() { this.context = this.getUIContext().getHostContext() as common.UIAbilityContext; + /* 在LauncherPage的onPageShow方法中,通过preferences.getPreferences方法获取“PREFERENCES_FILE_NAME”首选项表,然后通过preferences.get方法获取隐私协议状态值。 */ + // 获取保存数据操作类 // Get the operation class for saving data. this.getDataPreferences(this).then((preferences: preferences.Preferences) => { preferences.get(CommonConstants.PREFERENCES_KEY_PRIVACY, true).then((value: preferences.ValueType) => { @@ -107,9 +113,11 @@ struct LauncherPage { // let isJumpPrivacy: boolean = globalThis.isJumpPrivacy ?? false; let isJumpPrivacy: boolean = (GlobalContext.getContext().getObject('isJumpPrivacy') as boolean) ?? false; if (!isJumpPrivacy) { + // 自定义协议弹窗 this.dialogController.open(); } } else { + // 跳至广告页 this.jumpToAdvertisingPage(); } }); @@ -117,22 +125,31 @@ struct LauncherPage { } /** + * 获取数据首选项表 * Get data preferences action. */ getDataPreferences(common: Object) { return preferences.getPreferences(this.getUIContext().getHostContext()!, CommonConstants.PREFERENCES_FILE_NAME); } + // 通过LauncherPage.ets代码文件中的build方法,构建启动页组件 + // The launch page component is built using the build method in the LauncherPage.ets code file build() { Stack() { + // 背景图 + // background image Image($r('app.media.ic_launcher_background')) .width(CommonConstants.FULL_WIDTH) .height(CommonConstants.FULL_HEIGHT) Column() { + // 启动页logo + // logo of launch page Image($r('app.media.ic_logo')) .width($r('app.float.launcher_logo_size')) .height($r('app.float.launcher_logo_size')) .margin({ top: CommonConstants.LAUNCHER_IMAGE_MARGIN_TOP }) + // 标题:健康生活 + // Title: Healthy Lifestyle Text($r('app.string.healthy_life_text')) .width($r('app.float.launcher_life_text_width')) .height($r('app.float.launcher_life_text_height')) @@ -141,6 +158,8 @@ struct LauncherPage { $r('app.float.launcher_text_title_size'), $r('app.color.launcher_text_title_color')) .margin({ top: CommonConstants.LAUNCHER_TEXT_TITLE_MARGIN_TOP }) + // 副标题:健康生活说明 + // Subtitle: Explanation of a Healthy Lifestyle Text($r('app.string.healthy_life_introduce')) .height(CommonConstants.LAUNCHER_TEXT_INTRODUCE_HEIGHT) .healthyLifeTextStyle(FontWeight.Normal, @@ -155,11 +174,14 @@ struct LauncherPage { } } } + +// 健康生活字体公共样式抽取 // Healthy living text common styles. -@Extend(Text) function healthyLifeTextStyle (fontWeight: number, +@Extend(Text) +function healthyLifeTextStyle(fontWeight: number, textAttribute: number, fontSize: Resource, fontColor: Resource) { - .fontWeight(fontWeight) - .letterSpacing(textAttribute) - .fontSize(fontSize) - .fontColor(fontColor) + .fontWeight(fontWeight) + .letterSpacing(textAttribute) + .fontSize(fontSize) + .fontColor(fontColor) } \ No newline at end of file -- Gitee