diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd..483b727881ec8b7db1dd467abc7ba184048844b8 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 39d79af4317497a4dfd40a6d97735cfe3400066a..527b214456f4aff889027dba6d39acb7a834b080 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 de4d8eac7eeb3c55239fc23bb71bd145eac58b76..993030320f8824305859eed94ecf3fbf83fff9e4 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; }