Showing
1 changed file
with
43 additions
and
4 deletions
| 1 | import { CompDTO, ContentDTO } from 'wdBean' | 1 | import { CompDTO, ContentDTO } from 'wdBean' |
| 2 | import { CommonConstants } from 'wdConstant/Index'; | 2 | import { CommonConstants } from 'wdConstant/Index'; |
| 3 | import { DateTimeUtils } from 'wdKit/Index'; | 3 | import { DateTimeUtils } from 'wdKit/Index'; |
| 4 | +import { JSON } from '@kit.ArkTS'; | ||
| 5 | +import router from '@ohos.router' | ||
| 4 | 6 | ||
| 5 | @Component | 7 | @Component |
| 6 | export struct CardSourceInfo { | 8 | export struct CardSourceInfo { |
| 7 | @State contentDTO: ContentDTO = new ContentDTO(); | 9 | @State contentDTO: ContentDTO = new ContentDTO(); |
| 8 | @ObjectLink compDTO: CompDTO | 10 | @ObjectLink compDTO: CompDTO |
| 9 | 11 | ||
| 12 | + handleTimeStr() { | ||
| 13 | + return DateTimeUtils.getCommentTime( | ||
| 14 | + this.contentDTO.publishTime.includes(' ') | ||
| 15 | + ? Number.parseFloat(new Date(this.contentDTO.publishTime).getTime().toString()) | ||
| 16 | + : Number.parseFloat(this.contentDTO.publishTime) | ||
| 17 | + ) | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + showTime() { | ||
| 21 | + console.log('curRouter', this.contentDTO.publishTime) | ||
| 22 | + const curRouter = router.getState().name; | ||
| 23 | + const publishTime = this.contentDTO.publishTime.includes(' ') | ||
| 24 | + ? new Date(this.contentDTO.publishTime).getTime().toString() | ||
| 25 | + : this.contentDTO.publishTime | ||
| 26 | + let flag: boolean = false; | ||
| 27 | + if (curRouter === 'MainPage') { | ||
| 28 | + if (this.isTwoDaysAgo(publishTime)) { | ||
| 29 | + console.log('curRouter 01') | ||
| 30 | + flag = false | ||
| 31 | + } else { | ||
| 32 | + console.log('curRouter 02') | ||
| 33 | + flag = true; | ||
| 34 | + } | ||
| 35 | + } else { | ||
| 36 | + console.log('curRouter 03') | ||
| 37 | + flag = true; | ||
| 38 | + } | ||
| 39 | + return flag; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + isTwoDaysAgo(date: string) { | ||
| 43 | + const twoDaysAgo = new Date(); | ||
| 44 | + twoDaysAgo.setDate(twoDaysAgo.getDate() - 2); | ||
| 45 | + console.log('curRouter', date) | ||
| 46 | + return parseInt(date) < twoDaysAgo.getTime() | ||
| 47 | + } | ||
| 48 | + | ||
| 10 | build() { | 49 | build() { |
| 11 | Flex({ alignItems: ItemAlign.Center }) { | 50 | Flex({ alignItems: ItemAlign.Center }) { |
| 12 | if (this.contentDTO.corner) { | 51 | if (this.contentDTO.corner) { |
| @@ -52,11 +91,12 @@ export struct CardSourceInfo { | @@ -52,11 +91,12 @@ export struct CardSourceInfo { | ||
| 52 | // .fontColor($r("app.color.color_B0B0B0")) | 91 | // .fontColor($r("app.color.color_B0B0B0")) |
| 53 | // .flexShrink(0); | 92 | // .flexShrink(0); |
| 54 | // } | 93 | // } |
| 55 | - if (this.contentDTO.source) { | ||
| 56 | - Text(DateTimeUtils.getCommentTime(Number.parseFloat(new Date(this.contentDTO.publishTime).getTime().toString()))) | 94 | + if (this.contentDTO.source && this.showTime()) { |
| 95 | + Text(this.handleTimeStr()) | ||
| 57 | .fontSize($r("app.float.font_size_11")) | 96 | .fontSize($r("app.float.font_size_11")) |
| 58 | .fontColor($r("app.color.color_B0B0B0")) | 97 | .fontColor($r("app.color.color_B0B0B0")) |
| 59 | - .flexShrink(0); | 98 | + .flexShrink(0) |
| 99 | + .margin({right: 4}) | ||
| 60 | } | 100 | } |
| 61 | 101 | ||
| 62 | if (this.getContentDtoBean()?.interactData?.commentNum && this.contentDTO.source) { | 102 | if (this.getContentDtoBean()?.interactData?.commentNum && this.contentDTO.source) { |
| @@ -64,7 +104,6 @@ export struct CardSourceInfo { | @@ -64,7 +104,6 @@ export struct CardSourceInfo { | ||
| 64 | .fontSize($r("app.float.font_size_11")) | 104 | .fontSize($r("app.float.font_size_11")) |
| 65 | .fontColor($r("app.color.color_B0B0B0")) | 105 | .fontColor($r("app.color.color_B0B0B0")) |
| 66 | .flexShrink(0) | 106 | .flexShrink(0) |
| 67 | - .margin({ left: 6 }) | ||
| 68 | .visibility(Number(this.getContentDtoBean()?.interactData?.commentNum) === 0 ? Visibility.None : | 107 | .visibility(Number(this.getContentDtoBean()?.interactData?.commentNum) === 0 ? Visibility.None : |
| 69 | Visibility.Visible) | 108 | Visibility.Visible) |
| 70 | } | 109 | } |
-
Please register or login to post a comment