wangyujian_wd

feat:

1)电子版-日历和期刊弹窗和联动优化;
2)电子版-期刊选择弹框自定义,页面顶部状态栏修改;
1 import { NewspaperListBean, NewspaperListItemBean } from 'wdBean'; 1 import { NewspaperListBean, NewspaperListItemBean } from 'wdBean';
2 import { NewspaperViewModel } from '../viewmodel/NewspaperViewModel'; 2 import { NewspaperViewModel } from '../viewmodel/NewspaperViewModel';
3 import router from '@ohos.router'; 3 import router from '@ohos.router';
4 -import { Logger } from 'wdKit';  
5 import { ENewspaperItemComponent } from './ENewspaperItemComponent'; 4 import { ENewspaperItemComponent } from './ENewspaperItemComponent';
6 import { ENewspaperListDialog } from '../dialog/ENewspaperListDialog'; 5 import { ENewspaperListDialog } from '../dialog/ENewspaperListDialog';
7 import display from '@ohos.display'; 6 import display from '@ohos.display';
8 import { ENewspaperCalendarDialog } from '../dialog/ENewspaperCalendarDialog'; 7 import { ENewspaperCalendarDialog } from '../dialog/ENewspaperCalendarDialog';
9 import font from '@ohos.font'; 8 import font from '@ohos.font';
  9 +import { ENewspaperPageDialog } from '../dialog/ENewspaperPageDialog';
  10 +import { RMCalendarBean } from './calendar/RMCalendarBean';
