Journal.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import JournalCover from "@/features/journal/components/journal_cover";
  2. import { getJournals } from "@/services/health";
  3. import { View, Text, Image } from "@tarojs/components";
  4. import { useEffect, useState } from "react";
  5. import './Journal.scss'
  6. import dayjs from "dayjs";
  7. import { rpxToPx } from "@/utils/tools";
  8. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  9. import NewHeader, { NewHeaderType } from "@/_health/components/new_header";
  10. export default function Journal() {
  11. const [journals, setJournals] = useState<any>([])
  12. useEffect(() => {
  13. getJounalsData()
  14. }, [])
  15. function getJounalsData() {
  16. getJournals({
  17. page: 1,
  18. limit: 50
  19. }).then(res => {
  20. let list = (res as any).data
  21. list.forEach(element => {
  22. let array: any = []
  23. element.windows.map(item => {
  24. item.events.map(event => {
  25. event.moments && event.moments.map(moment => {
  26. if (moment.media && moment.media.length > 0) {
  27. moment.media.map(media => {
  28. array.push(media.url)
  29. })
  30. }
  31. })
  32. })
  33. })
  34. element.imgs = array
  35. });
  36. setJournals((res as any).data)
  37. })
  38. }
  39. function getTitle(item) {
  40. if (item.title) {
  41. return item.title;
  42. }
  43. if (item.moment) {
  44. return item.moment.title
  45. }
  46. return ''
  47. }
  48. return <View style={{ display: 'flex', flexDirection: 'column' }}>
  49. <NewHeader type={NewHeaderType.left} title="Journal" />
  50. {
  51. journals.map((item, index) => {
  52. return <View className="album_item" key={index} onClick={() => {
  53. jumpPage('/pages/account/JournalDetail?detail=' + JSON.stringify(item))
  54. }}>
  55. <Text className="album_date">{(item.date + '').substring(6, 9)}</Text>
  56. {
  57. item.imgs.length > 0 && <JournalCover imgs={item.imgs} />
  58. }
  59. <View style={{
  60. display: 'flex',
  61. flexDirection: 'column',
  62. flex: 1,
  63. backgroundColor: item.imgs.length == 0 ? '#f5f5f5' : 'transparent',
  64. padding: item.imgs.length == 0 ? rpxToPx(20) : 0,
  65. marginRight: rpxToPx(40)
  66. }}>
  67. {
  68. item.windows.map((window, i) => {
  69. return <View key={i * 400} style={{ display: 'flex', flexDirection: 'column' }}>{
  70. window.events.map((item2, index2) => {
  71. return <Text key={index2 * 1000}>
  72. <Text className="history_item_title" style={{color:'#000'}}>{dayjs(item2.time.timestamp).format('HH:mm')} {getTitle(item2)} </Text>
  73. {
  74. item2.moment && item2.moment.description && <Text className="history_item_desc">{item2.moment.description}</Text>
  75. }
  76. </Text>
  77. })
  78. }</View>
  79. })
  80. }
  81. </View>
  82. <View className="border_footer_line" />
  83. </View>
  84. })
  85. }
  86. </View>
  87. }