import formatMilliseconds from "@/utils/format_time"; import { View, Text, Image } from "@tarojs/components"; import './History.scss' import Taro from "@tarojs/taro"; import dayjs from "dayjs"; import { useSelector } from "react-redux"; import { getThemeColor } from "./hooks/health_hooks"; import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings"; import { MainColorType } from "@/context/themes/color"; import { durationArc, startArc } from "./util"; import { IconMore } from "@/components/basic/Icons"; import showActionSheet from "@/components/basic/ActionSheet"; import { makeDone } from "@/services/health"; export default function HistoryItem(props: { data: any, preData: any, index: number, onClick: Function, isArchived?: boolean, refresh?: Function, mode: string, fast_type?: string }) { const health = useSelector((state: any) => state.health); let showActionSheetWithOptions; function preview(obj) { var list: any = [] props.data.events.map((item) => { item.moment.media.map((media) => { list.push(media.url) }) }) Taro.previewImage({ current: obj.url, urls: list }) } //npm install react-native-text-size function getTitle(item) { if (item.title) return item.title if (item.moment) { return item.moment.title } // if (health.mode == 'FAST') { // return '开始断食' // } // else if (health.mode == 'SLEEP') { // return '开始睡眠' // } return '' } function ring() { const common: RingCommon = { useCase: 'ChooseScenario', radius: 10, lineWidth: 3, isFast: true, status: 'WAIT_FOR_START' } const bgRing: BgRing = { color: MainColorType.ringBg } const realRing = { hideBg: true, color: props.mode == 'FAST,SLEEP'?getThemeColor('FAST'):getThemeColor(health.mode), startArc: startArc(props.data.window_range.start_timestamp), durationArc: durationArc(props.data.window_range.start_timestamp, props.data.window_range.end_timestamp) } const canvasId = props.mode == 'FAST,SLEEP'?'history_fast_sleep' + props.index:'history_' + props.index return } function ring2() { const common: RingCommon = { useCase: 'ChooseScenario', radius: 10, lineWidth: 3, isFast: true, status: 'WAIT_FOR_START' } const bgRing: BgRing = { color: MainColorType.ringBg } const realRing = { hideBg: true, color: getThemeColor('SLEEP'), startArc: startArc(props.data.events[1].time.timestamp), durationArc: durationArc(props.data.events[1].time.timestamp, props.data.events[2].time.timestamp) } const canvasId = 'history2_props_mode' + props.index return } function mediaCount() { let count = 0; props.data.events.map((item) => { if (item.moment) { item.moment.media.map((obj, j) => { count++; }) } }) return count; } function historyDate() { if (!props.preData) { return dayjs(props.data.window_range.start_timestamp).format('D') } if (dayjs(props.data.window_range.start_timestamp).format('D') == dayjs(props.preData.window_range.start_timestamp).format('D')) { return '' } return dayjs(props.data.window_range.start_timestamp).format('D') } return {historyDate()} { props.data.events.map((item, index) => { return {item.time && dayjs(item.time.timestamp).format('HH:mm')} {getTitle(item)} { item.moments && item.moments.map((moment, i) => { return {moment.description} }) } }) } 0 ? 9 : -10, marginRight: mediaCount() == 4 ? 80 : 0 }}> { props.data.events.map((item) => { if (item.moments) { return item.moments.map(moment => { return moment.media.map((obj, j) => { return preview(obj)} src={obj.url} key={j * 10} /> }) }) } }) } { props.fast_type != 'LF' && ring() } { props.data.window_range.end_timestamp && {formatMilliseconds(props.data.window_range.end_timestamp - props.data.window_range.start_timestamp)} } { props.mode == 'FAST,SLEEP' && props.data.events.length>2 && { props.fast_type != 'LF' && ring2() } { props.data.window_range.end_timestamp && {formatMilliseconds(props.data.events[2].time.timestamp - props.data.events[1].time.timestamp)} } } { props.isArchived && { if (process.env.TARO_ENV == 'weapp') { e.stopPropagation() } showActionSheet({ showActionSheetWithOptions: showActionSheetWithOptions, title: 'Oprate Title', itemList: ['标记完成', '补记'], success: (res) => { // tapActionSheet(res) switch (res) { case 1: break; case 0: makeDone(props.data.window_id).then(res => { global.refreshWindow() global.refreshHistory() if (props.refresh) props.refresh() }) break; } } }); }}> } }