import { View, Text, Image } from "@tarojs/components"; import { useEffect, useRef, useState } from "react"; import { records } from "@/services/health"; import './History.scss' import Calendar from "./calendar"; import { useSelector } from "react-redux"; import HistoryItem from "./HistoryItem"; import { rpxToPx } from "@/utils/tools"; import { jumpPage } from "../trackTimeDuration/hooks/Common"; import Taro from "@tarojs/taro"; import { getThemeColor } from "./hooks/health_hooks"; import { TimeFormatter } from "@/utils/time_format"; let lastMode = '' export default function MainHistory(props: { type?: string, fast_type?: string }) { const [list, setList] = useState([]) const [page, setPage] = useState(1) const [total, setTotal] = useState(0) const [loaded, setLoaded] = useState(false) const refDemo = useRef() const health = useSelector((state: any) => state.health); const healthRef = useRef(health) global.refreshHistory = () => { refresh() } useEffect(() => { if (props.type) { loadData(1) } }, [props.type]) useEffect(() => { if (lastMode != health.mode) { lastMode = health.mode loadData(1) } }, [health.mode]) function refresh() { loadData(1) setPage(1) } function more() { var index = page; index++; setPage(index) loadData(index) } function loadData(index: number) { var params: any = { window: props.type ? props.type : health.mode, limit: 10, page: index } if (props.fast_type) { params.fast_type = props.fast_type } records(params).then(res => { setLoaded(true) if (index == 1) { setList((res as any).data) setTotal((res as any).total) } else { setList([...list, ...(res as any).data]) } if ((res as any).data.length > 0) { setTimeout(() => { // var array:any = []; // (res as any).data.map((item,index)=>{ // array.push('#history_id_'+index) // }) // var ids = array.join(',') // console.log(array) // console.log(ids) const query = Taro.createSelectorQuery(); query.selectAll('#history_id_0').boundingClientRect((rect) => { console.log(rect) }).exec(); }, 1000) } }) } if (!loaded) return return {/* */} {/* */} { (list.length > 0 || health.mode == 'EAT') && Recent { health.mode == 'EAT' && { jumpPage('/_health/pages/archive') }}> } } { health.mode == 'EAT' && health.eatArchived && health.eatArchived.archived && { jumpPage('/_health/pages/archive') }}> [{health.eatArchived.real_count}/{health.eatArchived.target_count} Meals] Archived {TimeFormatter.dateDescription(new Date(health.eatArchived.timestamp).getTime(), true, false)} { health.eatArchived.images.map((item, index) => { return }) } } { list.map((item, index) => { return 0 ? list[index - 1] : null} index={index} mode={props.type ?? health.mode} fast_type={props.fast_type} onClick={() => { jumpPage('/_health/pages/moment_detail') }} /> {/* { props.type == 'EAT' && } { props.type == 'FAST' && } { props.type == 'ACTIVE' && } { props.type == 'SLEEP' && } */} }) } { (list.length > 0) && (total == list.length) && 没有更多了 } }