Showing
1 changed file
with
74 additions
and
47 deletions
| 1 | -import { EmitterEventId, EmitterUtils } from 'wdKit/Index' | 1 | +import { DisplayUtils, EmitterEventId, EmitterUtils } from 'wdKit/Index' |
| 2 | import { publishCommentModel } from '../model/PublishCommentModel' | 2 | import { publishCommentModel } from '../model/PublishCommentModel' |
| 3 | import { CommentCustomDialog } from './CommentCustomDialog' | 3 | import { CommentCustomDialog } from './CommentCustomDialog' |
| 4 | - | 4 | +import measure from '@ohos.measure' |
| 5 | 5 | ||
| 6 | @Preview | 6 | @Preview |
| 7 | @Component | 7 | @Component |
| 8 | export struct CommentTabComponent { | 8 | export struct CommentTabComponent { |
| 9 | @ObjectLink publishCommentModel: publishCommentModel | 9 | @ObjectLink publishCommentModel: publishCommentModel |
| 10 | /*展示类型*/ | 10 | /*展示类型*/ |
| 11 | - @State type:number = 1 | 11 | + @State type: number = 1 |
| 12 | @State placeHolder: string = '说两句...' | 12 | @State placeHolder: string = '说两句...' |
| 13 | - | ||
| 14 | @State dialogController: CustomDialogController | null = null; | 13 | @State dialogController: CustomDialogController | null = null; |
| 15 | - | ||
| 16 | /*回调方法*/ | 14 | /*回调方法*/ |
| 17 | - dialogControllerConfirm: () => void = () => {} | ||
| 18 | - | ||
| 19 | - | 15 | + dialogControllerConfirm: () => void = () => { |
| 16 | + } | ||
| 20 | 17 | ||
| 21 | aboutToAppear() { | 18 | aboutToAppear() { |
| 22 | 19 | ||
| @@ -24,9 +21,9 @@ export struct CommentTabComponent { | @@ -24,9 +21,9 @@ export struct CommentTabComponent { | ||
| 24 | builder: CommentCustomDialog({ | 21 | builder: CommentCustomDialog({ |
| 25 | confirm: (value: Record<string, string>) => { | 22 | confirm: (value: Record<string, string>) => { |
| 26 | this.dialogControllerConfirm(); | 23 | this.dialogControllerConfirm(); |
| 27 | - EmitterUtils.sendEvent(EmitterEventId.COMMENT_PUBLISH,this.publishCommentModel.targetId) | 24 | + EmitterUtils.sendEvent(EmitterEventId.COMMENT_PUBLISH, this.publishCommentModel.targetId) |
| 28 | }, | 25 | }, |
| 29 | - publishCommentModel:this.publishCommentModel | 26 | + publishCommentModel: this.publishCommentModel |
| 30 | }), | 27 | }), |
| 31 | autoCancel: true, | 28 | autoCancel: true, |
| 32 | alignment: DialogAlignment.Bottom, | 29 | alignment: DialogAlignment.Bottom, |
| @@ -40,13 +37,13 @@ export struct CommentTabComponent { | @@ -40,13 +37,13 @@ export struct CommentTabComponent { | ||
| 40 | } | 37 | } |
| 41 | 38 | ||
| 42 | build() { | 39 | build() { |
| 43 | - Row(){ | ||
| 44 | - Stack({alignContent:Alignment.Start}){ | 40 | + Row() { |
| 41 | + Stack({ alignContent: Alignment.Start }) { | ||
| 45 | Image($r('app.media.comment_img_input_hui')).width(151).height(30) | 42 | Image($r('app.media.comment_img_input_hui')).width(151).height(30) |
| 46 | - Text(this.placeHolder).fontSize(12).fontColor('#999999').margin({left:10}) | 43 | + Text(this.placeHolder).fontSize(12).fontColor('#999999').margin({ left: 10 }) |
| 47 | } | 44 | } |
| 48 | }.width(151).height(30) | 45 | }.width(151).height(30) |
| 49 | - .onClick(()=>{ | 46 | + .onClick(() => { |
| 50 | this.publishCommentModel.parentId = '-1'; | 47 | this.publishCommentModel.parentId = '-1'; |
| 51 | this.dialogController?.open(); | 48 | this.dialogController?.open(); |
| 52 | }) | 49 | }) |
| @@ -58,54 +55,84 @@ export struct CommentTabComponent { | @@ -58,54 +55,84 @@ export struct CommentTabComponent { | ||
| 58 | export struct CommentIconComponent { | 55 | export struct CommentIconComponent { |
| 59 | @ObjectLink publishCommentModel: publishCommentModel | 56 | @ObjectLink publishCommentModel: publishCommentModel |
| 60 | /*展示类型*/ | 57 | /*展示类型*/ |
| 61 | - @State type:number = 1 | 58 | + @State type: number = 1 |
| 59 | + | ||
| 60 | + aboutToAppear(): void { | ||
| 61 | + setTimeout(() => { | ||
| 62 | + this.publishCommentModel.totalCommentNumer = '444' | ||
| 63 | + }, 3000); | ||
| 64 | + | ||
| 65 | + setTimeout(() => { | ||
| 66 | + this.publishCommentModel.totalCommentNumer = '2' | ||
| 67 | + }, 4000); | ||
| 68 | + | ||
| 69 | + } | ||
| 62 | 70 | ||
| 63 | /*回调方法*/ | 71 | /*回调方法*/ |
| 64 | - onClickItem: () => void = () => {} | 72 | + onClickItem: () => void = () => { |
| 73 | + } | ||
| 65 | 74 | ||
| 66 | build() { | 75 | build() { |
| 67 | - Row(){ | ||
| 68 | - Stack({alignContent:Alignment.TopEnd}){ | 76 | + Row() { |
| 77 | + Stack({ alignContent: Alignment.TopEnd }) { | ||
| 69 | Image($r('app.media.comment_icon')).width(24).height(24) | 78 | Image($r('app.media.comment_icon')).width(24).height(24) |
| 70 | // Stack({alignContent:Alignment.Start}) { | 79 | // Stack({alignContent:Alignment.Start}) { |
| 71 | - RelativeContainer() { | ||
| 72 | - Image($r('app.media.comment_icon_number_bg')) | ||
| 73 | - .objectFit(ImageFit.Fill) | ||
| 74 | - .resizable({ slice: {top:1, left: 20 , right:1, bottom:1} }) | ||
| 75 | - .alignRules({ | ||
| 76 | - top: {anchor: "Text", align: VerticalAlign.Top}, | ||
| 77 | - left: {anchor: "Text", align: HorizontalAlign.Start}, | ||
| 78 | - right: {anchor: "Text", align: HorizontalAlign.End}, | ||
| 79 | - bottom : {anchor: "Text", align: VerticalAlign.Bottom}, | ||
| 80 | - }) | ||
| 81 | - // .offset({ | 80 | + // if(Number.parseInt(this.publishCommentModel.totalCommentNumer) != 0){ |
| 81 | + RelativeContainer() { | ||
| 82 | + Image($r('app.media.comment_icon_number_bg')) | ||
| 83 | + .objectFit(ImageFit.Fill) | ||
| 84 | + .resizable({ slice: { top: 1, left: 20, right: 1, bottom: 1 } }) | ||
| 85 | + .alignRules({ | ||
| 86 | + top: { anchor: "Text", align: VerticalAlign.Top }, | ||
| 87 | + left: { anchor: "Text", align: HorizontalAlign.Start }, | ||
| 88 | + right: { anchor: "Text", align: HorizontalAlign.End }, | ||
| 89 | + bottom: { anchor: "Text", align: VerticalAlign.Bottom }, | ||
| 90 | + })// .offset({ | ||
| 82 | // x:-6 | 91 | // x:-6 |
| 83 | // }) | 92 | // }) |
| 84 | - .id("Image") | ||
| 85 | - | ||
| 86 | - Text('123213123123123') | ||
| 87 | - .fontSize(8) | ||
| 88 | - .fontColor('#ffffff')// .backgroundColor('#ED2800') | ||
| 89 | - .height(12) | ||
| 90 | - .alignRules({ | ||
| 91 | - top: {anchor: "__container__", align: VerticalAlign.Top}, | ||
| 92 | - left: {anchor: "__container__", align: HorizontalAlign.Start} | ||
| 93 | - }) | ||
| 94 | - // .margin({left: 4,right:4 | 93 | + .id("Image") |
| 94 | + | ||
| 95 | + Text(this.publishCommentModel.totalCommentNumer)// Text("44444444") | ||
| 96 | + .fontSize(8) | ||
| 97 | + .fontColor('#ffffff')// .backgroundColor('#ED2800') | ||
| 98 | + .height(12) | ||
| 99 | + .textAlign(TextAlign.Center) | ||
| 100 | + .alignRules({ | ||
| 101 | + top: { anchor: "__container__", align: VerticalAlign.Top }, | ||
| 102 | + left: { anchor: "__container__", align: HorizontalAlign.Start } | ||
| 103 | + })// .margin({left: 4,right:4 | ||
| 95 | // }) | 104 | // }) |
| 96 | /*动态计算文字宽度*/ | 105 | /*动态计算文字宽度*/ |
| 97 | - .width(50) | ||
| 98 | - // .backgroundColor(Color.Green) | ||
| 99 | - .id("Text") | 106 | + .width(this.getMeasureText(this.publishCommentModel.totalCommentNumer) + 12)// .backgroundColor(Color.Green) |
| 107 | + .id("Text") | ||
| 108 | + // .offset({ | ||
| 109 | + // x: 3 | ||
| 110 | + // }) | ||
| 100 | 111 | ||
| 101 | - } | 112 | + } |
| 102 | // } | 113 | // } |
| 103 | - | ||
| 104 | .offset({ | 114 | .offset({ |
| 105 | - x:12 | 115 | + x: 12 |
| 106 | }) | 116 | }) |
| 117 | + | ||
| 118 | + // } | ||
| 107 | } | 119 | } |
| 108 | }.width(24).height(24) | 120 | }.width(24).height(24) |
| 121 | + | ||
| 109 | // .backgroundColor(Color.Blue) | 122 | // .backgroundColor(Color.Blue) |
| 110 | } | 123 | } |
| 111 | -} | ||
| 124 | + | ||
| 125 | + private getMeasureText(text: string) { | ||
| 126 | + | ||
| 127 | + | ||
| 128 | + let width = measure.measureText({ | ||
| 129 | + textContent: text, | ||
| 130 | + fontSize: 8, | ||
| 131 | + lineHeight: 12, | ||
| 132 | + constraintWidth: DisplayUtils.getDeviceWidth(), | ||
| 133 | + }) | ||
| 134 | + width = px2vp(width) | ||
| 135 | + return width | ||
| 136 | + } | ||
| 137 | +} | ||
| 138 | + |
-
Please register or login to post a comment