From a756906d7d62b2d1cbe6022d39ca334c16357f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E4=B8=9C=E6=B5=B7?= Date: Wed, 30 Apr 2025 16:47:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/CustomCalendar.ets | 6 ++++-- entry/src/main/ets/pages/Details.ets | 2 +- entry/src/main/ets/pages/FullScreen.ets | 8 ++++---- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/pages/Privacy.ets | 2 +- entry/src/main/ets/pages/ScrollOption.ets | 4 ++-- entry/src/main/ets/view/CustomCalendarPickerDialog.ets | 6 ++++-- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/entry/src/main/ets/pages/CustomCalendar.ets b/entry/src/main/ets/pages/CustomCalendar.ets index a2da74a..e01aae7 100644 --- a/entry/src/main/ets/pages/CustomCalendar.ets +++ b/entry/src/main/ets/pages/CustomCalendar.ets @@ -17,6 +17,7 @@ import { CustomCalendarPickerDialog } from '../view/CustomCalendarPickerDialog'; import { DateModel } from '../viewmodel/DateModel'; import { getRealTimeDate } from '../viewmodel/GetDate'; import { CommonConstants } from '../common/constants/CommonConstants'; +import { common } from '@kit.AbilityKit'; @Entry @Component @@ -26,6 +27,7 @@ export struct CalendarView { @State currentDay: number = 1; @State currentYear: number = 1; @StorageLink('selectedDate') dateModel: DateModel = new DateModel(0, 0, 0, 0); + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; aboutToAppear(): void { this.dateModel = getRealTimeDate(); @@ -50,7 +52,7 @@ export struct CalendarView { getResourceString(resource: Resource): string { let resourceString: string = ''; - resourceString = getContext(this).resourceManager.getStringSync(resource.id); + resourceString = this.context.resourceManager.getStringSync(resource.id); return resourceString; } @@ -88,7 +90,7 @@ export struct CalendarView { .type(ButtonType.Normal) .borderRadius($r('app.float.corner_radius_default_m')) .onClick(() => { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.button_text') }); }) diff --git a/entry/src/main/ets/pages/Details.ets b/entry/src/main/ets/pages/Details.ets index c832289..2f6b865 100644 --- a/entry/src/main/ets/pages/Details.ets +++ b/entry/src/main/ets/pages/Details.ets @@ -23,7 +23,7 @@ struct Details { Row() { Column() { Button($r('app.string.back')).onClick(() => { - router.back(); + this.getUIContext().getRouter().back(); }) } .width('100%') diff --git a/entry/src/main/ets/pages/FullScreen.ets b/entry/src/main/ets/pages/FullScreen.ets index 37d1e37..fcbb162 100644 --- a/entry/src/main/ets/pages/FullScreen.ets +++ b/entry/src/main/ets/pages/FullScreen.ets @@ -27,7 +27,7 @@ struct FullScreen { Column() { Button($r('app.string.full_screen')) .onClick(() => { - animateTo({ + this.getUIContext().animateTo({ duration: CommonConstants.DURATION, curve: Curve.Sharp }, () => { @@ -162,7 +162,7 @@ struct FullScreen { } private closeSelf() { - animateTo({ + this.getUIContext().animateTo({ duration: CommonConstants.GRID_HEIGHT_M, curve: Curve.Sharp, }, () => { @@ -171,7 +171,7 @@ struct FullScreen { } private reset() { - animateTo({ + this.getUIContext().animateTo({ curve: curves.responsiveSpringMotion() }, () => { this.translateY = '0%'; @@ -183,7 +183,7 @@ struct FullScreen { if (!offsetY || offsetY < 0) { return; } - animateTo({ + this.getUIContext().animateTo({ curve: curves.responsiveSpringMotion() }, () => { this.translateY = this.positionY + offsetY; diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index c193aa1..90001bb 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -54,7 +54,7 @@ struct Index { }) .backgroundColor(Color.White) .onClick(() => { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url }) }) diff --git a/entry/src/main/ets/pages/Privacy.ets b/entry/src/main/ets/pages/Privacy.ets index 6bbb972..dd7bbce 100644 --- a/entry/src/main/ets/pages/Privacy.ets +++ b/entry/src/main/ets/pages/Privacy.ets @@ -83,7 +83,7 @@ struct Privacy { .fontWeight(FontWeight.Bold) .decoration({ type: TextDecorationType.Underline, color: Color.Orange }) .onClick(() => { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/Details' }) }) diff --git a/entry/src/main/ets/pages/ScrollOption.ets b/entry/src/main/ets/pages/ScrollOption.ets index 60bb92c..df85f52 100644 --- a/entry/src/main/ets/pages/ScrollOption.ets +++ b/entry/src/main/ets/pages/ScrollOption.ets @@ -28,7 +28,7 @@ struct ScrollOption { .width(CommonConstants.ONE_HUNDRED_PERCENT) .margin({ bottom: $r('app.float.button_margin') }) .onClick(() => { - TimePickerDialog.show({ + this.getUIContext().showTimePickerDialog({ selected: this.selectTime, backgroundColor: $r('app.color.start_window_background'), onAccept: (value: TimePickerResult) => { @@ -40,7 +40,7 @@ struct ScrollOption { .width(CommonConstants.ONE_HUNDRED_PERCENT) .margin({ bottom: $r('app.float.card_padding') }) .onClick(() => { - TextPickerDialog.show({ + this.getUIContext().showTextPickerDialog({ range: this.fruits, selected: this.select, backgroundColor: $r('app.color.start_window_background'), diff --git a/entry/src/main/ets/view/CustomCalendarPickerDialog.ets b/entry/src/main/ets/view/CustomCalendarPickerDialog.ets index a9623f0..e11d8e1 100644 --- a/entry/src/main/ets/view/CustomCalendarPickerDialog.ets +++ b/entry/src/main/ets/view/CustomCalendarPickerDialog.ets @@ -17,6 +17,7 @@ import { MonthDataSource, Month } from '../viewmodel/MonthDataSource'; import { DataManager } from '../viewmodel/DataManager'; import { DateModel } from '../viewmodel/DateModel'; import { CommonConstants } from '../common/constants/CommonConstants'; +import { common } from '@kit.AbilityKit'; @CustomDialog export struct CustomCalendarPickerDialog { @@ -33,10 +34,11 @@ export struct CustomCalendarPickerDialog { controller: CustomDialogController; cancel: () => void = () => {}; private week: ResourceStr[] = [$r('app.string.ri'), $r('app.string.yi'), $r('app.string.er'), $r('app.string.san'), $r('app.string.si'), $r('app.string.wu'), $r('app.string.liu')]; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; getResourceString(resource: Resource): string { let resourceString: string = ''; - resourceString = getContext(this).resourceManager.getStringSync(resource.id); + resourceString = this.context.resourceManager.getStringSync(resource.id); return resourceString; } @@ -127,7 +129,7 @@ export struct CustomCalendarPickerDialog { this.dateModel.day = day; this.dateModel.week = weekIndex; this.dateModel.month = monthItem.num; - DataManager.setDate(getContext(this), this.dateModel, () => {}); + DataManager.setDate(this.context, this.dateModel, () => {}); this.controller.close(); } }) -- Gitee