move_detail.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { getActiveMoveDetail } from "@/services/health";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import { useRouter } from "@tarojs/taro";
  4. import { useEffect, useState } from "react";
  5. import './move.scss'
  6. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  7. import { rpxToPx } from "@/utils/tools";
  8. import dayjs from "dayjs";
  9. import NewHeader, { NewHeaderType } from "../components/new_header";
  10. import NewButton, { NewButtonType } from "../base/new_button";
  11. import { MainColorType } from "@/context/themes/color";
  12. import ListFooter from "../components/list_footer";
  13. import { IconSit, IconWalk } from "@/components/basic/Icons";
  14. let useRoute;
  15. let useNavigation;
  16. let scenario = '';
  17. if (process.env.TARO_ENV == 'rn') {
  18. useRoute = require("@react-navigation/native").useRoute
  19. useNavigation = require("@react-navigation/native").useNavigation
  20. }
  21. export default function MoveDetail() {
  22. let router
  23. let navigation;
  24. if (useNavigation) {
  25. navigation = useNavigation()
  26. }
  27. if (process.env.TARO_ENV == 'rn') {
  28. router = useRoute()
  29. }
  30. else {
  31. router = useRouter()
  32. }
  33. const [loaded, setLoaded] = useState(false)
  34. const [data, setData] = useState<any>(null)
  35. const [moreActive, setMoreActive] = useState(false)
  36. useEffect(() => {
  37. getActiveMoveDetail(router.params.id).then(res => {
  38. setLoaded(true)
  39. setData(res)
  40. })
  41. }, [])
  42. function summary() {
  43. return <View className="move_summary">
  44. <View className="summary_header">
  45. <Text className="h34 bold">Summary</Text>
  46. <View style={{ flex: 1 }} />
  47. {
  48. data.last_updated && <Text style={{ color: '#b2b2b2', fontSize: 10, fontWeight: 'normal' }}>最近更新于 {dayjs(data.last_updated).format('HH:mm')}</Text>
  49. }
  50. <View className="border_footer_line" />
  51. </View>
  52. <View className="summary_content">
  53. <View className="summary_footer">
  54. <View className="summary_footer_item">
  55. <Text className="light_desc">Hours Sedentary</Text>
  56. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(24) }}><Text style={{ fontSize: rpxToPx(34) }}>{data.stat.sedentary_hours}</Text> / {data.stat.waking_hours}</Text>
  57. </View>
  58. <View className="summary_footer_item">
  59. <Text className="light_desc">Hours Active</Text>
  60. <Text style={{ color: getThemeColor('ACTIVE'), fontWeight: 'bold', fontSize: rpxToPx(24) }}><Text style={{ fontSize: rpxToPx(34) }}>{data.stat.active_hours}</Text> / {data.stat.waking_hours}</Text>
  61. </View>
  62. <View className="summary_footer_item">
  63. <Text className="light_desc">Hours Missed</Text>
  64. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(24) }}><Text style={{ fontSize: rpxToPx(34) }}>{data.stat.missed_hours}</Text> / {data.stat.waking_hours}</Text>
  65. </View>
  66. </View>
  67. <View className="summary_footer" style={{ marginTop: rpxToPx(48) }}>
  68. <View className="summary_footer_item">
  69. <Text className="light_desc">Total Steps</Text>
  70. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(24) }}><Text style={{ fontSize: rpxToPx(34) }}>{data.stat.real_steps}</Text> / {data.stat.target_steps}</Text>
  71. </View>
  72. <View className="summary_footer_item">
  73. <Text className="light_desc">Total Calories</Text>
  74. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(24) }}><Text style={{ fontSize: rpxToPx(34) }}>{data.stat.real_calories}</Text> / {data.stat.target_calories}</Text>
  75. </View>
  76. <View className="summary_footer_item">
  77. <Text className="light_desc">Total Distance</Text>
  78. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(24) }}><Text style={{ fontSize: rpxToPx(34) }}>{data.stat.real_distance}</Text> / {data.stat.target_distance}</Text>
  79. </View>
  80. </View>
  81. </View>
  82. </View>
  83. }
  84. function activeHour() {
  85. const hours = data.hours
  86. return <View className="summary">
  87. <View className="summary_header">
  88. <Text className="h34 bold">Hourly</Text>
  89. <View className="border_footer_line" />
  90. </View>
  91. <View className="summary_content2">
  92. {
  93. hours.map((item, index) => {
  94. return <View key={index}>
  95. {
  96. currentHistory(item)
  97. }
  98. </View>
  99. })
  100. }
  101. </View>
  102. </View>
  103. }
  104. function currentHistory(item) {
  105. var start = item.hour
  106. var isYesterday = start > new Date().getHours()
  107. var end = start + 1
  108. start = (start + '').padStart(2, '0')
  109. end = (end + '').padStart(2, '0')
  110. return <View className="current_history_item">
  111. <View style={{ display: 'flex', flexDirection: 'column' }}>
  112. <Text className="h24" style={{ color: MainColorType.g02, lineHeight: rpxToPx(36) + 'px' }}>{start}:00-{end}:00</Text>
  113. {
  114. item.is_extra && <Text style={{ color: getThemeColor('SLEEP') }}>is Extra</Text>
  115. }
  116. <Text className="h24 bold"><Text className="h34 bold">{item.real_steps}</Text> / {item.target_steps} steps</Text>
  117. <View style={{
  118. height: rpxToPx(18), flexShrink: 0,
  119. }} />
  120. </View>
  121. {
  122. item.status == 'MISSED' && <Text className="missed">Missed</Text>
  123. }
  124. {
  125. item.status == 'SEDENTARY' && <IconSit width={rpxToPx(44)} color={MainColorType.g02}/>
  126. }
  127. {
  128. item.status == 'ACTIVE' && <IconWalk width={rpxToPx(44)} color={MainColorType.active}/>
  129. }
  130. <View className="border_footer_line" />
  131. </View>
  132. }
  133. if (!loaded) return <View />
  134. const date = data.start_date + ''
  135. return <View>
  136. <NewHeader type={NewHeaderType.left} title={date.substring(0, 4) + '年' + date.substring(4, 6) + '月' + date.substring(6, 8) + '日'} />
  137. {
  138. summary()
  139. }
  140. {
  141. activeHour()
  142. }
  143. <ListFooter noMore={true} />
  144. </View>
  145. }