Showing
5 changed files
with
123 additions
and
19 deletions
| @@ -16,8 +16,8 @@ export struct ENewspaperItemComponent { | @@ -16,8 +16,8 @@ export struct ENewspaperItemComponent { | ||
| 16 | Stack() { | 16 | Stack() { |
| 17 | Image(this.newspaperListItemBean.pagePic) | 17 | Image(this.newspaperListItemBean.pagePic) |
| 18 | .width('100%') | 18 | .width('100%') |
| 19 | - .aspectRatio(0.68688) | ||
| 20 | - .objectFit(ImageFit.Contain) | 19 | + .aspectRatio(378 / 566) |
| 20 | + .objectFit(ImageFit.Fill) | ||
| 21 | 21 | ||
| 22 | Canvas(this.context) | 22 | Canvas(this.context) |
| 23 | .width('100%') | 23 | .width('100%') |
| @@ -27,8 +27,10 @@ export struct ENewspaperItemComponent { | @@ -27,8 +27,10 @@ export struct ENewspaperItemComponent { | ||
| 27 | 27 | ||
| 28 | }) | 28 | }) |
| 29 | } | 29 | } |
| 30 | + .padding({ top: 16, right: 16, bottom: 16, left: 16 }) | ||
| 31 | + .margin({ left: 10, right: 10 }) | ||
| 32 | + .backgroundColor(Color.White) | ||
| 30 | .width('100%') | 33 | .width('100%') |
| 31 | - .aspectRatio(0.68688) | ||
| 32 | .onTouch((event: TouchEvent) => { | 34 | .onTouch((event: TouchEvent) => { |
| 33 | if (event.type === TouchType.Down) { | 35 | if (event.type === TouchType.Down) { |
| 34 | let x = event.touches[0].x; | 36 | let x = event.touches[0].x; |
| @@ -36,10 +38,10 @@ export struct ENewspaperItemComponent { | @@ -36,10 +38,10 @@ export struct ENewspaperItemComponent { | ||
| 36 | this.startX = x; | 38 | this.startX = x; |
| 37 | this.startY = y; | 39 | this.startY = y; |
| 38 | let points: number[][] = this.getArea(x, y, this.newspaperListItemBean.items); | 40 | let points: number[][] = this.getArea(x, y, this.newspaperListItemBean.items); |
| 39 | - if (points && points.length > 2){ | 41 | + if (points && points.length > 2) { |
| 40 | let path = new Path2D(); | 42 | let path = new Path2D(); |
| 41 | path.moveTo(px2vp(points[0][0]), px2vp(points[0][1])); | 43 | path.moveTo(px2vp(points[0][0]), px2vp(points[0][1])); |
| 42 | - for(let point of points.slice(1, points.length)){ | 44 | + for (let point of points.slice(1, points.length)) { |
| 43 | path.lineTo(px2vp(point[0]), px2vp(point[1])); | 45 | path.lineTo(px2vp(point[0]), px2vp(point[1])); |
| 44 | } | 46 | } |
| 45 | path.closePath(); | 47 | path.closePath(); |
| @@ -52,14 +54,13 @@ export struct ENewspaperItemComponent { | @@ -52,14 +54,13 @@ export struct ENewspaperItemComponent { | ||
| 52 | } | 54 | } |
| 53 | if (event.type === TouchType.Up) { | 55 | if (event.type === TouchType.Up) { |
| 54 | this.context.clearRect(0, 0, this.context.width, this.context.height) | 56 | this.context.clearRect(0, 0, this.context.width, this.context.height) |
| 55 | - if (this.itemBeanClicked && this.itemBeanClicked.newsId){ | ||
| 56 | - // todo 跳转事件 | 57 | + if (this.itemBeanClicked && this.itemBeanClicked.newsId) { |
| 57 | let taskAction: Action = { | 58 | let taskAction: Action = { |
| 58 | type: 'JUMP_INNER_NEW_PAGE', | 59 | type: 'JUMP_INNER_NEW_PAGE', |
| 59 | params: { | 60 | params: { |
| 60 | - contentID:'30001758346', | 61 | + contentID: '30001758346', |
| 61 | pageID: 'IMAGE_TEXT_DETAIL', | 62 | pageID: 'IMAGE_TEXT_DETAIL', |
| 62 | - extra:{ | 63 | + extra: { |
| 63 | relType: '1', | 64 | relType: '1', |
| 64 | relId: '500000001277', | 65 | relId: '500000001277', |
| 65 | sourcePage: '5' | 66 | sourcePage: '5' |
| @@ -74,7 +75,7 @@ export struct ENewspaperItemComponent { | @@ -74,7 +75,7 @@ export struct ENewspaperItemComponent { | ||
| 74 | if (event.type === TouchType.Move) { | 75 | if (event.type === TouchType.Move) { |
| 75 | let mx = event.touches[0].x; | 76 | let mx = event.touches[0].x; |
| 76 | let my = event.touches[0].y; | 77 | let my = event.touches[0].y; |
| 77 | - if (this.startX - mx > 5 || mx - this.startX > 5 || this.startY - my > 5 || my - this.startY > 5){ | 78 | + if (this.startX - mx > 5 || mx - this.startX > 5 || this.startY - my > 5 || my - this.startY > 5) { |
| 78 | this.itemBeanClicked = {} as NewspaperPositionItemBean | 79 | this.itemBeanClicked = {} as NewspaperPositionItemBean |
| 79 | this.context.clearRect(0, 0, this.context.width, this.context.height) | 80 | this.context.clearRect(0, 0, this.context.width, this.context.height) |
| 80 | } | 81 | } |
| @@ -97,8 +98,7 @@ export struct ENewspaperItemComponent { | @@ -97,8 +98,7 @@ export struct ENewspaperItemComponent { | ||
| 97 | for (let item of area) { | 98 | for (let item of area) { |
| 98 | let pair: string[] = item.split(','); | 99 | let pair: string[] = item.split(','); |
| 99 | if (pair && pair.length > 1) { | 100 | if (pair && pair.length > 1) { |
| 100 | - // todo 因为数据是根据安卓手机抓的,这里根据分辨率倍数做了数据放大处理,真实数据不用乘以放大倍数 | ||
| 101 | - let xy: number[] = [StringUtils.parseNumber(pair[0])*1.215, StringUtils.parseNumber(pair[1])*1.16] | 101 | + let xy: number[] = [StringUtils.parseNumber(pair[0]), StringUtils.parseNumber(pair[1])] |
| 102 | if (minX < 0) { | 102 | if (minX < 0) { |
| 103 | minX = xy[0] | 103 | minX = xy[0] |
| 104 | } else { | 104 | } else { |
| @@ -4,12 +4,15 @@ import router from '@ohos.router'; | @@ -4,12 +4,15 @@ 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 | import { ENewspaperListDialog } from '../dialog/ENewspaperListDialog'; |
| 7 | +import display from '@ohos.display'; | ||
| 7 | 8 | ||
| 8 | @Component | 9 | @Component |
| 9 | export struct ENewspaperPageComponent { | 10 | export struct ENewspaperPageComponent { |
| 10 | @State newspaperListBean: NewspaperListBean = {} as NewspaperListBean | 11 | @State newspaperListBean: NewspaperListBean = {} as NewspaperListBean |
| 11 | @State currentPageNum: string = '01' | 12 | @State currentPageNum: string = '01' |
| 12 | @State pageNumPopup: boolean = false | 13 | @State pageNumPopup: boolean = false |
| 14 | + @State date: string = '2024-01-26' | ||
| 15 | + @State picHeight: number = 0 | ||
| 13 | private swiperController: SwiperController = new SwiperController() | 16 | private swiperController: SwiperController = new SwiperController() |
| 14 | listDialogController: CustomDialogController = new CustomDialogController({ | 17 | listDialogController: CustomDialogController = new CustomDialogController({ |
| 15 | builder: ENewspaperListDialog({ newspaperListBean: this.newspaperListBean, | 18 | builder: ENewspaperListDialog({ newspaperListBean: this.newspaperListBean, |
| @@ -61,7 +64,7 @@ export struct ENewspaperPageComponent { | @@ -61,7 +64,7 @@ export struct ENewspaperPageComponent { | ||
| 61 | }) | 64 | }) |
| 62 | 65 | ||
| 63 | Row() { | 66 | Row() { |
| 64 | - Text('2024.01.26') | 67 | + Text(this.date) |
| 65 | .fontSize($r('app.float.font_size_20')) | 68 | .fontSize($r('app.float.font_size_20')) |
| 66 | .fontColor($r('app.color.white')) | 69 | .fontColor($r('app.color.white')) |
| 67 | 70 | ||
| @@ -96,13 +99,13 @@ export struct ENewspaperPageComponent { | @@ -96,13 +99,13 @@ export struct ENewspaperPageComponent { | ||
| 96 | }) | 99 | }) |
| 97 | } | 100 | } |
| 98 | .width('100%') | 101 | .width('100%') |
| 102 | + .height(px2vp(this.picHeight) + 32) | ||
| 99 | .vertical(true) | 103 | .vertical(true) |
| 100 | .autoPlay(false) | 104 | .autoPlay(false) |
| 101 | .cachedCount(3) | 105 | .cachedCount(3) |
| 102 | .indicator(false) | 106 | .indicator(false) |
| 103 | .displayCount(1) | 107 | .displayCount(1) |
| 104 | - .aspectRatio(0.68688) | ||
| 105 | - .margin({ top: $r('app.float.vp_55'), left: 10, right: 10 }) | 108 | + .margin({ top: 35, left: 10, right: 10 }) |
| 106 | .id('e_newspaper_content') | 109 | .id('e_newspaper_content') |
| 107 | .alignRules({ top: { anchor: "e_newspaper_top", align: VerticalAlign.Bottom }, | 110 | .alignRules({ top: { anchor: "e_newspaper_top", align: VerticalAlign.Bottom }, |
| 108 | middle: { anchor: "__container__", align: HorizontalAlign.Center } }) | 111 | middle: { anchor: "__container__", align: HorizontalAlign.Center } }) |
| @@ -112,7 +115,7 @@ export struct ENewspaperPageComponent { | @@ -112,7 +115,7 @@ export struct ENewspaperPageComponent { | ||
| 112 | 115 | ||
| 113 | Image($r('app.media.newspaper_shadow')) | 116 | Image($r('app.media.newspaper_shadow')) |
| 114 | .height($r('app.float.vp_12')) | 117 | .height($r('app.float.vp_12')) |
| 115 | - .margin({ left: 12, right: 12, top: -5 }) | 118 | + .margin({ left: 12, right: 12, top: -1 }) |
| 116 | .objectFit(ImageFit.Contain) | 119 | .objectFit(ImageFit.Contain) |
| 117 | .alignRules({ top: { anchor: "e_newspaper_content", align: VerticalAlign.Bottom }, | 120 | .alignRules({ top: { anchor: "e_newspaper_content", align: VerticalAlign.Bottom }, |
| 118 | left: { anchor: 'e_newspaper_content', align: HorizontalAlign.Start }, | 121 | left: { anchor: 'e_newspaper_content', align: HorizontalAlign.Start }, |
| @@ -189,9 +192,22 @@ export struct ENewspaperPageComponent { | @@ -189,9 +192,22 @@ export struct ENewspaperPageComponent { | ||
| 189 | .id('e_newspaper_container') | 192 | .id('e_newspaper_container') |
| 190 | } | 193 | } |
| 191 | 194 | ||
| 192 | - aboutToAppear() { | ||
| 193 | - let listBean = NewspaperViewModel.getNewspaperListFromLocal(getContext(this)); | 195 | + async aboutToAppear() { |
| 196 | + let newspaperTimes = await NewspaperViewModel.getNewspaperTime() | ||
| 197 | + if (newspaperTimes && newspaperTimes.length > 0) { | ||
| 198 | + this.date = newspaperTimes[0].date | ||
| 199 | + } | ||
| 200 | + try { | ||
| 201 | + let displayTool = display.getDefaultDisplaySync() | ||
| 202 | + let screenWidth = displayTool.width | ||
| 203 | + let picWidth = screenWidth - vp2px(52) | ||
| 204 | + this.picHeight = picWidth * 566 / 378 | ||
| 205 | + let listBean = await NewspaperViewModel.getNewspaperList(this.date, picWidth + 'x' + this.picHeight) | ||
| 194 | this.newspaperListBean = listBean; | 206 | this.newspaperListBean = listBean; |
| 207 | + } catch (exception) { | ||
| 208 | + | ||
| 209 | + } | ||
| 210 | + | ||
| 195 | 211 | ||
| 196 | } | 212 | } |
| 197 | 213 |
| 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 } from 'wdKit'; | 3 | import { DateTimeUtils } from 'wdKit'; |
| 4 | -import { ContentDetailDTO, NavigationBodyDTO, PageDTO,InteractDataDTO, MorningEveningPaperDTO } from 'wdBean'; | 4 | +import { ContentDetailDTO, NavigationBodyDTO, PageDTO,InteractDataDTO, MorningEveningPaperDTO, |
| 5 | + NewspaperTimeInfoBean, | ||
| 6 | + NewspaperListBean | ||
| 7 | +} from 'wdBean'; | ||
| 5 | 8 | ||
| 6 | export class PageRepository { | 9 | export class PageRepository { |
| 7 | static getBottomNavGroupUrl() { | 10 | static getBottomNavGroupUrl() { |
| @@ -53,6 +56,18 @@ export class PageRepository { | @@ -53,6 +56,18 @@ export class PageRepository { | ||
| 53 | return url; | 56 | return url; |
| 54 | } | 57 | } |
| 55 | 58 | ||
| 59 | + static getNewspaperInfoUrl() { | ||
| 60 | + let url = HttpUrlUtils.getHost() + HttpUrlUtils.E_NEWSPAPER_INFO_PATH; | ||
| 61 | + return url; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + static getNewspaperListUrl(date: string, pageSize: string) { | ||
| 65 | + let url = HttpUrlUtils.getHost() + HttpUrlUtils.E_NEWSPAPER_LIST_PATH; | ||
| 66 | + url = url + "?date=" + date | ||
| 67 | + + "&pagesSize=" + pageSize; | ||
| 68 | + return url; | ||
| 69 | + } | ||
| 70 | + | ||
| 56 | static fetchNavigationDataApi() { | 71 | static fetchNavigationDataApi() { |
| 57 | let url = PageRepository.getBottomNavGroupUrl(); | 72 | let url = PageRepository.getBottomNavGroupUrl(); |
| 58 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 73 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| @@ -91,4 +106,16 @@ export class PageRepository { | @@ -91,4 +106,16 @@ export class PageRepository { | ||
| 91 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 106 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 92 | return WDHttp.post<ResponseDTO<InteractDataDTO[]>>(url, param, headers) | 107 | return WDHttp.post<ResponseDTO<InteractDataDTO[]>>(url, param, headers) |
| 93 | }; | 108 | }; |
| 109 | + | ||
| 110 | + static fetchNewspaperInfo() { | ||
| 111 | + let url = PageRepository.getNewspaperInfoUrl() | ||
| 112 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 113 | + return WDHttp.get<ResponseDTO<NewspaperTimeInfoBean[]>>(url, headers) | ||
| 114 | + }; | ||
| 115 | + | ||
| 116 | + static fetchNewspaperList(date: string, pageSize: string) { | ||
| 117 | + let url = PageRepository.getNewspaperListUrl(date, pageSize) | ||
| 118 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 119 | + return WDHttp.get<ResponseDTO<NewspaperListBean>>(url, headers) | ||
| 120 | + }; | ||
| 94 | } | 121 | } |
| 1 | import { Logger, ResourcesUtils } from 'wdKit'; | 1 | import { Logger, ResourcesUtils } from 'wdKit'; |
| 2 | import { ResponseDTO } from 'wdNetwork'; | 2 | import { ResponseDTO } from 'wdNetwork'; |
| 3 | import { NewspaperListBean, NewspaperTimeInfoBean } from 'wdBean'; | 3 | import { NewspaperListBean, NewspaperTimeInfoBean } from 'wdBean'; |
| 4 | +import { PageRepository } from '../repository/PageRepository'; | ||
| 4 | 5 | ||
| 5 | const TAG = 'NewspaperViewModel'; | 6 | const TAG = 'NewspaperViewModel'; |
| 6 | 7 | ||
| @@ -15,6 +16,53 @@ export class NewspaperViewModel { | @@ -15,6 +16,53 @@ export class NewspaperViewModel { | ||
| 15 | return newspaperTimeInfo.data | 16 | return newspaperTimeInfo.data |
| 16 | } | 17 | } |
| 17 | 18 | ||
| 19 | + static async getNewspaperTime(): Promise<NewspaperTimeInfoBean[]> { | ||
| 20 | + return new Promise<NewspaperTimeInfoBean[]>((success, error) => { | ||
| 21 | + Logger.info(TAG, `getNavData start`); | ||
| 22 | + PageRepository.fetchNewspaperInfo().then((resDTO: ResponseDTO<NewspaperTimeInfoBean[]>) => { | ||
| 23 | + if (!resDTO || !resDTO.data) { | ||
| 24 | + Logger.error(TAG, 'getNewspaperTime then navResDTO is empty'); | ||
| 25 | + error('resDTO is empty'); | ||
| 26 | + return | ||
| 27 | + } | ||
| 28 | + if (resDTO.code != 0) { | ||
| 29 | + Logger.error(TAG, `getNewspaperTime then code:${resDTO.code}, message:${resDTO.message}`); | ||
| 30 | + error('resDTO Response Code is failure'); | ||
| 31 | + return | ||
| 32 | + } | ||
| 33 | + Logger.info(TAG, "getNewspaperTime then,navResDTO.timestamp:" + resDTO.timestamp); | ||
| 34 | + success(resDTO.data); | ||
| 35 | + }).catch((err: Error) => { | ||
| 36 | + Logger.error(TAG, `getNewspaperTime catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 37 | + error(err); | ||
| 38 | + }) | ||
| 39 | + }) | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + static async getNewspaperList(date: string, pageSize: string): Promise<NewspaperListBean> { | ||
| 43 | + return new Promise<NewspaperListBean>((success, error) => { | ||
| 44 | + Logger.info(TAG, `getNavData start`); | ||
| 45 | + PageRepository.fetchNewspaperList(date, pageSize).then((resDTO: ResponseDTO<NewspaperListBean>) => { | ||
| 46 | + if (!resDTO || !resDTO.data) { | ||
| 47 | + Logger.error(TAG, 'getNewspaperList then navResDTO is empty'); | ||
| 48 | + error('resDTO is empty'); | ||
| 49 | + return | ||
| 50 | + } | ||
| 51 | + if (resDTO.code != 0) { | ||
| 52 | + Logger.error(TAG, `getNewspaperList then code:${resDTO.code}, message:${resDTO.message}`); | ||
| 53 | + error('resDTO Response Code is failure'); | ||
| 54 | + return | ||
| 55 | + } | ||
| 56 | + // let navResStr = JSON.stringify(navResDTO); | ||
| 57 | + Logger.info(TAG, "getNewspaperList then,navResDTO.timestamp:" + resDTO.timestamp); | ||
| 58 | + success(resDTO.data); | ||
| 59 | + }).catch((err: Error) => { | ||
| 60 | + Logger.error(TAG, `getNewspaperList catch, error.name : ${err.name}, error.message:${err.message}`); | ||
| 61 | + error(err); | ||
| 62 | + }) | ||
| 63 | + }) | ||
| 64 | + } | ||
| 65 | + | ||
| 18 | static getNewspaperListFromLocal(context: Context): NewspaperListBean { | 66 | static getNewspaperListFromLocal(context: Context): NewspaperListBean { |
| 19 | let newspaperListBean: ResponseDTO<NewspaperListBean> | null = ResourcesUtils.getResourcesJsonSync<ResponseDTO<NewspaperListBean>>(context, 'newspaper_datalist.json'); | 67 | let newspaperListBean: ResponseDTO<NewspaperListBean> | null = ResourcesUtils.getResourcesJsonSync<ResponseDTO<NewspaperListBean>>(context, 'newspaper_datalist.json'); |
| 20 | if (!newspaperListBean || !newspaperListBean.data) { | 68 | if (!newspaperListBean || !newspaperListBean.data) { |
| @@ -23,4 +71,6 @@ export class NewspaperViewModel { | @@ -23,4 +71,6 @@ export class NewspaperViewModel { | ||
| 23 | } | 71 | } |
| 24 | return newspaperListBean.data | 72 | return newspaperListBean.data |
| 25 | } | 73 | } |
| 74 | + | ||
| 75 | + | ||
| 26 | } | 76 | } |
| @@ -43,6 +43,17 @@ export class HttpUrlUtils { | @@ -43,6 +43,17 @@ export class HttpUrlUtils { | ||
| 43 | * 批查接口,查询互动相关数据,如收藏数、评论数等 | 43 | * 批查接口,查询互动相关数据,如收藏数、评论数等 |
| 44 | */ | 44 | */ |
| 45 | static readonly INTERACT_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/content/interactData"; | 45 | static readonly INTERACT_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/content/interactData"; |
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 电子报信息 | ||
| 49 | + */ | ||
| 50 | + static readonly E_NEWSPAPER_INFO_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/paperApi/paperTime"; | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 电子报列表 | ||
| 54 | + */ | ||
| 55 | + static readonly E_NEWSPAPER_LIST_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/paperApi/paperList"; | ||
| 56 | + | ||
| 46 | private static hostUrl: string = HttpUrlUtils.HOST_PRODUCT; | 57 | private static hostUrl: string = HttpUrlUtils.HOST_PRODUCT; |
| 47 | 58 | ||
| 48 | static getCommonHeaders(): HashMap<string, string> { | 59 | static getCommonHeaders(): HashMap<string, string> { |
-
Please register or login to post a comment