recent_item.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import TargetProgress from "@/_health/components/target_progress";
  2. import TimeTitleDesc from "@/_health/components/time_title_desc";
  3. import TimelineDate from "@/_health/components/timeline_date";
  4. import { IconActive } from "@/components/basic/Icons";
  5. import { MainColorType } from "@/context/themes/color";
  6. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  7. import JournalCover from "@/features/journal/components/journal_cover";
  8. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  9. import { rpxToPx } from "@/utils/tools";
  10. import { View, Text, Image, ScrollView } from "@tarojs/components";
  11. import dayjs from "dayjs";
  12. import './recent_item.scss'
  13. export default function RecentItem(props: { data: any, index: number }) {
  14. const { time, moment, link } = props.data
  15. function historyMonth(index) {
  16. var showDate = time.is_start_year ? true : false;
  17. var dateStr = global.language == 'en' ? dayjs(time.timestamp).format('YYYY') : dayjs(time.timestamp).format('YYYY年')
  18. if (index == 0) {
  19. var now = global.language == 'en' ? dayjs().format('YYYY') : dayjs().format('YYYY年')
  20. if (dateStr == now) {
  21. showDate = false
  22. }
  23. }
  24. if (showDate) {
  25. return <View className="history_year_month h42 bold" style={{ marginBottom: index==0?rpxToPx(60):0 }}>{dateStr}</View>
  26. }
  27. return <View />
  28. }
  29. function medias() {
  30. var pics = moment.media.map(obj => obj.url);
  31. return <JournalCover imgs={pics} />
  32. }
  33. function goDetail() {
  34. if (link.scenario == 'MOVE') {
  35. jumpPage('/_health/pages/move_detail?id=' + link.move.id)
  36. return;
  37. }
  38. jumpPage(`/_health/pages/timeline_detail?source=home&window_id=${link.window_id}&event_id=${link.event_id}`)
  39. }
  40. const hasImg = moment && moment.media.length > 0
  41. var hasText = moment && (moment.title || moment.description)
  42. if (hasText == undefined) {
  43. hasText = false
  44. }
  45. const spaceY = rpxToPx(12)
  46. return <View>
  47. {
  48. historyMonth(props.index)
  49. }
  50. <View className="recent_item1" style={{ paddingTop: time.is_start_day ? rpxToPx(60) : spaceY }} onClick={goDetail}>
  51. <TimelineDate timestamp={time.timestamp} pre_timestamp={0} isJournal={false} hideDate={!time.is_start_day} />
  52. <View className="history_content" style={{ paddingTop: rpxToPx(0) }}>
  53. <View style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(0), flex: 1 }}>
  54. {
  55. hasImg && medias()
  56. }
  57. {
  58. hasText && <View style={{
  59. display: 'flex',
  60. flex: 1,
  61. flexShrink: 0,
  62. flexDirection: 'column',
  63. backgroundColor: moment.media.length > 0 ? 'transparent' : '#fafafa',
  64. paddingLeft: moment.media.length > 0 ? 0 : rpxToPx(20),
  65. paddingRight: rpxToPx(20),
  66. paddingTop: hasImg ? rpxToPx(12) : rpxToPx(12),
  67. paddingBottom: rpxToPx(12)
  68. }}>
  69. <TimeTitleDesc
  70. className={'line2'}
  71. time=''
  72. title={moment.title}
  73. desc={moment.description} />
  74. </View>
  75. }
  76. </View>
  77. {
  78. link && link.ring && <View style={{ marginTop: (hasImg || hasText) ? spaceY : 0 }}>
  79. <TargetProgress
  80. color={getThemeColor(link.window)}
  81. showRing={true}
  82. desc={link.ring.description}
  83. time_desc={link.ring.time_desc}
  84. og={link.status == 'OG'}
  85. startTimestamp={link.ring.start_timestamp}
  86. endTimerstamp={link.ring.end_timestamp ?? new Date().getTime()}
  87. />
  88. </View>
  89. }
  90. {
  91. link && link.move && <View style={{ marginTop: (hasImg || hasText) ? spaceY : 0 }}>
  92. <TargetProgress
  93. color={getThemeColor(link.window)}
  94. showRing={false}
  95. desc={link.move.description}
  96. icon={
  97. <IconActive color={MainColorType.active} width={rpxToPx(32)} />
  98. }
  99. />
  100. </View>
  101. }
  102. </View>
  103. </View>
  104. </View>
  105. }