Showing
1 changed file
with
36 additions
and
40 deletions
| @@ -4,7 +4,9 @@ import { WDRouterRule } from 'wdRouter/Index' | @@ -4,7 +4,9 @@ import { WDRouterRule } from 'wdRouter/Index' | ||
| 4 | import { ENewspaperPageDialog } from '../dialog/ENewspaperPageDialog' | 4 | import { ENewspaperPageDialog } from '../dialog/ENewspaperPageDialog' |
| 5 | import { Logger } from 'wdKit'; | 5 | import { Logger } from 'wdKit'; |
| 6 | import { font, window } from '@kit.ArkUI'; | 6 | import { font, window } from '@kit.ArkUI'; |
| 7 | + | ||
| 7 | const TAG: string = 'ENewspaperListDialog'; | 8 | const TAG: string = 'ENewspaperListDialog'; |
| 9 | + | ||
| 8 | /** | 10 | /** |
| 9 | * 读报纸半屏弹窗 | 11 | * 读报纸半屏弹窗 |
| 10 | * 弹窗嵌套参考资料(https://developer.harmonyos.com/cn/docs/documentation/doc-references-V2/ts-methods-custom-dialog-box-0000001580345722-V2) | 12 | * 弹窗嵌套参考资料(https://developer.harmonyos.com/cn/docs/documentation/doc-references-V2/ts-methods-custom-dialog-box-0000001580345722-V2) |
| @@ -18,9 +20,7 @@ export struct ENewspaperListDialog { | @@ -18,9 +20,7 @@ export struct ENewspaperListDialog { | ||
| 18 | private listScroller: Scroller = new Scroller() | 20 | private listScroller: Scroller = new Scroller() |
| 19 | @State scrollOffset: number = 0 | 21 | @State scrollOffset: number = 0 |
| 20 | @State isCurrentViewOpen: boolean = false | 22 | @State isCurrentViewOpen: boolean = false |
| 21 | - @Consume bottomSafeHeight:number | ||
| 22 | - | ||
| 23 | - firstFlag : boolean = true | 23 | + @Consume bottomSafeHeight: number |
| 24 | //文字版选择弹框 | 24 | //文字版选择弹框 |
| 25 | pageListDialogController: CustomDialogController = new CustomDialogController({ | 25 | pageListDialogController: CustomDialogController = new CustomDialogController({ |
| 26 | builder: ENewspaperPageDialog({ | 26 | builder: ENewspaperPageDialog({ |
| @@ -42,7 +42,6 @@ export struct ENewspaperListDialog { | @@ -42,7 +42,6 @@ export struct ENewspaperListDialog { | ||
| 42 | // 那么此处需要将指向自己的controller放在所有controller的后面 | 42 | // 那么此处需要将指向自己的controller放在所有controller的后面 |
| 43 | // listDialogController: CustomDialogController | 43 | // listDialogController: CustomDialogController |
| 44 | public closeDialog?: () => void | 44 | public closeDialog?: () => void |
| 45 | - | ||
| 46 | // 手势滑动相关 | 45 | // 手势滑动相关 |
| 47 | private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }) | 46 | private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }) |
| 48 | private topFixedHeight = 124 | 47 | private topFixedHeight = 124 |
| @@ -51,17 +50,21 @@ export struct ENewspaperListDialog { | @@ -51,17 +50,21 @@ export struct ENewspaperListDialog { | ||
| 51 | 50 | ||
| 52 | //watch监听报纸页码回调 | 51 | //watch监听报纸页码回调 |
| 53 | onCurrentPageNumUpdated(): void { | 52 | onCurrentPageNumUpdated(): void { |
| 54 | - this.firstFlag = false | ||
| 55 | - console.log(TAG, "onCurrentPageNumUpdated currentPageNum:", this.currentPageNum) | ||
| 56 | - let _scrollIndex = Number.parseInt(this.currentPageNum) | ||
| 57 | - console.log(TAG, "onCurrentPageNumUpdated _scrollIndex:", _scrollIndex) | ||
| 58 | - let scrollIndexEnd = _scrollIndex > 0 ? _scrollIndex - 1 : _scrollIndex | 53 | + // console.log(TAG, "onCurrentPageNumUpdated currentPageNum:", this.currentPageNum) |
| 54 | + // let _scrollIndex = Number.parseInt(this.currentPageNum) | ||
| 55 | + // console.log(TAG, "onCurrentPageNumUpdated _scrollIndex:", _scrollIndex) | ||
| 56 | + // let scrollIndexEnd = _scrollIndex > 0 ? _scrollIndex - 1 : _scrollIndex | ||
| 57 | + | ||
| 58 | + if (this.newspaperListBean != undefined) { | ||
| 59 | + // 从业务数据中找到编号 | ||
| 60 | + let scrollIndexEnd = this.newspaperListBean?.list.findIndex(_item => _item?.pageNum === this.currentPageNum) | ||
| 59 | 61 | ||
| 60 | - console.log(TAG, "onCurrentPageNumUpdated scrollIndexEnd:", scrollIndexEnd) | 62 | + console.log(TAG, "onCurrentPageNumUpdated scrollIndexEnd:", scrollIndexEnd) |
| 61 | 63 | ||
| 62 | - console.log(TAG, "onCurrentPageNumUpdated (!this.isCurrentViewOpen):", ""+!this.isCurrentViewOpen) | ||
| 63 | - if (!this.isCurrentViewOpen) { | ||
| 64 | - this.listScroller.scrollToIndex(scrollIndexEnd) | 64 | + console.log(TAG, "onCurrentPageNumUpdated (!this.isCurrentViewOpen):", "" + !this.isCurrentViewOpen) |
| 65 | + if (!this.isCurrentViewOpen) { | ||
| 66 | + this.listScroller.scrollToIndex(scrollIndexEnd) | ||
| 67 | + } | ||
| 65 | } | 68 | } |
| 66 | } | 69 | } |
| 67 | 70 | ||
| @@ -73,7 +76,7 @@ export struct ENewspaperListDialog { | @@ -73,7 +76,7 @@ export struct ENewspaperListDialog { | ||
| 73 | }) | 76 | }) |
| 74 | // 屏幕高度 - 滑动高度计算 | 77 | // 屏幕高度 - 滑动高度计算 |
| 75 | let windowClass: window.Window = await window.getLastWindow(getContext(this)); | 78 | let windowClass: window.Window = await window.getLastWindow(getContext(this)); |
| 76 | - let changeHeight = 85 + 44 + px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height) | 79 | + let changeHeight = 85 + 44 + px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height) |
| 77 | changeHeight += px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).bottomRect.height) | 80 | changeHeight += px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).bottomRect.height) |
| 78 | this.deviceHeight = px2vp(windowClass.getWindowProperties().windowRect.height) - changeHeight | 81 | this.deviceHeight = px2vp(windowClass.getWindowProperties().windowRect.height) - changeHeight |
| 79 | 82 | ||
| @@ -143,13 +146,13 @@ export struct ENewspaperListDialog { | @@ -143,13 +146,13 @@ export struct ENewspaperListDialog { | ||
| 143 | .gesture( | 146 | .gesture( |
| 144 | PanGesture(this.panOption) | 147 | PanGesture(this.panOption) |
| 145 | .onActionStart((event: GestureEvent) => { | 148 | .onActionStart((event: GestureEvent) => { |
| 146 | - Logger.debug('ENewspaperListDialog','Pan start') | 149 | + Logger.debug('ENewspaperListDialog', 'Pan start') |
| 147 | }) | 150 | }) |
| 148 | .onActionUpdate((event: GestureEvent) => { | 151 | .onActionUpdate((event: GestureEvent) => { |
| 149 | if (this.topFixedHeight + event.offsetY >= this.topFixedHeight) { | 152 | if (this.topFixedHeight + event.offsetY >= this.topFixedHeight) { |
| 150 | this.topHeight = this.topFixedHeight + event.offsetY | 153 | this.topHeight = this.topFixedHeight + event.offsetY |
| 151 | } | 154 | } |
| 152 | - Logger.debug('ENewspaperListDialog', 'topHeight:' + this.topHeight) | 155 | + Logger.debug('ENewspaperListDialog', 'topHeight:' + this.topHeight) |
| 153 | }) | 156 | }) |
| 154 | .onActionEnd(() => { | 157 | .onActionEnd(() => { |
| 155 | this.onCloseGestureDialog() | 158 | this.onCloseGestureDialog() |
| @@ -182,8 +185,7 @@ export struct ENewspaperListDialog { | @@ -182,8 +185,7 @@ export struct ENewspaperListDialog { | ||
| 182 | Text(positionItem.shortTitle) | 185 | Text(positionItem.shortTitle) |
| 183 | .fontSize($r('app.float.font_size_13')) | 186 | .fontSize($r('app.float.font_size_13')) |
| 184 | .fontColor($r('app.color.color_222222')) | 187 | .fontColor($r('app.color.color_222222')) |
| 185 | - .fontWeight(600) | ||
| 186 | - // .maxLines(2) | 188 | + .fontWeight(600)// .maxLines(2) |
| 187 | .margin({ | 189 | .margin({ |
| 188 | bottom: 8 | 190 | bottom: 8 |
| 189 | }) | 191 | }) |
| @@ -197,7 +199,7 @@ export struct ENewspaperListDialog { | @@ -197,7 +199,7 @@ export struct ENewspaperListDialog { | ||
| 197 | .margin({ | 199 | .margin({ |
| 198 | bottom: 8 | 200 | bottom: 8 |
| 199 | }) | 201 | }) |
| 200 | - // .maxLines(2) | 202 | + // .maxLines(2) |
| 201 | } | 203 | } |
| 202 | 204 | ||
| 203 | if (positionItem.downTitle) { | 205 | if (positionItem.downTitle) { |
| @@ -208,7 +210,7 @@ export struct ENewspaperListDialog { | @@ -208,7 +210,7 @@ export struct ENewspaperListDialog { | ||
| 208 | .margin({ | 210 | .margin({ |
| 209 | bottom: 8 | 211 | bottom: 8 |
| 210 | }) | 212 | }) |
| 211 | - // .maxLines(2) | 213 | + // .maxLines(2) |
| 212 | } | 214 | } |
| 213 | if (positionItem.newsTxt) { | 215 | if (positionItem.newsTxt) { |
| 214 | Text(positionItem.newsTxt) | 216 | Text(positionItem.newsTxt) |
| @@ -276,7 +278,7 @@ export struct ENewspaperListDialog { | @@ -276,7 +278,7 @@ export struct ENewspaperListDialog { | ||
| 276 | left: 15, | 278 | left: 15, |
| 277 | right: 15, | 279 | right: 15, |
| 278 | // top: 16, | 280 | // top: 16, |
| 279 | - // bottom: 16 | 281 | + // bottom: 16 |
| 280 | }) | 282 | }) |
| 281 | .margin({ | 283 | .margin({ |
| 282 | bottom: 85 | 284 | bottom: 85 |
| @@ -287,30 +289,24 @@ export struct ENewspaperListDialog { | @@ -287,30 +289,24 @@ export struct ENewspaperListDialog { | ||
| 287 | console.info('ENewspaperListDialog::first' + firstIndex) | 289 | console.info('ENewspaperListDialog::first' + firstIndex) |
| 288 | console.info('ENewspaperListDialog::last' + lastIndex) | 290 | console.info('ENewspaperListDialog::last' + lastIndex) |
| 289 | console.info('ENewspaperListDialog::center' + centerIndex) | 291 | console.info('ENewspaperListDialog::center' + centerIndex) |
| 290 | - // this.updateCurrentPageNum(firstIndex) | ||
| 291 | - // const tempIndex = this.findClassIndex(firstIndex) | ||
| 292 | - // if (firstIndex !== centerIndex) { | ||
| 293 | - // return | ||
| 294 | - // } | ||
| 295 | - // console.info(`this.scrollOffset:` + this.scrollOffset) | ||
| 296 | - // if (this.scrollOffset == 0) { | ||
| 297 | - if(this.firstFlag){ | ||
| 298 | - this.currentPageNum = `${firstIndex < 9 ? '0' + (firstIndex + 1) : firstIndex + 1}` | ||
| 299 | - }else { | ||
| 300 | - this.firstFlag = true | 292 | + |
| 293 | + // this.currentPageNum = `${firstIndex < 9 ? '0' + (firstIndex + 1) : firstIndex + 1}` | ||
| 294 | + | ||
| 295 | + if (this.newspaperListBean != undefined) { | ||
| 296 | + this.currentPageNum = this.newspaperListBean?.list[lastIndex].pageNum | ||
| 301 | } | 297 | } |
| 302 | 298 | ||
| 303 | - // } | ||
| 304 | }) | 299 | }) |
| 305 | } | 300 | } |
| 306 | .margin({ top: this.topHeight }) | 301 | .margin({ top: this.topHeight }) |
| 307 | .width('100%') | 302 | .width('100%') |
| 308 | .backgroundColor(Color.White) | 303 | .backgroundColor(Color.White) |
| 309 | 304 | ||
| 310 | - }.width('100%') | 305 | + } |
| 306 | + .width('100%') | ||
| 311 | .height('100%') | 307 | .height('100%') |
| 312 | .backgroundColor('#80000000') | 308 | .backgroundColor('#80000000') |
| 313 | - .margin({bottom:50}) | 309 | + .margin({ bottom: 50 }) |
| 314 | .onClick(() => { | 310 | .onClick(() => { |
| 315 | if (this.closeDialog) { | 311 | if (this.closeDialog) { |
| 316 | this.closeDialog() | 312 | this.closeDialog() |
| @@ -319,24 +315,24 @@ export struct ENewspaperListDialog { | @@ -319,24 +315,24 @@ export struct ENewspaperListDialog { | ||
| 319 | .gesture( | 315 | .gesture( |
| 320 | PanGesture(this.panOption) | 316 | PanGesture(this.panOption) |
| 321 | .onActionStart((event: GestureEvent) => { | 317 | .onActionStart((event: GestureEvent) => { |
| 322 | - Logger.debug('ENewspaperListDialog','Pan start') | 318 | + Logger.debug('ENewspaperListDialog', 'Pan start') |
| 323 | }) | 319 | }) |
| 324 | .onActionUpdate((event: GestureEvent) => { | 320 | .onActionUpdate((event: GestureEvent) => { |
| 325 | if (event) { | 321 | if (event) { |
| 326 | - if (this.topFixedHeight + event.offsetY >= this.topFixedHeight) { | 322 | + if (this.topFixedHeight + event.offsetY >= this.topFixedHeight) { |
| 327 | this.topHeight = this.topFixedHeight + event.offsetY | 323 | this.topHeight = this.topFixedHeight + event.offsetY |
| 328 | } | 324 | } |
| 329 | - Logger.debug('ENewspaperListDialog', 'topHeight:' + this.topHeight) | 325 | + Logger.debug('ENewspaperListDialog', 'topHeight:' + this.topHeight) |
| 330 | } | 326 | } |
| 331 | }) | 327 | }) |
| 332 | .onActionEnd(() => { | 328 | .onActionEnd(() => { |
| 333 | - this.onCloseGestureDialog() | 329 | + this.onCloseGestureDialog() |
| 334 | }) | 330 | }) |
| 335 | ) | 331 | ) |
| 336 | } | 332 | } |
| 337 | 333 | ||
| 338 | onCloseGestureDialog() { | 334 | onCloseGestureDialog() { |
| 339 | - if (this.topHeight >= this.deviceHeight ) { | 335 | + if (this.topHeight >= this.deviceHeight) { |
| 340 | if (this.closeDialog) { | 336 | if (this.closeDialog) { |
| 341 | this.closeDialog() | 337 | this.closeDialog() |
| 342 | } | 338 | } |
-
Please register or login to post a comment