From 6feb399ccc0fce50f4dcfe3f0c9af6f5a35f77c6 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Mon, 26 May 2025 16:45:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20HMRouter=20=E4=BB=93=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/animation/CustomCutToAnimator.ets | 2 +- .../animation/CustomDifferentTransition.ets | 2 ++ .../main/ets/component/live/DialogAnimator.ets | 8 ++++---- entry/src/main/ets/component/pay/PayCancel.ets | 6 +++--- .../component/privacy/PrivacyDialogContent.ets | 2 +- .../ets/component/product/ProductContent.ets | 11 ++++++++++- .../product/elements/ProductUtilView.ets | 8 +++++++- .../shoppingBag/ShoppingBagContent.ets | 4 ---- .../ets/interceptor/LoginCheckInterceptor.ets | 4 ++-- .../ets/lifecycle/PageDurationLifecycle.ets | 18 ++++++------------ 10 files changed, 36 insertions(+), 29 deletions(-) diff --git a/entry/src/main/ets/animation/CustomCutToAnimator.ets b/entry/src/main/ets/animation/CustomCutToAnimator.ets index 89c3010..f8a849e 100644 --- a/entry/src/main/ets/animation/CustomCutToAnimator.ets +++ b/entry/src/main/ets/animation/CustomCutToAnimator.ets @@ -17,13 +17,13 @@ * 最佳实践:特定页面设置自定义转场 */ -// [Start custom_cut_to_animator] import { HMAnimator, HMAnimatorHandle, HMRouterMgr, IHMAnimator, OpacityOption, ScaleOption, TranslateOption } from "@hadss/hmrouter"; +// [Start custom_cut_to_animator] @HMAnimator({ animatorName: 'CustomAnimator' }) export class CustomAnimator implements IHMAnimator { diff --git a/entry/src/main/ets/animation/CustomDifferentTransition.ets b/entry/src/main/ets/animation/CustomDifferentTransition.ets index 787972c..3e67247 100644 --- a/entry/src/main/ets/animation/CustomDifferentTransition.ets +++ b/entry/src/main/ets/animation/CustomDifferentTransition.ets @@ -77,9 +77,11 @@ export class MyAnimator2 implements IHMAnimator { // [Start comment_input_amimator] @Component export struct CommentInput { + // [StartExclude comment_input_amimator] @State isLandscape: boolean = true; @State videoWidth: string = '' @State videoHeight: string = '' + // [EndExclude comment_input_amimator] build() { Row() { diff --git a/entry/src/main/ets/component/live/DialogAnimator.ets b/entry/src/main/ets/component/live/DialogAnimator.ets index f7d5056..a7e863b 100644 --- a/entry/src/main/ets/component/live/DialogAnimator.ets +++ b/entry/src/main/ets/component/live/DialogAnimator.ets @@ -21,10 +21,10 @@ import { HMNavigation, IHMAnimator } from '@hadss/hmrouter'; // [Start global_dialog] -const globalDialogTransitionEffect: IHMAnimator.Effect = new IHMAnimator.Effect({ +const globalPageTransitionEffect: IHMAnimator.Effect = new IHMAnimator.Effect({ direction: IHMAnimator.Direction.BOTTOM_TO_TOP, - opacity: { opacity: 1 }, - scale: { x: 1, y: 1 } + opacity: { opacity: 0.5 }, + scale: { x: 0.5, y: 0.2 } }) // [End global_dialog] @@ -36,7 +36,7 @@ export struct DialogAnimator { // [Start dialog_animator] HMNavigation({ navigationId: 'mainNavigationId', homePageUrl: 'HomeContent', options: { - dialogAnimator: globalDialogTransitionEffect, + dialogAnimator: globalPageTransitionEffect, } }) // [End dialog_animator] diff --git a/entry/src/main/ets/component/pay/PayCancel.ets b/entry/src/main/ets/component/pay/PayCancel.ets index b877911..a7eee3b 100644 --- a/entry/src/main/ets/component/pay/PayCancel.ets +++ b/entry/src/main/ets/component/pay/PayCancel.ets @@ -23,7 +23,7 @@ import { ConfirmDialog } from '../common/ConfirmDialog'; import { PayConstants } from '../common/constants/PayConstants' // [Start HMRouter_confirmDialog] -@HMRouter({pageUrl: PageConstant.PAY_CANCEL, dialog: true}) +@HMRouter({pageUrl: 'PayCancel', dialog: true}) @Component export struct PayCancel { // [StartExclude HMRouter_confirmDialog] @@ -49,13 +49,12 @@ export struct PayCancel { leftButtonName: '再看看', rightButtonName: '取消订单', leftButtonFunc: () => { - // [StartExclude HMRouter_confirmDialog] HMRouterMgr.pop({ navigationId: this.queryNavigationInfo()?.navigationId }); - // [EndExclude HMRouter_confirmDialog] }, rightButtonFunc: () => { + // [StartExclude HMRouter_confirmDialog] let pathStack = HMRouterMgr.getPathStack(this.queryNavigationInfo()?.navigationId!); if (this.pageUrl === 'shoppingBag') { for (let i = 0; i < 2; i++) { @@ -66,6 +65,7 @@ export struct PayCancel { pathStack?.pop(false); } } + // [EndExclude HMRouter_confirmDialog] } }); } diff --git a/entry/src/main/ets/component/privacy/PrivacyDialogContent.ets b/entry/src/main/ets/component/privacy/PrivacyDialogContent.ets index c35b834..98ef67b 100644 --- a/entry/src/main/ets/component/privacy/PrivacyDialogContent.ets +++ b/entry/src/main/ets/component/privacy/PrivacyDialogContent.ets @@ -25,7 +25,7 @@ import { PageConstant } from '../../constant/PageConstant'; */ // [Start HMRouter_dialog] -@HMRouter({pageUrl: PageConstant.PRIVACY_DIALOG, dialog: true}) +@HMRouter({ pageUrl: 'privacyDialog', dialog: true }) @Component export struct PrivacyDialogContent { // [StartExclude HMRouter_dialog] diff --git a/entry/src/main/ets/component/product/ProductContent.ets b/entry/src/main/ets/component/product/ProductContent.ets index 6336878..0ed3020 100644 --- a/entry/src/main/ets/component/product/ProductContent.ets +++ b/entry/src/main/ets/component/product/ProductContent.ets @@ -28,10 +28,17 @@ import { ProductMsg, ProductUtilView } from './elements/ProductUtilView'; @Component export struct ProductContent { // [StartExclude HMRouter] + // [StartExclude hm_router_get_current_param] @State product: ProductMsg = new ProductMsg(DetailConstants.COLOR_SELECT_NAME_LIST[0], DetailConstants.CAPACITY_SELECT_NAME_LIST[0], DetailConstants.PRODUCT_PRICE_NAMES[1]); + // [EndExclude hm_router_get_current_param] + @State param: ParamsType | null = null; + aboutToAppear(): void { + this.param = HMRouterMgr.getCurrentParam() as ParamsType; + } + // [StartExclude hm_router_get_current_param] build() { Column() { Scroll() { @@ -52,5 +59,7 @@ export struct ProductContent { .layoutWeight(1); } // [EndExclude HMRouter] + // [EndExclude hm_router_get_current_param] } -// [End HMRouter] \ No newline at end of file +// [End HMRouter] +// [End hm_router_get_current_param] \ No newline at end of file diff --git a/entry/src/main/ets/component/product/elements/ProductUtilView.ets b/entry/src/main/ets/component/product/elements/ProductUtilView.ets index f4f5e9a..79745b5 100644 --- a/entry/src/main/ets/component/product/elements/ProductUtilView.ets +++ b/entry/src/main/ets/component/product/elements/ProductUtilView.ets @@ -26,6 +26,7 @@ import { PayMgr } from '../../pay/PayCard'; @Component export struct ProductUtilView { @Link product: ProductMsg; + @State param: string = '' build() { Row() { @@ -42,7 +43,12 @@ export struct ProductUtilView { }); Image($r('app.media.ic_public_comments')) .width(24) - .margin({ right: 16 }); + .margin({ right: 16 }) + .onClick(() => { + // [Start HMRouterMgr_pageUrl_home_page] + HMRouterMgr.pop({ navigationId: 'mainNavigationId', pageUrl: 'HomePage', param: this.param }) + // [End HMRouterMgr_pageUrl_home_page] + }) Image($r('app.media.tab_shopping_bag')) .width(24) .margin({ right: 12 }); diff --git a/entry/src/main/ets/component/shoppingBag/ShoppingBagContent.ets b/entry/src/main/ets/component/shoppingBag/ShoppingBagContent.ets index 3b6fa36..f7462af 100644 --- a/entry/src/main/ets/component/shoppingBag/ShoppingBagContent.ets +++ b/entry/src/main/ets/component/shoppingBag/ShoppingBagContent.ets @@ -73,7 +73,6 @@ export class RequestModel { } // [Start HMRouter_life_cycle_name] -// [Start HMRouter_interceptors] @HMRouter({ pageUrl: PageConstant.SHOPPING_BAG, singleton: true, @@ -82,7 +81,6 @@ export class RequestModel { }) @Component export struct ShoppingBagContent { - // [StartExclude HMRouter_interceptors] // [StartExclude HMRouter_life_cycle_name] @StorageLink('currentBreakpoint') currentBreakpoint: string = BreakpointConstants.BREAKPOINT_SM; @State showTabsBtn: boolean = true; @@ -136,8 +134,6 @@ export struct ShoppingBagContent { ShoppingBagContentNavBar({showTabsBtn: this.showTabsBtn}); }; } - // [EndExclude HMRouter_interceptors] // [EndExclude HMRouter_life_cycle_name] } -// [End HMRouter_interceptors] // [End HMRouter_life_cycle_name] \ No newline at end of file diff --git a/entry/src/main/ets/interceptor/LoginCheckInterceptor.ets b/entry/src/main/ets/interceptor/LoginCheckInterceptor.ets index cb24646..2ea7c82 100644 --- a/entry/src/main/ets/interceptor/LoginCheckInterceptor.ets +++ b/entry/src/main/ets/interceptor/LoginCheckInterceptor.ets @@ -30,13 +30,14 @@ export class LoginCheckInterceptor implements IHMInterceptor { if(!!AppStorage.get('isLogin')) { return HMInterceptorAction.DO_NEXT; } else { - info.context.getPromptAction().showToast({message: LoginConstants.LOGIN_TOAST}); + info.context.getPromptAction().showToast({ message: '请先登录' }); HMRouterMgr.push({ pageUrl: 'loginPage', skipAllInterceptor: true }); return HMInterceptorAction.DO_REJECT; } + // [StartExclude hm_interceptor] } else { if(!!AppStorage.get('isLogin')) { return HMInterceptorAction.DO_NEXT; @@ -49,7 +50,6 @@ export class LoginCheckInterceptor implements IHMInterceptor { }); return HMInterceptorAction.DO_REJECT; } - // [StartExclude hm_interceptor] } // [EndExclude hm_interceptor] } diff --git a/entry/src/main/ets/lifecycle/PageDurationLifecycle.ets b/entry/src/main/ets/lifecycle/PageDurationLifecycle.ets index 599fa06..a8bff10 100644 --- a/entry/src/main/ets/lifecycle/PageDurationLifecycle.ets +++ b/entry/src/main/ets/lifecycle/PageDurationLifecycle.ets @@ -22,21 +22,15 @@ import { HMLifecycle, HMLifecycleContext, IHMLifecycle } from '@hadss/hmrouter'; // [Start page_duration_life_cycle] @HMLifecycle({ lifecycleName: 'PageDurationLifecycle', global: true }) export class PageDurationLifecycle implements IHMLifecycle { - private timeMap: Map = new Map(); - onShown(ctx: HMLifecycleContext): void { - const pageName = ctx.navContext?.pathInfo.name; - if(pageName) { - this.timeMap.set(pageName, new Date().getTime()); - } + private time: number = 0; + + onShown(): void { + this.time = new Date().getTime(); } onHidden(ctx: HMLifecycleContext): void { - const pageName = ctx.navContext?.pathInfo.name; - if(pageName && this.timeMap.has(pageName)) { - const duration = new Date().getTime() - (this.timeMap.get(pageName) as number); - this.timeMap.delete(pageName); - console.log(`Page ${pageName} stay ${duration} ms`); - } + const duration = new Date().getTime() - this.time; + console.log(`Page ${ctx.navContext?.pathInfo.name} stay ${duration}`); } } // [End page_duration_life_cycle] \ No newline at end of file -- Gitee From 8e61664734f6dab975c7a45fa4915d74ede5cb75 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Mon, 26 May 2025 16:50:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20HMRouter=20=E4=BB=93=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/component/product/ProductContent.ets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entry/src/main/ets/component/product/ProductContent.ets b/entry/src/main/ets/component/product/ProductContent.ets index 0ed3020..1a8760f 100644 --- a/entry/src/main/ets/component/product/ProductContent.ets +++ b/entry/src/main/ets/component/product/ProductContent.ets @@ -17,11 +17,12 @@ * 最佳实践:基于HMRouter路由框架的页面跳转开发实践 */ -import { HMRouter } from '@hadss/hmrouter'; +import { HMRouter, HMRouterMgr } from '@hadss/hmrouter'; import { PageConstant } from '../../constant/PageConstant'; import { DetailConstants } from '../common/constants/DetailConstants'; import { ProductInfo, ProductPicture } from './elements/ProductDetail'; import { ProductMsg, ProductUtilView } from './elements/ProductUtilView'; +interface ParamsType {} // [Start HMRouter] @HMRouter({pageUrl: 'ProductContent'}) -- Gitee