Showing
2 changed files
with
29 additions
and
6 deletions
| @@ -6,12 +6,15 @@ export struct ENewspaperItemComponent { | @@ -6,12 +6,15 @@ export struct ENewspaperItemComponent { | ||
| 6 | private newspaperListItemBean: NewspaperListItemBean = {} as NewspaperListItemBean | 6 | private newspaperListItemBean: NewspaperListItemBean = {} as NewspaperListItemBean |
| 7 | private settings: RenderingContextSettings = new RenderingContextSettings(true); | 7 | private settings: RenderingContextSettings = new RenderingContextSettings(true); |
| 8 | private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); | 8 | private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); |
| 9 | + private startX: number = 0 | ||
| 10 | + private startY: number = 0 | ||
| 11 | + private itemBeanClicked: NewspaperPositionItemBean = {} as NewspaperPositionItemBean | ||
| 9 | 12 | ||
| 10 | build() { | 13 | build() { |
| 11 | Stack() { | 14 | Stack() { |
| 12 | Image(this.newspaperListItemBean.pagePic) | 15 | Image(this.newspaperListItemBean.pagePic) |
| 13 | .width('100%') | 16 | .width('100%') |
| 14 | - .height('100%') | 17 | + .aspectRatio(0.68688) |
| 15 | .objectFit(ImageFit.Contain) | 18 | .objectFit(ImageFit.Contain) |
| 16 | 19 | ||
| 17 | Canvas(this.context) | 20 | Canvas(this.context) |
| @@ -23,11 +26,21 @@ export struct ENewspaperItemComponent { | @@ -23,11 +26,21 @@ export struct ENewspaperItemComponent { | ||
| 23 | }) | 26 | }) |
| 24 | } | 27 | } |
| 25 | .width('100%') | 28 | .width('100%') |
| 26 | - .aspectRatio(0.7) | 29 | + .aspectRatio(0.68688) |
| 30 | + .onClick((event: ClickEvent) =>{ | ||
| 31 | + if (this.itemBeanClicked && this.itemBeanClicked.newsId){ | ||
| 32 | + // todo 跳转事件 | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + this.itemBeanClicked = {} as NewspaperPositionItemBean | ||
| 36 | + } | ||
| 37 | + }) | ||
| 27 | .onTouch((event: TouchEvent) => { | 38 | .onTouch((event: TouchEvent) => { |
| 28 | if (event.type === TouchType.Down) { | 39 | if (event.type === TouchType.Down) { |
| 29 | let x = event.touches[0].x; | 40 | let x = event.touches[0].x; |
| 30 | let y = event.touches[0].y; | 41 | let y = event.touches[0].y; |
| 42 | + this.startX = x; | ||
| 43 | + this.startY = y; | ||
| 31 | let points: number[][] = this.getArea(x, y, this.newspaperListItemBean.items); | 44 | let points: number[][] = this.getArea(x, y, this.newspaperListItemBean.items); |
| 32 | if (points && points.length > 2){ | 45 | if (points && points.length > 2){ |
| 33 | let path = new Path2D(); | 46 | let path = new Path2D(); |
| @@ -47,7 +60,13 @@ export struct ENewspaperItemComponent { | @@ -47,7 +60,13 @@ export struct ENewspaperItemComponent { | ||
| 47 | this.context.clearRect(0, 0, this.context.width, this.context.height) | 60 | this.context.clearRect(0, 0, this.context.width, this.context.height) |
| 48 | } | 61 | } |
| 49 | if (event.type === TouchType.Move) { | 62 | if (event.type === TouchType.Move) { |
| 50 | - // this.context.clearRect(0, 0, this.context.width, this.context.height) | 63 | + let mx = event.touches[0].x; |
| 64 | + let my = event.touches[0].y; | ||
| 65 | + if (this.startX - mx > 5 || mx - this.startX > 5 || this.startY - my > 5 || my - this.startY > 5){ | ||
| 66 | + this.itemBeanClicked = {} as NewspaperPositionItemBean | ||
| 67 | + this.context.clearRect(0, 0, this.context.width, this.context.height) | ||
| 68 | + } | ||
| 69 | + | ||
| 51 | } | 70 | } |
| 52 | }) | 71 | }) |
| 53 | } | 72 | } |
| @@ -66,7 +85,8 @@ export struct ENewspaperItemComponent { | @@ -66,7 +85,8 @@ export struct ENewspaperItemComponent { | ||
| 66 | for (let item of area) { | 85 | for (let item of area) { |
| 67 | let pair: string[] = item.split(','); | 86 | let pair: string[] = item.split(','); |
| 68 | if (pair && pair.length > 1) { | 87 | if (pair && pair.length > 1) { |
| 69 | - let xy: number[] = [StringUtils.parseNumber(pair[0]), StringUtils.parseNumber(pair[1])] | 88 | + // todo 因为数据是根据安卓手机抓的,这里根据分辨率倍数做了数据放大处理,真实数据不用乘以放大倍数 |
| 89 | + let xy: number[] = [StringUtils.parseNumber(pair[0])*1.28, StringUtils.parseNumber(pair[1])*1.24] | ||
| 70 | if (minX < 0) { | 90 | if (minX < 0) { |
| 71 | minX = xy[0] | 91 | minX = xy[0] |
| 72 | } else { | 92 | } else { |
| @@ -101,6 +121,7 @@ export struct ENewspaperItemComponent { | @@ -101,6 +121,7 @@ export struct ENewspaperItemComponent { | ||
| 101 | } | 121 | } |
| 102 | 122 | ||
| 103 | if (vp2px(x) > minX && vp2px(x) < maxX && vp2px(y) > minY && vp2px(y) < maxY) { | 123 | if (vp2px(x) > minX && vp2px(x) < maxX && vp2px(y) > minY && vp2px(y) < maxY) { |
| 124 | + this.itemBeanClicked = itemBean; | ||
| 104 | return xys; | 125 | return xys; |
| 105 | } | 126 | } |
| 106 | } | 127 | } |
| 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'; | ||
| 4 | import { ENewspaperItemComponent } from './ENewspaperItemComponent' | 5 | import { ENewspaperItemComponent } from './ENewspaperItemComponent' |
| 5 | 6 | ||
| 6 | @Component | 7 | @Component |
| @@ -20,6 +21,7 @@ export struct ENewspaperPageComponent { | @@ -20,6 +21,7 @@ export struct ENewspaperPageComponent { | ||
| 20 | center: { anchor: "__container__", align: VerticalAlign.Center } }) | 21 | center: { anchor: "__container__", align: VerticalAlign.Center } }) |
| 21 | .id('e_newspaper_back') | 22 | .id('e_newspaper_back') |
| 22 | .onClick((event: ClickEvent) => { | 23 | .onClick((event: ClickEvent) => { |
| 24 | + Logger.info("sfsfsd", "" + vp2px(10)) | ||
| 23 | router.back() | 25 | router.back() |
| 24 | }) | 26 | }) |
| 25 | 27 | ||
| @@ -64,7 +66,7 @@ export struct ENewspaperPageComponent { | @@ -64,7 +66,7 @@ export struct ENewspaperPageComponent { | ||
| 64 | .cachedCount(3) | 66 | .cachedCount(3) |
| 65 | .indicator(false) | 67 | .indicator(false) |
| 66 | .displayCount(1) | 68 | .displayCount(1) |
| 67 | - .aspectRatio(0.7) | 69 | + .aspectRatio(0.68688) |
| 68 | .margin({ top: $r('app.float.vp_55'), left: 10, right: 10 }) | 70 | .margin({ top: $r('app.float.vp_55'), left: 10, right: 10 }) |
| 69 | .id('e_newspaper_content') | 71 | .id('e_newspaper_content') |
| 70 | .alignRules({ top: { anchor: "e_newspaper_top", align: VerticalAlign.Bottom }, | 72 | .alignRules({ top: { anchor: "e_newspaper_top", align: VerticalAlign.Bottom }, |
| @@ -75,7 +77,7 @@ export struct ENewspaperPageComponent { | @@ -75,7 +77,7 @@ export struct ENewspaperPageComponent { | ||
| 75 | 77 | ||
| 76 | Image($r('app.media.newspaper_shadow')) | 78 | Image($r('app.media.newspaper_shadow')) |
| 77 | .height($r('app.float.vp_12')) | 79 | .height($r('app.float.vp_12')) |
| 78 | - .margin({ left: 12, right: 12, top: -2 }) | 80 | + .margin({ left: 12, right: 12, top: -5 }) |
| 79 | .objectFit(ImageFit.Contain) | 81 | .objectFit(ImageFit.Contain) |
| 80 | .alignRules({ top: { anchor: "e_newspaper_content", align: VerticalAlign.Bottom }, | 82 | .alignRules({ top: { anchor: "e_newspaper_content", align: VerticalAlign.Bottom }, |
| 81 | left: { anchor: 'e_newspaper_content', align: HorizontalAlign.Start }, | 83 | left: { anchor: 'e_newspaper_content', align: HorizontalAlign.Start }, |
-
Please register or login to post a comment