HistoryItem.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. import { IconLongFast, IconMore } from "@/components/basic/Icons";
  12. import showActionSheet from "@/components/basic/ActionSheet";
  13. import { delRecord, makeDone } from "@/services/health";
  14. import showAlert from "@/components/basic/Alert";
  15. import { rpxToPx } from "@/utils/tools";
  16. import NewButton, { NewButtonType } from "@/_health/base/new_button";
  17. import TimeTitleDesc from "@/_health/components/time_title_desc";
  18. import CoverList from "@/_health/components/cover_list";
  19. import { TimeFormatter } from "@/utils/time_format";
  20. import { jumpPage } from "../trackTimeDuration/hooks/Common";
  21. import TargetProgress from "@/_health/components/target_progress";
  22. import Cell from "@/_health/base/cell";
  23. import { setFirstActiveId, setFirstEatId } from "@/store/health";
  24. import JournalCover from "../journal/components/journal_cover";
  25. import TimelineDate from "@/_health/components/timeline_date";
  26. import { useEffect } from "react";
  27. export default function HistoryItem(props: {
  28. data: any,
  29. preData: any,
  30. index: number,
  31. onClick: Function,
  32. isArchived?: boolean,
  33. refresh?: Function,
  34. mode: string,
  35. fast_type?: string,
  36. hideLine?: boolean,
  37. type?: string
  38. }) {
  39. const health = useSelector((state: any) => state.health);
  40. const scale = '?x-oss-process=image/format,webp/resize,w_400'
  41. useEffect(()=>{
  42. return ()=>{
  43. console.log('dealloc history item')
  44. }
  45. },[])
  46. function goDetail(event_id?: any) {
  47. // debugger
  48. if (props.mode == 'EAT' || props.mode == 'ACTIVE') {
  49. // jumpPage(`/_health/pages/timeline_detail?event_id=${event_id}&fast_type=${props.fast_type}&isfastsleep=0`)
  50. }
  51. else {
  52. jumpPage(`/_health/pages/timeline_detail?disable_edit=1&window_id=${props.data.window_id}&fast_type=${props.fast_type}&type=recent&isfastsleep=${props.mode == 'FAST,SLEEP' ? 1 : 0}`)
  53. }
  54. }
  55. function singleItem(type, url, obj, key,urls=[]) {
  56. return <View
  57. onClick={(e) => {
  58. if (process.env.TARO_ENV == 'weapp') {
  59. e.stopPropagation()
  60. }
  61. if (type == 'PIC') {
  62. var temp: any = null
  63. props.data.events.map(item => {
  64. item.moments && item.moments.map(moment => {
  65. if (moment.media && moment.media.length > 0) {
  66. if (moment.media[0].url == url) {
  67. temp = item
  68. }
  69. }
  70. })
  71. })
  72. if (temp) {
  73. jumpPage(`/_health/pages/timeline_detail?disable_edit=1&event_id=${temp.id}&isfastsleep=0`)
  74. }
  75. }
  76. else {
  77. jumpPage(`/_health/pages/timeline_detail?disable_edit=1&event_id=${obj.event_id}&isfastsleep=0`)
  78. }
  79. }}
  80. style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(12), flex: 1 }} key={key * 1000}>
  81. {
  82. type == 'TEXT' && <View style={{
  83. display: 'flex',
  84. flex: 1,
  85. flexShrink: 0,
  86. flexDirection: 'column',
  87. backgroundColor: '#fafafa',
  88. paddingLeft: rpxToPx(20),
  89. paddingRight: rpxToPx(20),
  90. paddingTop: rpxToPx(12),
  91. paddingBottom: rpxToPx(12)
  92. }}><TimeTitleDesc
  93. className={'line3'}
  94. time=''
  95. title={obj.title}
  96. desc={obj.description}
  97. />
  98. </View>
  99. }
  100. {
  101. type == 'PIC' && <CoverList imgs={[url]} count={1} />
  102. }
  103. {
  104. type == 'PIC_TEXT' && <View onClick={(e) => {
  105. if (process.env.TARO_ENV == 'weapp') {
  106. e.stopPropagation()
  107. }
  108. Taro.previewImage({
  109. current: urls[0],
  110. urls: urls
  111. })
  112. }}>
  113. <JournalCover imgs={urls} />
  114. </View>
  115. // <Image
  116. // className="gray_bg"
  117. // style={{ width: rpxToPx(178), height: rpxToPx(178), marginRight: rpxToPx(7), flexShrink: 0 }}
  118. // src={url+scale}
  119. // onClick={(e) => {
  120. // if (process.env.TARO_ENV == 'weapp') {
  121. // e.stopPropagation()
  122. // }
  123. // Taro.previewImage({
  124. // current: url,
  125. // urls: [url]
  126. // })
  127. // }}
  128. // mode="aspectFill" />
  129. }
  130. {
  131. type == 'PIC_TEXT' && <View style={{
  132. display: 'flex',
  133. flex: 1,
  134. flexShrink: 0,
  135. flexDirection: 'column',
  136. backgroundColor: 'transparent',
  137. // paddingLeft: rpxToPx(17),
  138. paddingRight: 0,
  139. paddingTop: 0,
  140. paddingBottom: 0
  141. }}>
  142. <TimeTitleDesc
  143. className={'line3'}
  144. time=''
  145. title={obj.title}
  146. desc={obj.description}
  147. />
  148. </View>
  149. }
  150. </View>
  151. }
  152. function imgText() {
  153. if (props.data.texts.length == 0 && props.data.pics.length == 0) {
  154. return <View />
  155. }
  156. return <View style={{
  157. display: 'flex', flexDirection: 'row',
  158. // backgroundColor:'pink',
  159. marginBottom: rpxToPx(12),
  160. overflow: 'hidden',
  161. width: rpxToPx(554),
  162. flex: 1
  163. }}>
  164. {
  165. props.data.pics.length > 0 && <JournalCover imgs={props.data.pics} />
  166. }
  167. <View style={{
  168. display: 'flex',
  169. flexDirection: 'column',
  170. flex: 1,
  171. overflow: 'hidden',
  172. backgroundColor: props.data.pics.length == 0 ? '#fafafa' : 'transparent',
  173. paddingLeft: props.data.pics.length == 0 ? rpxToPx(20) : 0,
  174. paddingRight: props.data.pics.length == 0 ? rpxToPx(40) : 0,
  175. paddingTop: props.data.pics.length == 0 ? rpxToPx(12) : 0,
  176. paddingBottom: props.data.pics.length == 0 ? rpxToPx(12) : 0,
  177. // marginRight: rpxToPx(40),
  178. flexShrink: 0
  179. }}>
  180. {
  181. props.data.texts.map((item2, index2) => {
  182. return <TimeTitleDesc
  183. key={index2 * 1000}
  184. className='line1'//{item.pics.length == 0 ? 'line2' : 'line3'}
  185. // style={{ width: props.data.pics.length > 0 ? rpxToPx(310) : rpxToPx(512) }}
  186. time=''
  187. title={item2.title}
  188. desc={item2.description}
  189. />
  190. })
  191. }
  192. </View>
  193. </View>
  194. }
  195. return <View className="history_item2" onClick={goDetail}>
  196. <TimelineDate timestamp={props.data.window_range.start_timestamp}
  197. pre_timestamp={props.preData ? props.preData.window_range.start_timestamp : null}
  198. />
  199. <View className="history_content" style={{ paddingTop: rpxToPx(0) }}>
  200. {
  201. props.mode != 'EAT' && props.mode != 'ACTIVE' && props.data.dataArray.map((content, i) => {
  202. var urlArray:any = []
  203. if (content.type == 'PIC_TEXT'){
  204. urlArray = content.data[0].urls.map(obj => obj.url);
  205. }
  206. return <View style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(12), flex: 1 }} key={i}>
  207. {
  208. content.type == 'TEXT' && <View style={{
  209. display: 'flex',
  210. flex: 1,
  211. flexShrink: 0,
  212. flexDirection: 'column',
  213. backgroundColor: '#fafafa',
  214. paddingLeft: rpxToPx(20),
  215. paddingRight: rpxToPx(20),
  216. paddingTop: rpxToPx(12),
  217. paddingBottom: rpxToPx(12)
  218. }}>{content.data.map((detail, j) => {
  219. return <TimeTitleDesc
  220. key={j * 100}
  221. className={'line2'}
  222. time=''
  223. title={detail.title}
  224. desc={detail.description}
  225. />
  226. })}</View>
  227. }
  228. {
  229. content.type == 'PIC' && <CoverList imgs={content.data} count={content.data.length} />
  230. }
  231. {
  232. content.type == 'PIC_TEXT' && <View style={{marginRight: rpxToPx(7)}} onClick={(e) => {
  233. if (process.env.TARO_ENV == 'weapp') {
  234. e.stopPropagation()
  235. }
  236. Taro.previewImage({
  237. current: urlArray[0],
  238. urls: urlArray
  239. })
  240. }}>
  241. <JournalCover imgs={urlArray} />
  242. </View>
  243. // <Image
  244. // className="gray_bg"
  245. // style={{ width: rpxToPx(178), height: rpxToPx(178), marginRight: rpxToPx(7), flexShrink: 0 }}
  246. // src={content.data[0].url+scale}
  247. // onClick={(e) => {
  248. // if (process.env.TARO_ENV == 'weapp') {
  249. // e.stopPropagation()
  250. // }
  251. // Taro.previewImage({
  252. // current: content.data[0].url,
  253. // urls: [content.data[0].url]
  254. // })
  255. // }}
  256. // mode="aspectFill" />
  257. }
  258. {
  259. content.type == 'PIC_TEXT' && <View style={{
  260. display: 'flex',
  261. flex: 1,
  262. flexShrink: 0,
  263. flexDirection: 'column',
  264. backgroundColor: 'transparent',
  265. paddingLeft: rpxToPx(17),
  266. paddingRight: 0,
  267. paddingTop: 0,
  268. paddingBottom: 0
  269. }}>
  270. <TimeTitleDesc
  271. className={'line3'}
  272. time=''
  273. title={content.data[0].title}
  274. desc={content.data[0].description}
  275. />
  276. </View>
  277. }
  278. </View>
  279. })
  280. }
  281. {
  282. props.mode != 'EAT' && props.mode != 'ACTIVE' && imgText()
  283. }
  284. {
  285. (props.mode == 'EAT' || props.mode == 'ACTIVE') && props.data.dataArray.map((content, i) => {
  286. switch (content.type) {
  287. case 'TEXT':
  288. {
  289. return content.data.map((detail, j) => {
  290. return singleItem('TEXT', '', detail, j * 10)
  291. })
  292. }
  293. break
  294. case 'PIC':
  295. {
  296. return content.data.map((detail, j) => {
  297. return singleItem('PIC', detail, '', j * 10)
  298. })
  299. }
  300. break
  301. case 'PIC_TEXT':
  302. const urlArray = content.data[0].urls.map(obj => obj.url);
  303. return singleItem('PIC_TEXT', content.data[0].url, content.data[0], i,urlArray)
  304. break
  305. }
  306. })
  307. }
  308. {
  309. props.type != 'FAST,SLEEP' && props.mode != 'EAT' && props.mode != 'ACTIVE' && props.data.windows.map((item, index) => {
  310. return <TargetProgress key={index} showLine={index < props.data.windows.length - 1}
  311. color={getThemeColor(item.window)}
  312. showRing={props.fast_type != 'LF'}
  313. desc={item.description}
  314. icon={
  315. props.fast_type == 'LF' ? <IconLongFast color={MainColorType.fast} width={rpxToPx(32)} /> : null
  316. }
  317. canvasId={`${item.window}${item.window_range.start_timestamp}${index}`}
  318. startTimestamp={item.window_range.start_timestamp}
  319. endTimerstamp={item.window_range.end_timestamp}
  320. />
  321. })
  322. }
  323. {
  324. props.type == 'FAST,SLEEP' && props.data.windows.length >= 2 && <TargetProgress
  325. showRing={true}
  326. doubleRing={true}
  327. first={props.data.windows[0]}
  328. second={props.data.windows[1]}
  329. canvasId={`double_${props.data.windows[0].window_range.start_timestamp}`}
  330. />
  331. }
  332. {/* fast_sleep双环无法展示时,显示一个placeholder 骨架图 */}
  333. {
  334. props.type == 'FAST,SLEEP' && props.data.windows.length < 2 && <View className='history_duration_bg' />
  335. }
  336. <View style={{ height: rpxToPx(0), flexShrink: 0 }} />
  337. </View>
  338. </View>
  339. }