Showing
1 changed file
with
41 additions
and
11 deletions
| @@ -3,12 +3,40 @@ | @@ -3,12 +3,40 @@ | ||
| 3 | */ | 3 | */ |
| 4 | import { RmhInfoDTO } from 'wdBean' | 4 | import { RmhInfoDTO } from 'wdBean' |
| 5 | import { CommonConstants } from 'wdConstant/Index'; | 5 | import { CommonConstants } from 'wdConstant/Index'; |
| 6 | -import { DateTimeUtils } from 'wdKit'; | 6 | +import { DateTimeUtils, SPHelper } from 'wdKit'; |
| 7 | +import { SpConstants } from 'wdConstant/Index' | ||
| 8 | +import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; | ||
| 9 | +import router from '@ohos.router' | ||
| 7 | 10 | ||
| 8 | @Component | 11 | @Component |
| 9 | export struct RmhTitle { | 12 | export struct RmhTitle { |
| 10 | @Prop rmhInfo: RmhInfoDTO | 13 | @Prop rmhInfo: RmhInfoDTO |
| 11 | @Prop publishTime: string | undefined | 14 | @Prop publishTime: string | undefined |
| 15 | + @Prop hideTime: boolean | ||
| 16 | + | ||
| 17 | + async appointReq() { | ||
| 18 | + // 未登录,跳转登录 | ||
| 19 | + const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') | ||
| 20 | + if (!user_id) { | ||
| 21 | + WDRouterRule.jumpWithPage(WDRouterPage.loginPage) | ||
| 22 | + return | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + aboutToAppear(): void { | ||
| 27 | + let page = router.getState(); | ||
| 28 | + if (page.path.includes('/page/PeopleShipHomePage')) { | ||
| 29 | + this.hideTime = true; | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + getDaysBetweenDates(date: number) { | ||
| 34 | + const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数 | ||
| 35 | + const time1 = new Date().getTime(); // 今天日期的时间戳 | ||
| 36 | + const time2 = new Date(date).getTime(); // 要比较日期的时间戳 | ||
| 37 | + const diffDays = Math.round(Math.abs((time1 - time2) / oneDay)); // 两个日期时间戳差值除以一天的毫秒数得到天数,取绝对值并四舍五入 | ||
| 38 | + return Math.ceil(diffDays); | ||
| 39 | + } | ||
| 12 | 40 | ||
| 13 | build() { | 41 | build() { |
| 14 | Flex() { | 42 | Flex() { |
| @@ -33,15 +61,17 @@ export struct RmhTitle { | @@ -33,15 +61,17 @@ export struct RmhTitle { | ||
| 33 | .alignSelf(ItemAlign.Start) | 61 | .alignSelf(ItemAlign.Start) |
| 34 | Flex({alignContent: FlexAlign.Start, wrap: FlexWrap.NoWrap}) { | 62 | Flex({alignContent: FlexAlign.Start, wrap: FlexWrap.NoWrap}) { |
| 35 | Row() { | 63 | Row() { |
| 36 | - if (this.publishTime) { | ||
| 37 | - Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.publishTime))) | ||
| 38 | - .fontSize($r("app.float.font_size_12")) | ||
| 39 | - .fontColor($r("app.color.color_B0B0B0")) | ||
| 40 | - } | ||
| 41 | - if (this.publishTime && this.rmhInfo.rmhDesc) { | ||
| 42 | - Image($r('app.media.point')) | ||
| 43 | - .width(16) | ||
| 44 | - .height(16) | 64 | + if (!(this.hideTime && this.getDaysBetweenDates(Number(this.publishTime)) > 2)) { |
| 65 | + if (this.publishTime) { | ||
| 66 | + Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.publishTime))) | ||
| 67 | + .fontSize($r("app.float.font_size_12")) | ||
| 68 | + .fontColor($r("app.color.color_B0B0B0")) | ||
| 69 | + } | ||
| 70 | + if (this.publishTime && this.rmhInfo.rmhDesc) { | ||
| 71 | + Image($r('app.media.point')) | ||
| 72 | + .width(16) | ||
| 73 | + .height(16) | ||
| 74 | + } | ||
| 45 | } | 75 | } |
| 46 | Text(this.rmhInfo.rmhDesc) | 76 | Text(this.rmhInfo.rmhDesc) |
| 47 | .fontSize($r("app.float.font_size_12")) | 77 | .fontSize($r("app.float.font_size_12")) |
| @@ -68,7 +98,7 @@ export struct RmhTitle { | @@ -68,7 +98,7 @@ export struct RmhTitle { | ||
| 68 | .flexShrink(0) | 98 | .flexShrink(0) |
| 69 | .alignSelf(ItemAlign.Center) | 99 | .alignSelf(ItemAlign.Center) |
| 70 | .onClick(() => { | 100 | .onClick(() => { |
| 71 | - // TODO 调用关注接口 | 101 | + this.appointReq(); |
| 72 | }) | 102 | }) |
| 73 | } | 103 | } |
| 74 | } | 104 | } |
-
Please register or login to post a comment