ref |> 解决动态详情页首次进入时跳转评论区问题
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
2 changed files
with
40 additions
and
17 deletions
| @@ -17,6 +17,7 @@ import { | @@ -17,6 +17,7 @@ import { | ||
| 17 | batchLikeAndCollectResult, | 17 | batchLikeAndCollectResult, |
| 18 | RmhInfoDTO, | 18 | RmhInfoDTO, |
| 19 | InteractDataDTO, | 19 | InteractDataDTO, |
| 20 | + Action, | ||
| 20 | } from 'wdBean'; | 21 | } from 'wdBean'; |
| 21 | import media from '@ohos.multimedia.media'; | 22 | import media from '@ohos.multimedia.media'; |
| 22 | import { OperRowListView } from './view/OperRowListView'; | 23 | import { OperRowListView } from './view/OperRowListView'; |
| @@ -56,9 +57,7 @@ const PATTERN_DATE_CN_RN: string = 'yyyy年MM月dd日 HH:mm'; | @@ -56,9 +57,7 @@ const PATTERN_DATE_CN_RN: string = 'yyyy年MM月dd日 HH:mm'; | ||
| 56 | @Component | 57 | @Component |
| 57 | export struct DynamicDetailComponent { | 58 | export struct DynamicDetailComponent { |
| 58 | //入参 | 59 | //入参 |
| 59 | - private relId: string = '' | ||
| 60 | - private contentId: string = '' | ||
| 61 | - private relType: string = '' | 60 | + action: Action = {} as Action |
| 62 | //出参 | 61 | //出参 |
| 63 | @Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO | 62 | @Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO |
| 64 | //UI | 63 | //UI |
| @@ -82,6 +81,8 @@ export struct DynamicDetailComponent { | @@ -82,6 +81,8 @@ export struct DynamicDetailComponent { | ||
| 82 | @State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以 | 81 | @State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以 |
| 83 | 82 | ||
| 84 | pageParam: ParamType = {} | 83 | pageParam: ParamType = {} |
| 84 | + commentListAreaInfo?: Area | ||
| 85 | + lastTimeoutId?: number | ||
| 85 | 86 | ||
| 86 | // @Provide bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 | 87 | // @Provide bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 |
| 87 | @Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0 | 88 | @Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0 |
| @@ -553,6 +554,12 @@ export struct DynamicDetailComponent { | @@ -553,6 +554,12 @@ export struct DynamicDetailComponent { | ||
| 553 | CommentComponent({ | 554 | CommentComponent({ |
| 554 | publishCommentModel: this.publishCommentModel | 555 | publishCommentModel: this.publishCommentModel |
| 555 | }) | 556 | }) |
| 557 | + .id("comment") | ||
| 558 | + .onAreaChange((oldValue: Area, newValue: Area) => { | ||
| 559 | + this.commentListAreaInfo = newValue | ||
| 560 | + this.checkToScrollCommentArea() | ||
| 561 | + }) | ||
| 562 | + | ||
| 556 | } | 563 | } |
| 557 | Blank().layoutWeight(1) | 564 | Blank().layoutWeight(1) |
| 558 | } | 565 | } |
| @@ -587,7 +594,10 @@ export struct DynamicDetailComponent { | @@ -587,7 +594,10 @@ export struct DynamicDetailComponent { | ||
| 587 | private async getContentDetailData() { | 594 | private async getContentDetailData() { |
| 588 | this.isNetConnected = NetworkUtil.isNetConnected() | 595 | this.isNetConnected = NetworkUtil.isNetConnected() |
| 589 | try { | 596 | try { |
| 590 | - let data = await MultiPictureDetailViewModel.getDetailData(this.relId, this.contentId, this.relType) | 597 | + const relId = this.action.params?.extra?.relId || ''; |
| 598 | + const relType = this.action.params?.extra?.relType || ''; | ||
| 599 | + const contentId = this.action.params?.contentID || ''; | ||
| 600 | + let data = await MultiPictureDetailViewModel.getDetailData(relId, contentId, relType) | ||
| 591 | this.isPageEnd = true; | 601 | this.isPageEnd = true; |
| 592 | this.contentDetailData = data[0]; | 602 | this.contentDetailData = data[0]; |
| 593 | let dateTime = | 603 | let dateTime = |
| @@ -804,6 +814,29 @@ export struct DynamicDetailComponent { | @@ -804,6 +814,29 @@ export struct DynamicDetailComponent { | ||
| 804 | let context = getContext(this) as common.UIAbilityContext; | 814 | let context = getContext(this) as common.UIAbilityContext; |
| 805 | viewBlogItemInsightIntentShare(context,this.contentDetailData, this.interactDataDTO) | 815 | viewBlogItemInsightIntentShare(context,this.contentDetailData, this.interactDataDTO) |
| 806 | } | 816 | } |
| 817 | + | ||
| 818 | + checkToScrollCommentArea() { | ||
| 819 | + if (!this.commentListAreaInfo) { | ||
| 820 | + // 需要评论区位置,调用前 请确保它有值 | ||
| 821 | + return | ||
| 822 | + } | ||
| 823 | + if (this.action.params?.targetLayout && this.action.params.targetLayout == "comment") { | ||
| 824 | + if (this.lastTimeoutId) { | ||
| 825 | + clearTimeout(this.lastTimeoutId) | ||
| 826 | + } | ||
| 827 | + this.lastTimeoutId = setTimeout(() => { | ||
| 828 | + let offSetY = this.commentListAreaInfo?.globalPosition.y as number | ||
| 829 | + Logger.debug(TAG, "即将滚动至yOffset: " + (offSetY - 100)) | ||
| 830 | + //头部距离48 | ||
| 831 | + this.scroller.scrollTo({ | ||
| 832 | + yOffset: offSetY - 100, | ||
| 833 | + xOffset: 0, | ||
| 834 | + animation: { duration: 1000, curve: Curve.Ease } | ||
| 835 | + }) | ||
| 836 | + this.action.params!.targetLayout = undefined | ||
| 837 | + }, 600) | ||
| 838 | + } | ||
| 839 | + } | ||
| 807 | } | 840 | } |
| 808 | 841 | ||
| 809 | interface radiusType { | 842 | interface radiusType { |
| @@ -9,35 +9,25 @@ const TAG = 'DynamicDetailPage'; | @@ -9,35 +9,25 @@ const TAG = 'DynamicDetailPage'; | ||
| 9 | @Component | 9 | @Component |
| 10 | struct DynamicDetailPage { | 10 | struct DynamicDetailPage { |
| 11 | pageShowTime:number = 0; | 11 | pageShowTime:number = 0; |
| 12 | - @State relId: string = '' | ||
| 13 | - @State contentId: string = '' | ||
| 14 | - @State relType: string = '' | ||
| 15 | 12 | ||
| 16 | @Provide pageName: string = TrackConstants.PageName.DynamicDetail | 13 | @Provide pageName: string = TrackConstants.PageName.DynamicDetail |
| 17 | @Provide pageId: string = TrackConstants.PageName.DynamicDetail | 14 | @Provide pageId: string = TrackConstants.PageName.DynamicDetail |
| 18 | 15 | ||
| 19 | build() { | 16 | build() { |
| 20 | Column() { | 17 | Column() { |
| 21 | - DynamicDetailComponent({ | ||
| 22 | - relId: this.relId, | ||
| 23 | - contentId: this.contentId, | ||
| 24 | - relType: this.relType | ||
| 25 | - }) | 18 | + DynamicDetailComponent({action: router.getParams() as Action }) |
| 26 | } | 19 | } |
| 27 | .height('100%') | 20 | .height('100%') |
| 28 | .width('100%') | 21 | .width('100%') |
| 29 | .backgroundColor('#20272E') | 22 | .backgroundColor('#20272E') |
| 30 | } | 23 | } |
| 31 | aboutToAppear() { | 24 | aboutToAppear() { |
| 32 | - let par:Action = router.getParams() as Action; | ||
| 33 | - let params = par?.params; | ||
| 34 | - this.relId = params?.extra?.relId || ''; | ||
| 35 | - this.relType = params?.extra?.relType || ''; | ||
| 36 | - this.contentId = params?.contentID || ''; | ||
| 37 | } | 25 | } |
| 26 | + | ||
| 38 | onPageShow() { | 27 | onPageShow() { |
| 39 | this.pageShowTime = DateTimeUtils.getTimeStamp() | 28 | this.pageShowTime = DateTimeUtils.getTimeStamp() |
| 40 | } | 29 | } |
| 30 | + | ||
| 41 | onPageHide() { | 31 | onPageHide() { |
| 42 | //页面浏览 | 32 | //页面浏览 |
| 43 | TrackingPageBrowse.trackCommonPageExposureEnd(TrackConstants.PageName.DynamicDetail,TrackConstants.PageName.DynamicDetail,Math.floor((DateTimeUtils.getTimeStamp() - this.pageShowTime)/1000)) | 33 | TrackingPageBrowse.trackCommonPageExposureEnd(TrackConstants.PageName.DynamicDetail,TrackConstants.PageName.DynamicDetail,Math.floor((DateTimeUtils.getTimeStamp() - this.pageShowTime)/1000)) |
-
Please register or login to post a comment