Showing
2 changed files
with
109 additions
and
74 deletions
| @@ -66,6 +66,29 @@ export struct ENewspaperPageComponent { | @@ -66,6 +66,29 @@ export struct ENewspaperPageComponent { | ||
| 66 | offset: { dx: 0, dy: 0 } | 66 | offset: { dx: 0, dy: 0 } |
| 67 | }) | 67 | }) |
| 68 | 68 | ||
| 69 | + async aboutToAppear() { | ||
| 70 | + //获取宽高尺寸 | ||
| 71 | + this.screenWidth = this.displayTool.width | ||
| 72 | + this.picWidth = this.screenWidth - vp2px(52) | ||
| 73 | + this.picHeight = this.picWidth * 566 / 378 | ||
| 74 | + //注册字体 | ||
| 75 | + font.registerFont({ | ||
| 76 | + familyName: 'BebasNeue_Regular', | ||
| 77 | + familySrc: $rawfile('font/BebasNeue_Regular.otf') | ||
| 78 | + }) | ||
| 79 | + this.getNewspaperTime() | ||
| 80 | + this.getNewspaperList() | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + aboutToDisappear() { | ||
| 84 | + // if (this.calendarDialogController) { | ||
| 85 | + // this.calendarDialogController = null | ||
| 86 | + // } | ||
| 87 | + // if (this.listDialogController) { | ||
| 88 | + // this.listDialogController = null | ||
| 89 | + // } | ||
| 90 | + } | ||
| 91 | + | ||
| 69 | build() { | 92 | build() { |
| 70 | RelativeContainer() { | 93 | RelativeContainer() { |
| 71 | RelativeContainer() { | 94 | RelativeContainer() { |
| @@ -245,26 +268,11 @@ export struct ENewspaperPageComponent { | @@ -245,26 +268,11 @@ export struct ENewspaperPageComponent { | ||
| 245 | .id('e_newspaper_container') | 268 | .id('e_newspaper_container') |
| 246 | } | 269 | } |
| 247 | 270 | ||
| 248 | - async aboutToAppear() { | ||
| 249 | - //获取宽高尺寸 | ||
| 250 | - this.screenWidth = this.displayTool.width | ||
| 251 | - this.picWidth = this.screenWidth - vp2px(52) | ||
| 252 | - this.picHeight = this.picWidth * 566 / 378 | ||
| 253 | - //注册字体 | ||
| 254 | - font.registerFont({ | ||
| 255 | - familyName: 'BebasNeue_Regular', | ||
| 256 | - familySrc: $rawfile('font/BebasNeue_Regular.otf') | ||
| 257 | - }) | ||
| 258 | - this.getNewspaperTime() | ||
| 259 | - this.getNewspaperList() | ||
| 260 | - } | ||
| 261 | - | ||
| 262 | private async getNewspaperTime() { | 271 | private async getNewspaperTime() { |
| 263 | let newspaperTimes = await NewspaperViewModel.getNewspaperTime(this.calendarDate) | 272 | let newspaperTimes = await NewspaperViewModel.getNewspaperTime(this.calendarDate) |
| 264 | if (newspaperTimes && newspaperTimes.length > 0) { | 273 | if (newspaperTimes && newspaperTimes.length > 0) { |
| 265 | this.calendarDate = newspaperTimes[0].date | 274 | this.calendarDate = newspaperTimes[0].date |
| 266 | this.currentPageNum = '01' | 275 | this.currentPageNum = '01' |
| 267 | - this.swiperIndex = 0 | ||
| 268 | } | 276 | } |
| 269 | } | 277 | } |
| 270 | 278 |
| @@ -12,16 +12,6 @@ export struct ENewspaperListDialog { | @@ -12,16 +12,6 @@ export struct ENewspaperListDialog { | ||
| 12 | @State scrollIndex: number = 0 | 12 | @State scrollIndex: number = 0 |
| 13 | newspaperListBean: NewspaperListBean = {} as NewspaperListBean | 13 | newspaperListBean: NewspaperListBean = {} as NewspaperListBean |
| 14 | private listScroller: Scroller = new Scroller(); | 14 | private listScroller: Scroller = new Scroller(); |
| 15 | - | ||
| 16 | - //watch监听报纸页码回调 | ||
| 17 | - onCurrentPageNumUpdated(): void { | ||
| 18 | - console.log("ENewspaperListDialog-onCurrentPageNumUpdated", "currentPageNum:", this.currentPageNum) | ||
| 19 | - let _scrollIndex = Number.parseInt(this.currentPageNum) | ||
| 20 | - console.log("ENewspaperListDialog-onCurrentPageNumUpdated", "_swiperIndex:", _scrollIndex) | ||
| 21 | - this.scrollIndex = _scrollIndex > 0 ? _scrollIndex - 1 : _scrollIndex | ||
| 22 | - this.listScroller.scrollToIndex(this.scrollIndex) | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | //文字版选择弹框 | 15 | //文字版选择弹框 |
| 26 | pageListDialogController: CustomDialogController = new CustomDialogController({ | 16 | pageListDialogController: CustomDialogController = new CustomDialogController({ |
| 27 | builder: ENewspaperPageDialog({ | 17 | builder: ENewspaperPageDialog({ |
| @@ -37,6 +27,29 @@ export struct ENewspaperListDialog { | @@ -37,6 +27,29 @@ export struct ENewspaperListDialog { | ||
| 37 | // 那么此处需要将指向自己的controller放在所有controller的后面 | 27 | // 那么此处需要将指向自己的controller放在所有controller的后面 |
| 38 | listDialogController: CustomDialogController | 28 | listDialogController: CustomDialogController |
| 39 | 29 | ||
| 30 | + //watch监听报纸页码回调 | ||
| 31 | + onCurrentPageNumUpdated(): void { | ||
| 32 | + console.log("ENewspaperListDialog-onCurrentPageNumUpdated", "currentPageNum:", this.currentPageNum) | ||
| 33 | + let _scrollIndex = Number.parseInt(this.currentPageNum) | ||
| 34 | + console.log("ENewspaperListDialog-onCurrentPageNumUpdated", "_scrollIndex:", _scrollIndex) | ||
| 35 | + this.scrollIndex = _scrollIndex > 0 ? _scrollIndex - 1 : _scrollIndex | ||
| 36 | + this.listScroller.scrollToIndex(this.scrollIndex) | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + aboutToAppear(): void { | ||
| 40 | + console.log("ENewspaperListDialog-aboutToAppear", "currentPageNum:", this.currentPageNum) | ||
| 41 | + let _scrollIndex = Number.parseInt(this.currentPageNum) | ||
| 42 | + console.log("ENewspaperListDialog-aboutToAppear", "_scrollIndex:", _scrollIndex) | ||
| 43 | + this.scrollIndex = _scrollIndex > 0 ? _scrollIndex - 1 : _scrollIndex | ||
| 44 | + // this.listScroller.scrollToIndex(this.scrollIndex) | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + aboutToDisappear() { | ||
| 48 | + // if (this.pageListDialogController) { | ||
| 49 | + // this.pageListDialogController = null | ||
| 50 | + // } | ||
| 51 | + } | ||
| 52 | + | ||
| 40 | build() { | 53 | build() { |
| 41 | Column() { | 54 | Column() { |
| 42 | Row() | 55 | Row() |
| @@ -80,57 +93,61 @@ export struct ENewspaperListDialog { | @@ -80,57 +93,61 @@ export struct ENewspaperListDialog { | ||
| 80 | .margin({ top: 20, left: 16, right: 16 }) | 93 | .margin({ top: 20, left: 16, right: 16 }) |
| 81 | .objectFit(ImageFit.Contain) | 94 | .objectFit(ImageFit.Contain) |
| 82 | 95 | ||
| 83 | - List({ scroller: this.listScroller }) { | 96 | + List({ scroller: this.listScroller, initialIndex: this.scrollIndex }) { |
| 84 | ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => { | 97 | ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => { |
| 85 | - ForEach(item.items, (positionItem: NewspaperPositionItemBean, itemIndex: number) => { | ||
| 86 | - ListItem() { | ||
| 87 | - Column() { | ||
| 88 | - if (itemIndex == 0) { | ||
| 89 | - Text(item.pageNum + item.pageName) | ||
| 90 | - .fontSize($r('app.float.font_size_14')) | ||
| 91 | - .fontColor($r('app.color.color_ED2800')) | ||
| 92 | - .fontWeight(600) | ||
| 93 | - .margin({ top: 16, bottom: 16 }) | ||
| 94 | - .maxLines(1) | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - if (positionItem.shortTitle) { | ||
| 98 | - Text(positionItem.shortTitle) | ||
| 99 | - .fontSize($r('app.float.font_size_14')) | ||
| 100 | - .fontColor($r('app.color.color_222222')) | ||
| 101 | - .fontWeight(600) | ||
| 102 | - .maxLines(2) | 98 | + ListItem() { |
| 99 | + List() { | ||
| 100 | + ForEach(item.items, (positionItem: NewspaperPositionItemBean, itemIndex: number) => { | ||
| 101 | + ListItem() { | ||
| 102 | + Column() { | ||
| 103 | + if (itemIndex == 0) { | ||
| 104 | + Text(item.pageNum + item.pageName) | ||
| 105 | + .fontSize($r('app.float.font_size_14')) | ||
| 106 | + .fontColor($r('app.color.color_ED2800')) | ||
| 107 | + .fontWeight(600) | ||
| 108 | + .margin({ top: 16, bottom: 16 }) | ||
| 109 | + .maxLines(1) | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + if (positionItem.shortTitle) { | ||
| 113 | + Text(positionItem.shortTitle) | ||
| 114 | + .fontSize($r('app.float.font_size_14')) | ||
| 115 | + .fontColor($r('app.color.color_222222')) | ||
| 116 | + .fontWeight(600) | ||
| 117 | + .maxLines(2) | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + if (positionItem.title) { | ||
| 121 | + Text(positionItem.title) | ||
| 122 | + .fontSize($r('app.float.font_size_17')) | ||
| 123 | + .fontColor($r('app.color.color_222222')) | ||
| 124 | + .margin({ top: 8 }) | ||
| 125 | + .maxLines(2) | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + if (positionItem.downTitle) { | ||
| 129 | + Text(positionItem.downTitle) | ||
| 130 | + .fontSize($r('app.float.font_size_14')) | ||
| 131 | + .fontColor($r('app.color.color_222222')) | ||
| 132 | + .fontWeight(600) | ||
| 133 | + .margin({ top: 8 }) | ||
| 134 | + .maxLines(2) | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + if (positionItem.newsTxt) { | ||
| 138 | + Text(positionItem.newsTxt) | ||
| 139 | + .fontSize($r('app.float.font_size_14')) | ||
| 140 | + .fontColor($r('app.color.color_999999')) | ||
| 141 | + .margin({ top: 15, bottom: 15 }) | ||
| 142 | + .maxLines(5) | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + .alignItems(HorizontalAlign.Start) | ||
| 103 | } | 146 | } |
| 104 | 147 | ||
| 105 | - if (positionItem.title) { | ||
| 106 | - Text(positionItem.title) | ||
| 107 | - .fontSize($r('app.float.font_size_17')) | ||
| 108 | - .fontColor($r('app.color.color_222222')) | ||
| 109 | - .margin({ top: 8 }) | ||
| 110 | - .maxLines(2) | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - if (positionItem.downTitle) { | ||
| 114 | - Text(positionItem.downTitle) | ||
| 115 | - .fontSize($r('app.float.font_size_14')) | ||
| 116 | - .fontColor($r('app.color.color_222222')) | ||
| 117 | - .fontWeight(600) | ||
| 118 | - .margin({ top: 8 }) | ||
| 119 | - .maxLines(2) | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - if (positionItem.newsTxt) { | ||
| 123 | - Text(positionItem.newsTxt) | ||
| 124 | - .fontSize($r('app.float.font_size_14')) | ||
| 125 | - .fontColor($r('app.color.color_999999')) | ||
| 126 | - .margin({ top: 15, bottom: 15 }) | ||
| 127 | - .maxLines(5) | ||
| 128 | - } | ||
| 129 | - } | ||
| 130 | - .alignItems(HorizontalAlign.Start) | 148 | + }) |
| 131 | } | 149 | } |
| 132 | - | ||
| 133 | - }) | 150 | + } |
| 134 | }) | 151 | }) |
| 135 | } | 152 | } |
| 136 | .width('100%') | 153 | .width('100%') |
| @@ -141,7 +158,17 @@ export struct ENewspaperListDialog { | @@ -141,7 +158,17 @@ export struct ENewspaperListDialog { | ||
| 141 | color: '#EDEDED' | 158 | color: '#EDEDED' |
| 142 | }) | 159 | }) |
| 143 | .onScrollIndex((firstIndex: number) => { | 160 | .onScrollIndex((firstIndex: number) => { |
| 144 | - this.updateCurrentPageNum(firstIndex) | 161 | + console.log('firstIndex', firstIndex) |
| 162 | + }) | ||
| 163 | + .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { | ||
| 164 | + console.info('first' + firstIndex) | ||
| 165 | + console.info('last' + lastIndex) | ||
| 166 | + console.info('center' + centerIndex) | ||
| 167 | + // this.updateCurrentPageNum(firstIndex) | ||
| 168 | + this.currentPageNum = `${centerIndex < 9 ? '0' + (centerIndex + 1) : centerIndex + 1}` | ||
| 169 | + }) | ||
| 170 | + .onScroll((scrollOffset: number, scrollState: ScrollState) => { | ||
| 171 | + console.info(`onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset) | ||
| 145 | }) | 172 | }) |
| 146 | } | 173 | } |
| 147 | .width('100%') | 174 | .width('100%') |
| @@ -157,7 +184,7 @@ export struct ENewspaperListDialog { | @@ -157,7 +184,7 @@ export struct ENewspaperListDialog { | ||
| 157 | for (let item of itemBean.items) { | 184 | for (let item of itemBean.items) { |
| 158 | index++ | 185 | index++ |
| 159 | if (index == firstIndex) { | 186 | if (index == firstIndex) { |
| 160 | - // this.currentPageNum = itemBean.pageNum | 187 | + this.currentPageNum = itemBean.pageNum |
| 161 | return | 188 | return |
| 162 | } | 189 | } |
| 163 | } | 190 | } |
-
Please register or login to post a comment