10 11
11 @Component 12 @Component
12 export struct ENewspaperPageComponent { 13 export struct ENewspaperPageComponent {
  14 + private displayTool = display.getDefaultDisplaySync()
  15 + private screenWidth: number = 0
  16 + private picWidth: number = 0
  17 + @State picHeight: number = 0
13 @State newspaperListBean: NewspaperListBean = {} as NewspaperListBean 18 @State newspaperListBean: NewspaperListBean = {} as NewspaperListBean
14 @State currentPageNum: string = '01' 19 @State currentPageNum: string = '01'
15 - @State pageNumPopup: boolean = false  
16 - @State calendarPopup: boolean = false  
17 - @State calendarDateTitle: string = ''  
18 - @State picHeight: number = 0 20 + @State pageDialogShow: boolean = false
  21 + @State calendarDialogShow: boolean = false
  22 + @State calendarDate: string = ''
19 private swiperController: SwiperController = new SwiperController() 23 private swiperController: SwiperController = new SwiperController()
  24 + @State swiperIndex: number = 0;
  25 + //watch监听报纸页码回调
  26 + // onCurrentPageNumUpdated(): void {
  27 + // console.log("ENewspaperPageComponent-onCurrentPageNumUpdated", "date:", this.currentPageNum)
  28 + // let _swiperIndex = Number.parseInt(this.currentPageNum)
  29 + // console.log("ENewspaperPageComponent-onCurrentPageNumUpdated", "_swiperIndex:", _swiperIndex)
  30 + // this.swiperIndex = _swiperIndex > 0 ? _swiperIndex - 1 : _swiperIndex
  31 + // }
  32 +
  33 + //日历选择弹框
20 calendarDialogController: CustomDialogController = new CustomDialogController({ 34 calendarDialogController: CustomDialogController = new CustomDialogController({
21 - builder: ENewspaperCalendarDialog(), 35 + builder: ENewspaperCalendarDialog({ onDateChange: (date: RMCalendarBean) => {
  36 + console.log("onDateChange-日历选择弹框", "date:", JSON.stringify(date))
  37 + if (date.fullYear && date.month && date.date) {
  38 + this.calendarDate = `${date.fullYear}-${date.month > 9 ? date.month + 1 : '0' + (date.month + 1)}-${date.date > 9 ? date.date : '0' + date.date}`
  39 + this.currentPageNum = '01'
  40 + this.getNewspaperTime()
  41 + this.getNewspaperList()
  42 + }
  43 + } }),
22 alignment: DialogAlignment.Top, 44 alignment: DialogAlignment.Top,
23 offset: { dx: 0, dy: 80 }, 45 offset: { dx: 0, dy: 80 },
24 customStyle: true, 46 customStyle: true,
25 - // cornerRadius: 4  
26 }) 47 })
27 - listDialogController: CustomDialogController = new CustomDialogController({  
28 - builder: ENewspaperListDialog({ newspaperListBean: this.newspaperListBean, 48 + //图片版选择弹框
  49 + pageDialogController: CustomDialogController = new CustomDialogController({
  50 + builder: ENewspaperPageDialog({
29 currentPageNum: this.currentPageNum, 51 currentPageNum: this.currentPageNum,
  52 + dialogType: 0,
  53 + newspaperListBean: this.newspaperListBean,
  54 + onDateChange: (date: string, dialogType: number) => {
  55 + if (dialogType == 0) {
  56 + let _swiperIndex = Number.parseInt(this.currentPageNum)
  57 + console.log("ENewspaperPageComponent-onCurrentPageNumUpdated", "_swiperIndex:", _swiperIndex)
  58 + this.swiperIndex = _swiperIndex > 0 ? _swiperIndex - 1 : _swiperIndex
  59 + }
  60 + }
30 }), 61 }),
31 - alignment: DialogAlignment.Bottom 62 + alignment: DialogAlignment.BottomStart,
  63 + offset: { dx: 0, dy: -90 },
  64 + customStyle: true,
  65 + })
  66 + //文字报纸弹框
  67 + listDialogController: CustomDialogController = new CustomDialogController({
  68 + builder: ENewspaperListDialog({
  69 + currentPageNum: this.currentPageNum,
  70 + newspaperListBean: this.newspaperListBean }),
  71 + alignment: DialogAlignment.Bottom,
  72 + offset: { dx: 0, dy: 0 }
32 }) 73 })
33 -  
34 - @Builder  
35 - popupBuilder() {  
36 - Row() {  
37 - GridRow({ columns: 5 }) {  
38 - ForEach(this.newspaperListBean.list, (item: NewspaperListItemBean, index) => {  
39 - GridCol() {  
40 - Row() {  
41 - Text(item.pageNum)  
42 - .fontSize($r('app.float.normal_text_size'))  
43 - .fontColor(this.currentPageNum == item.pageNum ? Color.White : $r('app.color.color_222222'))  
44 - }  
45 - .alignItems(VerticalAlign.Center)  
46 - .justifyContent(FlexAlign.Center)  
47 - .width(30)  
48 - .height(30)  
49 - .backgroundColor(this.currentPageNum != item.pageNum ? Color.White : $r('app.color.color_ED2800'))  
50 - .onClick((event: ClickEvent) => {  
51 - this.pageNumPopup = !this.pageNumPopup  
52 - })  
53 - }  
54 - })  
55 - }  
56 - }  
57 - .padding({ top: 20, bottom: 20 })  
58 - .margin({ left: 10 })  
59 - .width(260)  
60 - }  
61 74
62 build() { 75 build() {
63 RelativeContainer() { 76 RelativeContainer() {
@@ -69,15 +82,15 @@ export struct ENewspaperPageComponent { @@ -69,15 +82,15 @@ export struct ENewspaperPageComponent {
69 center: { anchor: "__container__", align: VerticalAlign.Center } }) 82 center: { anchor: "__container__", align: VerticalAlign.Center } })
70 .id('e_newspaper_back') 83 .id('e_newspaper_back')
71 .onClick((event: ClickEvent) => { 84 .onClick((event: ClickEvent) => {
72 - Logger.info("sfsfsd", "" + vp2px(10))  
73 router.back() 85 router.back()
74 }) 86 })
75 87
76 Row() { 88 Row() {
77 - Text(this.calendarDateTitle) 89 + Text(this.calendarDate)
78 .fontSize($r('app.float.font_size_20')) 90 .fontSize($r('app.float.font_size_20'))
79 .fontColor($r('app.color.white')) 91 .fontColor($r('app.color.white'))
80 .fontFamily('BebasNeue_Regular') 92 .fontFamily('BebasNeue_Regular')
  93 + .fontWeight(FontWeight.Bold)
81 94
82 Image($r('app.media.icon_triangle')) 95 Image($r('app.media.icon_triangle'))
83 .width($r('app.float.border_radius_6')) 96 .width($r('app.float.border_radius_6'))
@@ -89,8 +102,8 @@ export struct ENewspaperPageComponent { @@ -89,8 +102,8 @@ export struct ENewspaperPageComponent {
89 center: { anchor: "__container__", align: VerticalAlign.Center } }) 102 center: { anchor: "__container__", align: VerticalAlign.Center } })
90 .id('e_newspaper_date') 103 .id('e_newspaper_date')
91 .onClick(() => { 104 .onClick(() => {
92 - this.calendarPopup = !this.calendarPopup  
93 - if (this.calendarPopup) { 105 + this.calendarDialogShow = !this.calendarDialogShow
  106 + if (this.calendarDialogShow) {
94 this.calendarDialogController.open() 107 this.calendarDialogController.open()
95 } else { 108 } else {
96 this.calendarDialogController.close() 109 this.calendarDialogController.close()
@@ -117,6 +130,7 @@ export struct ENewspaperPageComponent { @@ -117,6 +130,7 @@ export struct ENewspaperPageComponent {
117 ENewspaperItemComponent({ newspaperListItemBean: item }) 130 ENewspaperItemComponent({ newspaperListItemBean: item })
118 }) 131 })
119 } 132 }
  133 + .index(this.swiperIndex)
120 .width('100%') 134 .width('100%')
121 .height(px2vp(this.picHeight) + 32) 135 .height(px2vp(this.picHeight) + 32)
122 .vertical(true) 136 .vertical(true)
@@ -163,6 +177,7 @@ export struct ENewspaperPageComponent { @@ -163,6 +177,7 @@ export struct ENewspaperPageComponent {
163 Text(this.currentPageNum) 177 Text(this.currentPageNum)
164 .fontSize($r('app.float.font_size_36')) 178 .fontSize($r('app.float.font_size_36'))
165 .fontColor($r('app.color.white')) 179 .fontColor($r('app.color.white'))
  180 + .fontFamily('BebasNeue_Regular')
166 Text('版') 181 Text('版')
167 .fontSize($r('app.float.font_size_16')) 182 .fontSize($r('app.float.font_size_16'))
168 .fontColor($r('app.color.white')) 183 .fontColor($r('app.color.white'))
@@ -179,14 +194,20 @@ export struct ENewspaperPageComponent { @@ -179,14 +194,20 @@ export struct ENewspaperPageComponent {
179 left: { anchor: '__container__', align: HorizontalAlign.Start } }) 194 left: { anchor: '__container__', align: HorizontalAlign.Start } })
180 .id('e_newspaper_page_num') 195 .id('e_newspaper_page_num')
181 .onClick((event: ClickEvent) => { 196 .onClick((event: ClickEvent) => {
182 - this.pageNumPopup = !this.pageNumPopup  
183 - })  
184 - .bindPopup(this.pageNumPopup, {  
185 - builder: this.popupBuilder,  
186 - placement: Placement.Top,  
187 - popupColor: Color.White 197 + this.pageDialogShow = !this.pageDialogShow
  198 + if (this.pageDialogShow) {
  199 + this.pageDialogController.open()
  200 + } else {
  201 + this.pageDialogController.close()
  202 + }
188 }) 203 })
189 204
  205 + // .bindPopup(this.pageNumPopup, {
  206 + // builder: this.popupBuilder,
  207 + // placement: Placement.Top,
  208 + // popupColor: Color.White
  209 + // })
  210 +
190 Row() { 211 Row() {
191 Image($r('app.media.icon_read_paper')) 212 Image($r('app.media.icon_read_paper'))
192 .width($r('app.float.vp_20')) 213 .width($r('app.float.vp_20'))
@@ -212,22 +233,29 @@ export struct ENewspaperPageComponent { @@ -212,22 +233,29 @@ export struct ENewspaperPageComponent {
212 } 233 }
213 234
214 async aboutToAppear() { 235 async aboutToAppear() {
  236 + //获取宽高尺寸
  237 + this.screenWidth = this.displayTool.width
  238 + this.picWidth = this.screenWidth - vp2px(52)
  239 + this.picHeight = this.picWidth * 566 / 378
215 //注册字体 240 //注册字体
216 font.registerFont({ 241 font.registerFont({
217 familyName: 'BebasNeue_Regular', 242 familyName: 'BebasNeue_Regular',
218 - // familySrc: '/font/roboto_medium_numbers.ttf' // font文件夹与pages目录同级  
219 familySrc: $rawfile('font/BebasNeue_Regular.otf') 243 familySrc: $rawfile('font/BebasNeue_Regular.otf')
220 }) 244 })
221 - let newspaperTimes = await NewspaperViewModel.getNewspaperTime() 245 + this.getNewspaperTime()
  246 + this.getNewspaperList()
  247 + }
  248 +
  249 + private async getNewspaperTime() {
  250 + let newspaperTimes = await NewspaperViewModel.getNewspaperTime(this.calendarDate)
222 if (newspaperTimes && newspaperTimes.length > 0) { 251 if (newspaperTimes && newspaperTimes.length > 0) {
223 - this.calendarDateTitle = newspaperTimes[0].date 252 + this.calendarDate = newspaperTimes[0].date
224 } 253 }
  254 + }
  255 +
  256 + private async getNewspaperList() {
225 try { 257 try {
226 - let displayTool = display.getDefaultDisplaySync()  
227 - let screenWidth = displayTool.width  
228 - let picWidth = screenWidth - vp2px(52)  
229 - this.picHeight = picWidth * 566 / 378  
230 - let listBean = await NewspaperViewModel.getNewspaperList(this.calendarDateTitle, picWidth + 'x' + this.picHeight) 258 + let listBean = await NewspaperViewModel.getNewspaperList(this.calendarDate, this.picWidth + 'x' + this.picHeight)
231 this.newspaperListBean = listBean; 259 this.newspaperListBean = listBean;
232 } catch (exception) { 260 } catch (exception) {
233 261
@@ -4,16 +4,20 @@ import { RMCalendarBean } from '../components/calendar/RMCalendarBean' @@ -4,16 +4,20 @@ import { RMCalendarBean } from '../components/calendar/RMCalendarBean'
4 @CustomDialog 4 @CustomDialog
5 export struct ENewspaperCalendarDialog { 5 export struct ENewspaperCalendarDialog {
6 calendarDialogController?: CustomDialogController 6 calendarDialogController?: CustomDialogController
  7 + // 选择变化监听,
  8 + onDateChange?: (date: RMCalendarBean) => void
7 9
8 build() { 10 build() {
9 RMCalendar({ 11 RMCalendar({
10 // 开始日期 12 // 开始日期
11 startDate: new Date(2023, 8, 1), 13 startDate: new Date(2023, 8, 1),
12 // 截止日期 14 // 截止日期
13 - endDate: new Date(2024, 2, 20), 15 + endDate: new Date(),
14 // 日期选择变化监听 16 // 日期选择变化监听
15 - onDateChange: (date1: RMCalendarBean) => {  
16 - console.log("onDateChange", "date1:", JSON.stringify(date1)) 17 + onDateChange: (date: RMCalendarBean) => {
  18 + if (this.onDateChange) {
  19 + this.onDateChange(date)
  20 + }
17 if (this.calendarDialogController) { 21 if (this.calendarDialogController) {
18 this.calendarDialogController.close() 22 this.calendarDialogController.close()
19 } 23 }
1 import { NewspaperListBean, NewspaperListItemBean, NewspaperPositionItemBean } from 'wdBean' 1 import { NewspaperListBean, NewspaperListItemBean, NewspaperPositionItemBean } from 'wdBean'
  2 +import { ENewspaperPageDialog } from '../dialog/ENewspaperPageDialog'
2 3
  4 +/**
  5 + * 读报纸半屏弹窗
  6 + * 弹窗嵌套参考资料(https://developer.harmonyos.com/cn/docs/documentation/doc-references-V2/ts-methods-custom-dialog-box-0000001580345722-V2)
  7 + */
3 @CustomDialog 8 @CustomDialog
4 export struct ENewspaperListDialog { 9 export struct ENewspaperListDialog {
5 - @State currentPageNum: string = '01'  
6 - controller: CustomDialogController 10 + @Link currentPageNum: string
  11 + @State pageDialogShow: boolean = false
  12 + @State scrollIndex: number = 0
7 newspaperListBean: NewspaperListBean = {} as NewspaperListBean 13 newspaperListBean: NewspaperListBean = {} as NewspaperListBean
  14 + private listScroller: Scroller = new Scroller();
  15 + //文字版选择弹框
  16 + pageListDialogController: CustomDialogController = new CustomDialogController({
  17 + builder: ENewspaperPageDialog({
  18 + currentPageNum: this.currentPageNum,
  19 + dialogType: 1,
  20 + newspaperListBean: this.newspaperListBean,
  21 + onDateChange: (date: string, dialogType: number) => {
  22 + if (dialogType == 1) {
  23 + console.log("ENewspaperListDialog-pageListDialogController", "date:", this.currentPageNum)
  24 + let _scrollIndex = Number.parseInt(this.currentPageNum)
  25 + console.log("ENewspaperListDialog-pageListDialogController", "_swiperIndex:", _scrollIndex)
  26 + this.scrollIndex = _scrollIndex > 0 ? _scrollIndex - 1 : _scrollIndex
  27 + this.listScroller.scrollToIndex(this.scrollIndex)
  28 + }
  29 + }
  30 + }),
  31 + alignment: DialogAlignment.TopStart,
  32 + offset: { dx: 0, dy: 214 },
  33 + customStyle: true,
  34 + })
  35 + //页面半屏弹窗(实现在上个组件)若尝试在CustomDialog中传入多个其他的Controller,
  36 + // 以实现在CustomDialog中打开另一个或另一些CustomDialog,
  37 + // 那么此处需要将指向自己的controller放在所有controller的后面
  38 + listDialogController: CustomDialogController
8 39
9 build() { 40 build() {
10 Column() { 41 Column() {
  42 + Row()
  43 + .width(43)
  44 + .height(4)
  45 + .backgroundColor('#EDEDED')
  46 + .margin({ top: 10,
  47 + bottom: 10 })
11 Row() { 48 Row() {
12 Text(this.currentPageNum) 49 Text(this.currentPageNum)
13 .fontSize($r('app.float.font_size_36')) 50 .fontSize($r('app.float.font_size_36'))
14 .fontColor($r('app.color.color_222222')) 51 .fontColor($r('app.color.color_222222'))
  52 + .fontFamily('BebasNeue_Regular')
15 Text('版') 53 Text('版')
16 .fontSize($r('app.float.font_size_16')) 54 .fontSize($r('app.float.font_size_16'))
17 .fontColor($r('app.color.color_222222')) 55 .fontColor($r('app.color.color_222222'))
@@ -23,8 +61,16 @@ export struct ENewspaperListDialog { @@ -23,8 +61,16 @@ export struct ENewspaperListDialog {
23 .margin({ left: 2, bottom: 6 }) 61 .margin({ left: 2, bottom: 6 })
24 } 62 }
25 .alignItems(VerticalAlign.Bottom) 63 .alignItems(VerticalAlign.Bottom)
26 - .margin({ top: 25, left: 15 }) 64 + .margin({ left: 15 })
27 .alignSelf(ItemAlign.Start) 65 .alignSelf(ItemAlign.Start)
  66 + .onClick(() => {
  67 + this.pageDialogShow = !this.pageDialogShow
  68 + if (this.pageDialogShow) {
  69 + this.pageListDialogController.open()
  70 + } else {
  71 + this.pageListDialogController.close()
  72 + }
  73 + })
28 74
29 Image($r('app.media.line')) 75 Image($r('app.media.line'))
30 .width('100%') 76 .width('100%')
@@ -32,16 +78,17 @@ export struct ENewspaperListDialog { @@ -32,16 +78,17 @@ export struct ENewspaperListDialog {
32 .margin({ top: 20, left: 16, right: 16 }) 78 .margin({ top: 20, left: 16, right: 16 })
33 .objectFit(ImageFit.Contain) 79 .objectFit(ImageFit.Contain)
34 80
35 - List() { 81 + List({ scroller: this.listScroller }) {
36 ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => { 82 ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => {
37 ForEach(item.items, (positionItem: NewspaperPositionItemBean, itemIndex: number) => { 83 ForEach(item.items, (positionItem: NewspaperPositionItemBean, itemIndex: number) => {
38 ListItem() { 84 ListItem() {
39 - Column(){ 85 + Column() {
40 if (itemIndex == 0) { 86 if (itemIndex == 0) {
41 Text(item.pageNum + item.pageName) 87 Text(item.pageNum + item.pageName)
42 .fontSize($r('app.float.font_size_14')) 88 .fontSize($r('app.float.font_size_14'))
43 .fontColor($r('app.color.color_ED2800')) 89 .fontColor($r('app.color.color_ED2800'))
44 - .margin({ top: 16 }) 90 + .fontWeight(600)
  91 + .margin({ top: 16, bottom: 16 })
45 .maxLines(1) 92 .maxLines(1)
46 } 93 }
47 94
@@ -49,7 +96,7 @@ export struct ENewspaperListDialog { @@ -49,7 +96,7 @@ export struct ENewspaperListDialog {
49 Text(positionItem.shortTitle) 96 Text(positionItem.shortTitle)
50 .fontSize($r('app.float.font_size_14')) 97 .fontSize($r('app.float.font_size_14'))
51 .fontColor($r('app.color.color_222222')) 98 .fontColor($r('app.color.color_222222'))
52 - .margin({ top: 16 }) 99 + .fontWeight(600)
53 .maxLines(2) 100 .maxLines(2)
54 } 101 }
55 102
@@ -57,7 +104,7 @@ export struct ENewspaperListDialog { @@ -57,7 +104,7 @@ export struct ENewspaperListDialog {
57 Text(positionItem.title) 104 Text(positionItem.title)
58 .fontSize($r('app.float.font_size_17')) 105 .fontSize($r('app.float.font_size_17'))
59 .fontColor($r('app.color.color_222222')) 106 .fontColor($r('app.color.color_222222'))
60 - .margin({ top: 16 }) 107 + .margin({ top: 8 })
61 .maxLines(2) 108 .maxLines(2)
62 } 109 }
63 110
@@ -65,7 +112,8 @@ export struct ENewspaperListDialog { @@ -65,7 +112,8 @@ export struct ENewspaperListDialog {
65 Text(positionItem.downTitle) 112 Text(positionItem.downTitle)
66 .fontSize($r('app.float.font_size_14')) 113 .fontSize($r('app.float.font_size_14'))
67 .fontColor($r('app.color.color_222222')) 114 .fontColor($r('app.color.color_222222'))
68 - .margin({ top: 16 }) 115 + .fontWeight(600)
  116 + .margin({ top: 8 })
69 .maxLines(2) 117 .maxLines(2)
70 } 118 }
71 119
@@ -73,7 +121,7 @@ export struct ENewspaperListDialog { @@ -73,7 +121,7 @@ export struct ENewspaperListDialog {
73 Text(positionItem.newsTxt) 121 Text(positionItem.newsTxt)
74 .fontSize($r('app.float.font_size_14')) 122 .fontSize($r('app.float.font_size_14'))
75 .fontColor($r('app.color.color_999999')) 123 .fontColor($r('app.color.color_999999'))
76 - .margin({ top: 16, bottom: 16 }) 124 + .margin({ top: 15, bottom: 15 })
77 .maxLines(5) 125 .maxLines(5)
78 } 126 }
79 } 127 }
@@ -81,24 +129,20 @@ export struct ENewspaperListDialog { @@ -81,24 +129,20 @@ export struct ENewspaperListDialog {
81 } 129 }
82 130
83 }) 131 })
84 -  
85 }) 132 })
86 -  
87 } 133 }
88 .width('100%') 134 .width('100%')
89 - .margin({ top: 16, left: 16, right: 16 }) 135 + .padding({ left: 15, right: 15 })
90 .scrollBar(BarState.Off) 136 .scrollBar(BarState.Off)
91 .divider({ 137 .divider({
92 - strokeWidth: 1, 138 + strokeWidth: 0.5,
93 color: '#EDEDED' 139 color: '#EDEDED'
94 }) 140 })
95 .onScrollIndex((firstIndex: number) => { 141 .onScrollIndex((firstIndex: number) => {
96 this.updateCurrentPageNum(firstIndex) 142 this.updateCurrentPageNum(firstIndex)
97 }) 143 })
98 -  
99 } 144 }
100 .width('100%') 145 .width('100%')
101 - .height(674)  
102 .backgroundColor(Color.White) 146 .backgroundColor(Color.White)
103 147
104 } 148 }
@@ -107,20 +151,19 @@ export struct ENewspaperListDialog { @@ -107,20 +151,19 @@ export struct ENewspaperListDialog {
107 if (this.newspaperListBean.list && this.newspaperListBean.list.length > 0) { 151 if (this.newspaperListBean.list && this.newspaperListBean.list.length > 0) {
108 let index = 0; 152 let index = 0;
109 for (let itemBean of this.newspaperListBean.list) { 153 for (let itemBean of this.newspaperListBean.list) {
110 - if (itemBean.items && itemBean.items.length > 0){  
111 - for (let item of itemBean.items){ 154 + if (itemBean.items && itemBean.items.length > 0) {
  155 + for (let item of itemBean.items) {
112 index++ 156 index++
113 - if (index == firstIndex){ 157 + if (index == firstIndex) {
114 this.currentPageNum = itemBean.pageNum 158 this.currentPageNum = itemBean.pageNum
115 return 159 return
116 } 160 }
117 -  
118 } 161 }
119 } 162 }
120 } 163 }
121 } 164 }
122 165
123 - } 166 + }
124 } 167 }
125 168
126 169
  1 +import { NewspaperListBean, NewspaperListItemBean } from 'wdBean/Index'
  2 +
  3 +/**
  4 + * 期刊日期选择弹窗
  5 + */
  6 +@CustomDialog
  7 +export struct ENewspaperPageDialog {
  8 + dialogType: number = 0 //0:图片版,1:文字版
  9 + pageDialogController?: CustomDialogController
  10 + @Link currentPageNum: string
  11 + @Prop newspaperListBean: NewspaperListBean = {} as NewspaperListBean
  12 + // 选择变化监听,
  13 + onDateChange?: (date: string, dialogType: number) => void
  14 +
  15 + build() {
  16 + Column() {
  17 + if (this.dialogType == 1) {
  18 + Image($r("app.media.iv_e_news_pager_calendar_arrow_up"))
  19 + .width(18).height(8.5)
  20 + .margin({ left: 31 })
  21 + }
  22 + Stack() {
  23 + GridRow({ columns: 5, gutter: { x: 15, y: 15 } }) {
  24 + ForEach(this.newspaperListBean.list, (item: NewspaperListItemBean, index) => {
  25 + GridCol() {
  26 + Row() {
  27 + Text(item.pageNum)
  28 + .fontSize($r('app.float.normal_text_size'))
  29 + .fontColor(this.currentPageNum == item.pageNum ? Color.White : $r('app.color.color_222222'))
  30 + .fontFamily('BebasNeue_Regular')
  31 + }
  32 + .alignItems(VerticalAlign.Center)
  33 + .justifyContent(FlexAlign.Center)
  34 + .width(30)
  35 + .height(30)
  36 + .backgroundColor(this.currentPageNum != item.pageNum ? Color.White : $r('app.color.color_ED2800'))
  37 + .onClick((event: ClickEvent) => {
  38 + this.currentPageNum = item.pageNum
  39 + if (this.onDateChange) {
  40 + this.onDateChange(item.pageNum, this.dialogType)
  41 + }
  42 + if (this.pageDialogController) {
  43 + this.pageDialogController.close()
  44 + }
  45 + })
  46 + }
  47 + })
  48 + }
  49 + }
  50 + .padding(20)
  51 + .width(260)
  52 + .borderRadius(4)
  53 + .backgroundColor(Color.White)
  54 +
  55 + if (this.dialogType == 0) {
  56 + Image($r("app.media.iv_e_news_pager_calendar_arrow_down"))
  57 + .width(18).height(8.5)
  58 + .margin({ left: 31 })
  59 + }
  60 + }
  61 + .margin({ left: 10 })
  62 + .alignItems(HorizontalAlign.Start)
  63 + }
  64 +}
1 import HashMap from '@ohos.util.HashMap'; 1 import HashMap from '@ohos.util.HashMap';
2 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork'; 2 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
3 import { DateTimeUtils, Logger } from 'wdKit'; 3 import { DateTimeUtils, Logger } from 'wdKit';
4 -import { ContentDetailDTO, NavigationBodyDTO, PageDTO,InteractDataDTO, MorningEveningPaperDTO,  
5 - NewspaperTimeInfoBean, 4 +import {
  5 + CompInfoBean,
  6 + ContentDetailDTO,
  7 + InteractDataDTO,
  8 + MorningEveningPaperDTO,
  9 + NavigationBodyDTO,
6 NewspaperListBean, 10 NewspaperListBean,
7 - PageInfoBean,  
8 - CompInfoBean 11 + NewspaperTimeInfoBean,
  12 + PageDTO,
  13 + PageInfoBean
9 } from 'wdBean'; 14 } from 'wdBean';
  15 +
10 const TAG = 'HttpRequest'; 16 const TAG = 'HttpRequest';
11 export class PageRepository { 17 export class PageRepository {
12 static getBottomNavGroupUrl() { 18 static getBottomNavGroupUrl() {
@@ -62,8 +68,8 @@ export class PageRepository { @@ -62,8 +68,8 @@ export class PageRepository {
62 return url; 68 return url;
63 } 69 }
64 70
65 - static getNewspaperInfoUrl() {  
66 - let url = HttpUrlUtils.getHost() + HttpUrlUtils.E_NEWSPAPER_INFO_PATH; 71 + static getNewspaperInfoUrl(date: string) {
  72 + let url = HttpUrlUtils.getHost() + HttpUrlUtils.E_NEWSPAPER_INFO_PATH + "?date=" + date;
67 Logger.info(TAG,"getNewspaperInfoUrl url = "+url) 73 Logger.info(TAG,"getNewspaperInfoUrl url = "+url)
68 return url; 74 return url;
69 } 75 }
@@ -146,8 +152,8 @@ export class PageRepository { @@ -146,8 +152,8 @@ export class PageRepository {
146 return WDHttp.post<ResponseDTO<InteractDataDTO[]>>(url, param, headers) 152 return WDHttp.post<ResponseDTO<InteractDataDTO[]>>(url, param, headers)
147 }; 153 };
148 154
149 - static fetchNewspaperInfo() {  
150 - let url = PageRepository.getNewspaperInfoUrl() 155 + static fetchNewspaperInfo(date: string) {
  156 + let url = PageRepository.getNewspaperInfoUrl(date)
151 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); 157 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
152 return WDHttp.get<ResponseDTO<NewspaperTimeInfoBean[]>>(url, headers) 158 return WDHttp.get<ResponseDTO<NewspaperTimeInfoBean[]>>(url, headers)
153 }; 159 };
@@ -16,10 +16,10 @@ export class NewspaperViewModel { @@ -16,10 +16,10 @@ export class NewspaperViewModel {
16 return newspaperTimeInfo.data 16 return newspaperTimeInfo.data
17 } 17 }
18 18
19 - static async getNewspaperTime(): Promise<NewspaperTimeInfoBean[]> { 19 + static async getNewspaperTime(date: string): Promise<NewspaperTimeInfoBean[]> {
20 return new Promise<NewspaperTimeInfoBean[]>((success, error) => { 20 return new Promise<NewspaperTimeInfoBean[]>((success, error) => {
21 Logger.info(TAG, `getNavData start`); 21 Logger.info(TAG, `getNavData start`);
22 - PageRepository.fetchNewspaperInfo().then((resDTO: ResponseDTO<NewspaperTimeInfoBean[]>) => { 22 + PageRepository.fetchNewspaperInfo(date).then((resDTO: ResponseDTO<NewspaperTimeInfoBean[]>) => {
23 if (!resDTO || !resDTO.data) { 23 if (!resDTO || !resDTO.data) {
24 Logger.error(TAG, 'getNewspaperTime then navResDTO is empty'); 24 Logger.error(TAG, 'getNewspaperTime then navResDTO is empty');
25 error('resDTO is empty'); 25 error('resDTO is empty');
@@ -71,6 +71,4 @@ export class NewspaperViewModel { @@ -71,6 +71,4 @@ export class NewspaperViewModel {
71 } 71 }
72 return newspaperListBean.data 72 return newspaperListBean.data
73 } 73 }
74 -  
75 -  
76 } 74 }
1 import { ENewspaperPageComponent } from 'wdComponent'; 1 import { ENewspaperPageComponent } from 'wdComponent';
2 -import { Logger } from 'wdKit' 2 +import { Logger } from 'wdKit';
  3 +import common from '@ohos.app.ability.common';
  4 +import window from '@ohos.window';
3 5
4 const TAG = 'ENewspaper'; 6 const TAG = 'ENewspaper';
5 7
6 @Entry 8 @Entry
7 @Component 9 @Component
8 struct ENewspaper { 10 struct ENewspaper {
  11 + // 获取UIAbility上下文
  12 + context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
  13 +
  14 + async setSystemBar(color: string) {
  15 + // 获取当前应用窗口
  16 + let windowClass: window.Window = await window.getLastWindow(this.context)
  17 + // 将状态栏和导航栏的背景色设置为跟应用窗口相同的颜色
  18 + await windowClass.setWindowSystemBarProperties({
  19 + navigationBarColor: color,
  20 + statusBarColor: color,
  21 + // navigationBarContentColor: "#00FF00",
  22 + // statusBarContentColor: "#00FF00"
  23 + })
  24 + }
9 25
10 build() { 26 build() {
11 Column() { 27 Column() {
@@ -13,7 +29,7 @@ struct ENewspaper { @@ -13,7 +29,7 @@ struct ENewspaper {
13 } 29 }
14 } 30 }
15 31
16 - pageTransition(){ 32 + pageTransition() {
17 // 定义页面进入时的效果,从底侧滑入 33 // 定义页面进入时的效果,从底侧滑入
18 PageTransitionEnter({ type: RouteType.None, duration: 300 }) 34 PageTransitionEnter({ type: RouteType.None, duration: 300 })
19 .slide(SlideEffect.Bottom) 35 .slide(SlideEffect.Bottom)
@@ -31,10 +47,12 @@ struct ENewspaper { @@ -31,10 +47,12 @@ struct ENewspaper {
31 } 47 }
32 48
33 onPageShow() { 49 onPageShow() {
  50 + this.setSystemBar('#80000000')
34 Logger.info(TAG, 'onPageShow'); 51 Logger.info(TAG, 'onPageShow');
35 } 52 }
36 53
37 onPageHide() { 54 onPageHide() {
  55 + this.setSystemBar('#FFFFFFFF')
38 Logger.info(TAG, 'onPageHide'); 56 Logger.info(TAG, 'onPageHide');
39 } 57 }
40 58