moment_item.tsx 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { View, Image, Button } from "@tarojs/components";
  2. import './moment_item.scss'
  3. import { MainColorType } from "@/context/themes/color";
  4. import TimeTitleDesc from "@/_health/components/time_title_desc";
  5. import dayjs from 'dayjs';
  6. import relativeTime from 'dayjs/plugin/relativeTime';
  7. import isToday from 'dayjs/plugin/isToday';
  8. import isTomorrow from 'dayjs/plugin/isTomorrow'
  9. import isYesterday from 'dayjs/plugin/isYesterday'
  10. import TargetProgress from "@/_health/components/target_progress";
  11. import { rpxToPx } from "@/utils/tools";
  12. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  13. import CoverList from "@/_health/components/cover_list";
  14. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  15. import { IconActive } from "@/components/basic/Icons";
  16. dayjs.extend(relativeTime);
  17. dayjs.extend(isToday);
  18. dayjs.extend(isTomorrow);
  19. dayjs.extend(isYesterday);
  20. export default function MomentItem(props: { data: any }) {
  21. const { link, moment, user } = props.data
  22. const formatTime = (timestamp) => {
  23. const now = dayjs();
  24. const time = dayjs(timestamp);
  25. if (time.isToday()) {
  26. return time.format('HH:mm'); // 今天的时间
  27. }
  28. const diffInMinutes = now.diff(time, 'minute');
  29. if (diffInMinutes < 60) {
  30. return `${diffInMinutes} min ago`; // xx分钟之前
  31. } else {
  32. return time.format('YYYY-MM-DD'); // 显示完整日期
  33. }
  34. };
  35. const formatImages = (list) => {
  36. return list.map(obj => obj.url);
  37. }
  38. function goProfile() {
  39. jumpPage(`/_moment/pages/home?uid=${user.id}`)
  40. }
  41. function goDetail() {
  42. jumpPage(`/_health/pages/timeline_detail?disable_edit=1&window_id=${link.window_id}`)
  43. }
  44. return <View className="moment_item">
  45. <Image className="moment_avatar" src={user.avatar} mode="aspectFill" onClick={goProfile} />
  46. <View className="moment_detail" onClick={goDetail}>
  47. <View className="h34 bold" style={{ color: MainColorType.link, marginBottom: rpxToPx(6) }}>{user.nickname}</View>
  48. {
  49. (moment.title || moment.description) && <TimeTitleDesc time="" title={moment.title} desc={moment.description} />
  50. }
  51. <View style={{ height: rpxToPx(12) }} />
  52. {
  53. moment.media.length > 0 && <CoverList imgs={formatImages(moment.media)} count={moment.media.length} />
  54. }
  55. {
  56. link && link.ring && <View style={{ marginTop: rpxToPx(24) }}>
  57. <TargetProgress
  58. color={getThemeColor(link.window)}
  59. showRing={true}
  60. desc={link.ring.description}
  61. og={link.status == 'OG'}
  62. startTimestamp={link.ring.start_timestamp}
  63. endTimerstamp={link.ring.end_timestamp ?? new Date().getTime()}
  64. />
  65. </View>
  66. }
  67. {
  68. link && link.move && <View style={{ marginTop: rpxToPx(24) }}>
  69. <TargetProgress
  70. color={getThemeColor(link.window)}
  71. showRing={false}
  72. desc={link.move.description}
  73. icon={
  74. <IconActive color={MainColorType.active} width={rpxToPx(32)} />
  75. }
  76. />
  77. </View>
  78. }
  79. <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', marginTop: rpxToPx(24) }}>
  80. <View className="h26 g02">{formatTime(moment.timestamp)}</View>
  81. <View style={{ position: 'relative' }}>
  82. <Button className="item_share" openType="share" onClick={() => { global.shareData = '9527'; console.log('sgareeeeeee') }}></Button>
  83. </View>
  84. </View>
  85. </View>
  86. </View>
  87. }