Showing
8 changed files
with
195 additions
and
7 deletions
| @@ -29,3 +29,7 @@ export { WaterFlowComponent } from "./src/main/ets/components/WaterFlowComponent | @@ -29,3 +29,7 @@ export { WaterFlowComponent } from "./src/main/ets/components/WaterFlowComponent | ||
| 29 | export { NewspaperViewModel} from "./src/main/ets/viewmodel/NewspaperViewModel" | 29 | export { NewspaperViewModel} from "./src/main/ets/viewmodel/NewspaperViewModel" |
| 30 | 30 | ||
| 31 | export {ENewspaperPageComponent} from "./src/main/ets/components/ENewspaperPageComponent" | 31 | export {ENewspaperPageComponent} from "./src/main/ets/components/ENewspaperPageComponent" |
| 32 | + | ||
| 33 | +export {ENewspaperItemComponent} from "./src/main/ets/components/ENewspaperItemComponent" | ||
| 34 | + | ||
| 35 | +export {ENewspaperListDialog} from "./src/main/ets/dialog/ENewspaperListDialog" |
| 1 | -import { NewspaperListBean, NewspaperListItemBean } from 'wdBean' | ||
| 2 | -import { NewspaperViewModel } from '../viewmodel/NewspaperViewModel' | ||
| 3 | -import router from '@ohos.router' | 1 | +import { NewspaperListBean, NewspaperListItemBean } from 'wdBean'; |
| 2 | +import { NewspaperViewModel } from '../viewmodel/NewspaperViewModel'; | ||
| 3 | +import router from '@ohos.router'; | ||
| 4 | import { Logger } from 'wdKit'; | 4 | import { Logger } from 'wdKit'; |
| 5 | -import { ENewspaperItemComponent } from './ENewspaperItemComponent' | 5 | +import { ENewspaperItemComponent } from './ENewspaperItemComponent'; |
| 6 | +import { ENewspaperListDialog } from '../dialog/ENewspaperListDialog'; | ||
| 6 | 7 | ||
| 7 | @Component | 8 | @Component |
| 8 | export struct ENewspaperPageComponent { | 9 | export struct ENewspaperPageComponent { |
| 9 | @State newspaperListBean: NewspaperListBean = {} as NewspaperListBean | 10 | @State newspaperListBean: NewspaperListBean = {} as NewspaperListBean |
| 10 | - @State currentPageNum: string = '01'; | 11 | + @State currentPageNum: string = '01' |
| 12 | + @State pageNumPopup: boolean = false | ||
| 11 | private swiperController: SwiperController = new SwiperController() | 13 | private swiperController: SwiperController = new SwiperController() |
| 12 | - | 14 | + listDialogController: CustomDialogController = new CustomDialogController({ |
| 15 | + builder: ENewspaperListDialog({ newspaperListBean: this.newspaperListBean, | ||
| 16 | + currentPageNum: this.currentPageNum, | ||
| 17 | + }), | ||
| 18 | + alignment: DialogAlignment.Bottom | ||
| 19 | + }) | ||
| 20 | + | ||
| 21 | + @Builder | ||
| 22 | + popupBuilder() { | ||
| 23 | + Row() { | ||
| 24 | + GridRow({ columns: 5 }) { | ||
| 25 | + ForEach(this.newspaperListBean.list, (item: NewspaperListItemBean, index) => { | ||
| 26 | + GridCol() { | ||
| 27 | + Row() { | ||
| 28 | + Text(item.pageNum) | ||
| 29 | + .fontSize($r('app.float.normal_text_size')) | ||
| 30 | + .fontColor(this.currentPageNum == item.pageNum ? Color.White : $r('app.color.color_222222')) | ||
| 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.pageNumPopup = !this.pageNumPopup | ||
| 39 | + }) | ||
| 40 | + } | ||
| 41 | + }) | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + .padding({ top: 20, bottom: 20 }) | ||
| 45 | + .margin({ left: 10 }) | ||
| 46 | + .width(260) | ||
| 47 | + } | ||
| 13 | 48 | ||
| 14 | build() { | 49 | build() { |
| 15 | RelativeContainer() { | 50 | RelativeContainer() { |
| @@ -57,7 +92,7 @@ export struct ENewspaperPageComponent { | @@ -57,7 +92,7 @@ export struct ENewspaperPageComponent { | ||
| 57 | if (this.newspaperListBean && this.newspaperListBean.list && this.newspaperListBean.list.length > 0) { | 92 | if (this.newspaperListBean && this.newspaperListBean.list && this.newspaperListBean.list.length > 0) { |
| 58 | Swiper(this.swiperController) { | 93 | Swiper(this.swiperController) { |
| 59 | ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => { | 94 | ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => { |
| 60 | - ENewspaperItemComponent({newspaperListItemBean: item}) | 95 | + ENewspaperItemComponent({ newspaperListItemBean: item }) |
| 61 | }) | 96 | }) |
| 62 | } | 97 | } |
| 63 | .width('100%') | 98 | .width('100%') |
| @@ -121,6 +156,14 @@ export struct ENewspaperPageComponent { | @@ -121,6 +156,14 @@ export struct ENewspaperPageComponent { | ||
| 121 | .alignRules({ bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, | 156 | .alignRules({ bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, |
| 122 | left: { anchor: '__container__', align: HorizontalAlign.Start } }) | 157 | left: { anchor: '__container__', align: HorizontalAlign.Start } }) |
| 123 | .id('e_newspaper_page_num') | 158 | .id('e_newspaper_page_num') |
| 159 | + .onClick((event: ClickEvent) => { | ||
| 160 | + this.pageNumPopup = !this.pageNumPopup | ||
| 161 | + }) | ||
| 162 | + .bindPopup(this.pageNumPopup, { | ||
| 163 | + builder: this.popupBuilder, | ||
| 164 | + placement: Placement.Top, | ||
| 165 | + popupColor: Color.White | ||
| 166 | + }) | ||
| 124 | 167 | ||
| 125 | Row() { | 168 | Row() { |
| 126 | Image($r('app.media.icon_read_paper')) | 169 | Image($r('app.media.icon_read_paper')) |
| @@ -136,6 +179,9 @@ export struct ENewspaperPageComponent { | @@ -136,6 +179,9 @@ export struct ENewspaperPageComponent { | ||
| 136 | .alignRules({ bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, | 179 | .alignRules({ bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, |
| 137 | right: { anchor: '__container__', align: HorizontalAlign.End } }) | 180 | right: { anchor: '__container__', align: HorizontalAlign.End } }) |
| 138 | .id('e_newspaper_read') | 181 | .id('e_newspaper_read') |
| 182 | + .onClick((event: ClickEvent) => { | ||
| 183 | + this.listDialogController.open() | ||
| 184 | + }) | ||
| 139 | } | 185 | } |
| 140 | .width('100%') | 186 | .width('100%') |
| 141 | .height('100%') | 187 | .height('100%') |
| 1 | +import { NewspaperListBean, NewspaperListItemBean, NewspaperPositionItemBean } from 'wdBean' | ||
| 2 | + | ||
| 3 | +@CustomDialog | ||
| 4 | +export struct ENewspaperListDialog { | ||
| 5 | + @State currentPageNum: string = '01' | ||
| 6 | + controller: CustomDialogController | ||
| 7 | + newspaperListBean: NewspaperListBean = {} as NewspaperListBean | ||
| 8 | + | ||
| 9 | + build() { | ||
| 10 | + Column() { | ||
| 11 | + Row() { | ||
| 12 | + Text(this.currentPageNum) | ||
| 13 | + .fontSize($r('app.float.font_size_36')) | ||
| 14 | + .fontColor($r('app.color.color_222222')) | ||
| 15 | + Text('版') | ||
| 16 | + .fontSize($r('app.float.font_size_16')) | ||
| 17 | + .fontColor($r('app.color.color_222222')) | ||
| 18 | + .margin({ bottom: 6 }) | ||
| 19 | + | ||
| 20 | + Image($r('app.media.icon_triangle_black')) | ||
| 21 | + .width($r('app.float.border_radius_6')) | ||
| 22 | + .height($r('app.float.border_radius_6')) | ||
| 23 | + .margin({ left: 2, bottom: 6 }) | ||
| 24 | + } | ||
| 25 | + .alignItems(VerticalAlign.Bottom) | ||
| 26 | + .margin({ top: 25, left: 15 }) | ||
| 27 | + .alignSelf(ItemAlign.Start) | ||
| 28 | + | ||
| 29 | + Image($r('app.media.line')) | ||
| 30 | + .width('100%') | ||
| 31 | + .height(6) | ||
| 32 | + .margin({ top: 20, left: 16, right: 16 }) | ||
| 33 | + .objectFit(ImageFit.Contain) | ||
| 34 | + | ||
| 35 | + List() { | ||
| 36 | + ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => { | ||
| 37 | + ForEach(item.items, (positionItem: NewspaperPositionItemBean, itemIndex: number) => { | ||
| 38 | + ListItem() { | ||
| 39 | + Column(){ | ||
| 40 | + if (itemIndex == 0) { | ||
| 41 | + Text(item.pageNum + item.pageName) | ||
| 42 | + .fontSize($r('app.float.font_size_14')) | ||
| 43 | + .fontColor($r('app.color.color_ED2800')) | ||
| 44 | + .margin({ top: 16 }) | ||
| 45 | + .maxLines(1) | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + if (positionItem.shortTitle) { | ||
| 49 | + Text(positionItem.shortTitle) | ||
| 50 | + .fontSize($r('app.float.font_size_14')) | ||
| 51 | + .fontColor($r('app.color.color_222222')) | ||
| 52 | + .margin({ top: 16 }) | ||
| 53 | + .maxLines(2) | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + if (positionItem.title) { | ||
| 57 | + Text(positionItem.title) | ||
| 58 | + .fontSize($r('app.float.font_size_17')) | ||
| 59 | + .fontColor($r('app.color.color_222222')) | ||
| 60 | + .margin({ top: 16 }) | ||
| 61 | + .maxLines(2) | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + if (positionItem.downTitle) { | ||
| 65 | + Text(positionItem.downTitle) | ||
| 66 | + .fontSize($r('app.float.font_size_14')) | ||
| 67 | + .fontColor($r('app.color.color_222222')) | ||
| 68 | + .margin({ top: 16 }) | ||
| 69 | + .maxLines(2) | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + if (positionItem.newsTxt) { | ||
| 73 | + Text(positionItem.newsTxt) | ||
| 74 | + .fontSize($r('app.float.font_size_14')) | ||
| 75 | + .fontColor($r('app.color.color_999999')) | ||
| 76 | + .margin({ top: 16, bottom: 16 }) | ||
| 77 | + .maxLines(5) | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + .alignItems(HorizontalAlign.Start) | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + }) | ||
| 84 | + | ||
| 85 | + }) | ||
| 86 | + | ||
| 87 | + } | ||
| 88 | + .width('100%') | ||
| 89 | + .margin({ top: 16, left: 16, right: 16 }) | ||
| 90 | + .scrollBar(BarState.Off) | ||
| 91 | + .divider({ | ||
| 92 | + strokeWidth: 1, | ||
| 93 | + color: '#EDEDED' | ||
| 94 | + }) | ||
| 95 | + .onScrollIndex((firstIndex: number) => { | ||
| 96 | + this.updateCurrentPageNum(firstIndex) | ||
| 97 | + }) | ||
| 98 | + | ||
| 99 | + } | ||
| 100 | + .width('100%') | ||
| 101 | + .height(674) | ||
| 102 | + .backgroundColor(Color.White) | ||
| 103 | + | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + updateCurrentPageNum(firstIndex: number): void { | ||
| 107 | + if (this.newspaperListBean.list && this.newspaperListBean.list.length > 0) { | ||
| 108 | + let index = 0; | ||
| 109 | + for (let itemBean of this.newspaperListBean.list) { | ||
| 110 | + if (itemBean.items && itemBean.items.length > 0){ | ||
| 111 | + for (let item of itemBean.items){ | ||
| 112 | + index++ | ||
| 113 | + if (index == firstIndex){ | ||
| 114 | + this.currentPageNum = itemBean.pageNum | ||
| 115 | + return | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | + |
| @@ -27,6 +27,14 @@ | @@ -27,6 +27,14 @@ | ||
| 27 | { | 27 | { |
| 28 | "name": "color_80000000", | 28 | "name": "color_80000000", |
| 29 | "value": "#80000000" | 29 | "value": "#80000000" |
| 30 | + }, | ||
| 31 | + { | ||
| 32 | + "name": "color_222222", | ||
| 33 | + "value": "#222222" | ||
| 34 | + }, | ||
| 35 | + { | ||
| 36 | + "name": "color_ED2800", | ||
| 37 | + "value": "#ED2800" | ||
| 30 | } | 38 | } |
| 31 | ] | 39 | ] |
| 32 | } | 40 | } |
171 Bytes
520 Bytes
608 Bytes
-
Please register or login to post a comment