From 2edb7e77fe027c2b51597985d31f0b5cecb00013 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Sat, 14 Jun 2025 14:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=BC=83=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/entryability/EntryAbility.ets | 2 ++ entry/src/main/ets/pages/PersonalInformation.ets | 8 ++++---- entry/src/main/ets/utils/CommonUtils.ets | 9 ++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 0f2f8b9..483b727 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -35,6 +35,8 @@ export default class EntryAbility extends UIAbility { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } + let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext(); + AppStorage.setOrCreate('uiContext', uiContext); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); }); } diff --git a/entry/src/main/ets/pages/PersonalInformation.ets b/entry/src/main/ets/pages/PersonalInformation.ets index 39d79af..527b214 100644 --- a/entry/src/main/ets/pages/PersonalInformation.ets +++ b/entry/src/main/ets/pages/PersonalInformation.ets @@ -14,7 +14,7 @@ */ import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction, ComponentContent } from '@kit.ArkUI'; +import { ComponentContent } from '@kit.ArkUI'; import TextInputComponent from '../view/TextInputComponent'; import TextCommonComponent from '../view/TextCommonComponent'; import CommonUtils from '../utils/CommonUtils'; @@ -176,7 +176,7 @@ export struct PersonalInformation { this.isSaved = true; this.customPopup = false; // Close popup dialog AppStorage.setOrCreate('isEdit', false); - promptAction.showToast({ + this.ctx.getPromptAction().showToast({ message: $r('app.string.save_successfully'), duration: 2000 }) @@ -207,7 +207,7 @@ export struct PersonalInformation { if (!this.birthDate) { this.birthDate = CommonUtils.getBirthDateValue(year, month, day); } - let context = getContext(this); + let context = this.getUIContext().getHostContext() as Context; if ((CommonUtils.isEmpty(context)) || (CommonUtils.isEmpty(context.resourceManager))) { hilog.info(0xFF00, 'PersonalInformation', '%{public}s', 'context or resourceManager is null'); return; @@ -333,7 +333,7 @@ export struct PersonalInformation { content: this.hobbies, onItemClick: () => { this.hobbyItems = []; - let context = getContext(this); + let context = this.getUIContext().getHostContext() as Context; if ((CommonUtils.isEmpty(context)) || (CommonUtils.isEmpty(context.resourceManager))) { return; } diff --git a/entry/src/main/ets/utils/CommonUtils.ets b/entry/src/main/ets/utils/CommonUtils.ets index de4d8ea..9930303 100644 --- a/entry/src/main/ets/utils/CommonUtils.ets +++ b/entry/src/main/ets/utils/CommonUtils.ets @@ -18,11 +18,14 @@ class HobbyItem { isChecked?: boolean; } +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +const context = uiContext?.getHostContext(); + export class CommonUtils { getBirthDateValue(year: number, month: number, day: number): string { - let resourceYear = getContext(this).resourceManager.getStringSync($r('app.string.year')); - let resourceMonth = getContext(this).resourceManager.getStringSync($r('app.string.month')); - let resourceDay = getContext(this).resourceManager.getStringSync($r('app.string.day')); + let resourceYear = context?.resourceManager.getStringSync($r('app.string.year')); + let resourceMonth = context?.resourceManager.getStringSync($r('app.string.month')); + let resourceDay = context?.resourceManager.getStringSync($r('app.string.day')); let birthdate: string = `${year}${resourceYear}${month}` + `${resourceMonth}${day}${resourceDay}`; return birthdate; } -- Gitee