JournalDetail.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { View, Image, Text } from "@tarojs/components";
  2. import { useRouter } from "@tarojs/taro";
  3. import { useEffect, useState } from "react";
  4. import { useSelector } from "react-redux";
  5. import './JournalDetail.scss'
  6. import Taro from "@tarojs/taro";
  7. import dayjs from "dayjs";
  8. import { rpxToPx } from "@/utils/tools";
  9. import { MainColorType } from "@/context/themes/color";
  10. import TimeTitleDesc from "@/_health/components/time_title_desc";
  11. import CoverList from "@/_health/components/cover_list";
  12. import ListFooter from "@/_health/components/list_footer";
  13. let useRoute;
  14. let useNavigation;
  15. let scenario = '';
  16. if (process.env.TARO_ENV == 'rn') {
  17. useRoute = require("@react-navigation/native").useRoute
  18. useNavigation = require("@react-navigation/native").useNavigation
  19. }
  20. export default function JournalDetail() {
  21. const health = useSelector((state: any) => state.health);
  22. const user = useSelector((state: any) => state.user);
  23. const [imgs, setImgs] = useState<any>([])
  24. const [events, setEvents] = useState<any>([])
  25. let router
  26. let navigation;
  27. if (useNavigation) {
  28. navigation = useNavigation()
  29. }
  30. if (process.env.TARO_ENV == 'rn') {
  31. router = useRoute()
  32. }
  33. else {
  34. router = useRouter()
  35. }
  36. const [data, setData] = useState<any>(JSON.parse(router.params.detail))
  37. // const [detail, setDetail] = useState(JSON.parse(router.params.detail))
  38. useEffect(() => {
  39. let obj = JSON.parse(router.params.detail)
  40. console.log(obj)
  41. var array: any = []
  42. obj.windows.map(item => {
  43. item.events.map(tem => {
  44. array.push(tem)
  45. })
  46. })
  47. const sortedArray = array.sort((a, b) => {
  48. return a.time.timestamp - b.time.timestamp;
  49. });
  50. // 返回一个新数组
  51. const newArray = [...sortedArray];
  52. setImgs(obj.imgs)
  53. setEvents(newArray)
  54. }, [])
  55. function preview(url) {
  56. Taro.previewImage({
  57. current: url,
  58. urls: imgs
  59. })
  60. }
  61. function eventList(detail, index) {
  62. const list = detail.moments
  63. return <View key={index}>
  64. {
  65. (detail.scenario != 'MEAL' && detail.scenario != 'ACTIVITY') && <View style={{ flexDirection: 'column', display: 'flex', marginBottom: rpxToPx(48) }}>
  66. <TimeTitleDesc
  67. timeObj={detail.time}
  68. time={dayjs(detail.time.timestamp).format('HH:mm')}
  69. title={detail.title}
  70. // desc={item.description}
  71. />
  72. </View>
  73. }
  74. {
  75. detail.scenario == 'ACTIVITY' && !list && <View style={{ flexDirection: 'column', display: 'flex', marginBottom: rpxToPx(48) }}>
  76. <TimeTitleDesc
  77. timeObj={detail.time}
  78. time={dayjs(detail.time.timestamp).format('HH:mm')}
  79. title={detail.title}
  80. // desc={item.description}
  81. />
  82. {/* {
  83. item.media && item.media.length > 0 && <Image mode="aspectFill" src={item.media[0].url} style={{ width: 60, height: 60, marginTop: 5 }} />
  84. } */}
  85. </View>
  86. }
  87. {
  88. list && list.map((item, index) => {
  89. return <View key={index} style={{ flexDirection: 'column', display: 'flex', marginBottom: rpxToPx(48) }}>
  90. <TimeTitleDesc
  91. timeObj={detail.time}
  92. time={dayjs(detail.time.timestamp).format('HH:mm')}
  93. title={detail.title}
  94. desc={item.description}
  95. />
  96. {/* {
  97. item.media && item.media.length > 0 && <Image mode="aspectFill" src={item.media[0].url} style={{ width: 60, height: 60, marginTop: 5 }} />
  98. } */}
  99. </View>
  100. })
  101. }
  102. </View>
  103. }
  104. return <View>
  105. <View className="journal_detail">
  106. <Image className="header_avatar" src={user.avatar} mode="aspectFill" />
  107. <View className="jounal_content">
  108. <Text className="journal_nickname">{user.nickname}</Text>
  109. <View style={{ flexDirection: 'column', display: 'flex', marginTop: rpxToPx(16) }}>
  110. {
  111. events.map((item, index) => {
  112. return eventList(item, index)
  113. // if (item.scenario != 'MEAL' && item.scenario != 'ACTIVITY') {
  114. // return <View key={index} style={{ marginBottom: index < events.length - 1 ? rpxToPx(48) : 0, display: 'flex', flexDirection: 'column' }}>
  115. // <Text style={{ color: '#5C7099' }}>{dayjs(item.time.timestamp).format('HH:mm')}
  116. // {
  117. // item.title && <Text> {item.title}</Text>
  118. // }
  119. // </Text>
  120. // </View>
  121. // }
  122. // if (item.scenario == 'ACTIVITY') {
  123. // return <View key={index} style={{ marginBottom: index < events.length - 1 ? rpxToPx(48) : 0, display: 'flex', flexDirection: 'column' }}>
  124. // <Text style={{ color: '#5C7099' }}>{dayjs(item.time.timestamp).format('HH:mm')}
  125. // {
  126. // item.title && <Text> {item.title}</Text>
  127. // }
  128. // </Text>
  129. // </View>
  130. // }
  131. // return <View key={index} style={{ marginBottom: index < events.length - 1 ? rpxToPx(48) : 0, display: 'flex', flexDirection: 'column' }}>
  132. // <Text >
  133. // {
  134. // item.time && <Text style={{ color: '#5C7099' }}>{dayjs(item.time.timestamp).format('HH:mm')} </Text>
  135. // }
  136. // {
  137. // item.title && <Text> {item.title} </Text>
  138. // }
  139. // {
  140. // item.moments && item.moment.description && <Text> {item.moment.description} </Text>
  141. // }
  142. // </Text>
  143. // </View>
  144. })
  145. }
  146. </View>
  147. <View className="img_container" style={{ marginTop: -rpxToPx(24) }}>
  148. <CoverList
  149. imgs={imgs}
  150. count={imgs.length}
  151. />
  152. {/* {
  153. imgs.map((item, index) => {
  154. return <Image key={index} src={item} className="journal_img" mode="aspectFill" onClick={() => {
  155. preview(item)
  156. }} />
  157. })
  158. } */}
  159. </View>
  160. <Text className="h24" style={{ color: MainColorType.g02 }}>发布于{dayjs(data.publish_timestamp).format('MM-DD HH:mm')}</Text>
  161. </View>
  162. </View>
  163. <ListFooter />
  164. </View>
  165. }