HistoryItem.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import formatMilliseconds from "@/utils/format_time";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import './History.scss'
  4. import Taro from "@tarojs/taro";
  5. import dayjs from "dayjs";
  6. import { useSelector } from "react-redux";
  7. import { getThemeColor } from "./hooks/health_hooks";
  8. import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
  9. import { MainColorType } from "@/context/themes/color";
  10. import { durationArc, startArc } from "./util";
  11. export default function HistoryItem(props: { data: any, index: number }) {
  12. const health = useSelector((state: any) => state.health);
  13. function preview(obj) {
  14. var list:any = []
  15. props.data.events.map((item) => {
  16. item.moment.media.map((media) => {
  17. list.push(media.url)
  18. })
  19. })
  20. Taro.previewImage({
  21. current: obj.url,
  22. urls: list
  23. })
  24. }
  25. function getTitle(item) {
  26. if (item.moment) {
  27. return item.moment.title
  28. }
  29. if (health.mode == 'FAST') {
  30. return '开始断食'
  31. }
  32. else if (health.mode == 'SLEEP') {
  33. return '开始睡眠'
  34. }
  35. return ''
  36. }
  37. function ring() {
  38. const common: RingCommon = {
  39. useCase: 'ChooseScenario',
  40. radius: 17,
  41. lineWidth: 3,
  42. isFast: true,
  43. status: 'WAIT_FOR_START'
  44. }
  45. const bgRing: BgRing = {
  46. color: MainColorType.ringBg
  47. }
  48. const realRing = {
  49. hideBg:true,
  50. color:getThemeColor(health.mode),
  51. startArc:startArc(props.data.window_range.start_timestamp),
  52. durationArc:durationArc(props.data.window_range.start_timestamp,props.data.window_range.end_timestamp)
  53. }
  54. return <Rings common={common} bgRing={bgRing} realRing={realRing} canvasId={'history_' + props.index} />
  55. }
  56. function mediaCount(){
  57. let count = 0;
  58. props.data.events.map((item) => {
  59. if (item.moment){
  60. item.moment.media.map((obj, j) => {
  61. count++;
  62. })
  63. }
  64. })
  65. return count;
  66. }
  67. return <View className="history_item">
  68. <View className="history_ring">
  69. {
  70. ring()
  71. }
  72. <View className="history_date">{dayjs(props.data.window_range.start_timestamp).format('D')}</View>
  73. </View>
  74. <View className="history_content">
  75. {
  76. props.data.window_range.end_timestamp && <Text className="history_item_duration" style={{ color: getThemeColor(health.mode) }}>{formatMilliseconds(props.data.window_range.end_timestamp - props.data.window_range.start_timestamp)}</Text>
  77. }
  78. <Text>
  79. {
  80. props.data.events.map((item, index) => {
  81. return <Text key={index}>
  82. <Text className="history_item_title">{dayjs(item.real.start_timestamp).format('HH:mm')} {getTitle(item)} </Text>
  83. {
  84. item.moment && item.moment.description && <Text className="history_item_desc">{item.moment.description}</Text>
  85. }
  86. </Text>
  87. })
  88. }
  89. </Text>
  90. <View className="media" style={{ marginTop: mediaCount()>0?9:-10 }}>
  91. {
  92. props.data.events.map((item) => {
  93. if (item.moment){
  94. return item.moment.media.map((obj, j) => {
  95. return <Image className="media_item" mode="aspectFill" onClick={() => preview(obj)} src={obj.url} key={j * 10} />
  96. })
  97. }
  98. })
  99. }
  100. </View>
  101. </View>
  102. <View className="border_footer_line" />
  103. </View>
  104. }