|
@@ -1,31 +1,50 @@
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
import { View, Text } from "@tarojs/components";
|
|
import { View, Text } from "@tarojs/components";
|
|
|
import { useRouter } from "@tarojs/taro";
|
|
import { useRouter } from "@tarojs/taro";
|
|
|
-import { useEffect, useState } from "react";
|
|
|
|
|
|
|
+import { useEffect, useRef, useState } from "react";
|
|
|
import './Result.scss';
|
|
import './Result.scss';
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
import { useTranslation } from "react-i18next";
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { deleteWorkoutRecord } from "@/services/workout";
|
|
import { deleteWorkoutRecord } from "@/services/workout";
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
|
|
+import Layout from "@/components/layout/layout";
|
|
|
|
|
+import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
|
|
|
|
|
+import Box from "@/components/layout/Box";
|
|
|
|
|
+import MultiText from "@/components/view/MultiText";
|
|
|
|
|
+import { IconX } from "@/components/basic/Icons";
|
|
|
|
|
|
|
|
export default function Component() {
|
|
export default function Component() {
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
const [histories, setHistories] = useState<any>([])
|
|
const [histories, setHistories] = useState<any>([])
|
|
|
const [record, setRecord] = useState(null)
|
|
const [record, setRecord] = useState(null)
|
|
|
|
|
+ const [showDel, setShowDel] = useState(false)
|
|
|
|
|
+ const [delPosition, setDelPosition] = useState('absolute')
|
|
|
|
|
+ const myRef = useRef(null)
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
var data = JSON.parse(router.params.detail as any)
|
|
var data = JSON.parse(router.params.detail as any)
|
|
|
- console.log(data)
|
|
|
|
|
setRecord(data)
|
|
setRecord(data)
|
|
|
var list = data.items[0].groups
|
|
var list = data.items[0].groups
|
|
|
setHistories(list)
|
|
setHistories(list)
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ const query = Taro.createSelectorQuery();
|
|
|
|
|
+ query.select('#footId').boundingClientRect((rect) => {
|
|
|
|
|
+ console.log('Element size:', rect);
|
|
|
|
|
+ console.log('screen height', Taro.getSystemInfoSync().windowHeight)
|
|
|
|
|
+ setShowDel(true)
|
|
|
|
|
+ setDelPosition(Taro.getSystemInfoSync().windowHeight - (rect as any).top > 100 ? 'absolute' : 'relative')
|
|
|
|
|
+ }).exec();
|
|
|
|
|
+ }, 100)
|
|
|
|
|
+ }, [])
|
|
|
|
|
+
|
|
|
function twoTimeDuration(start, end) {
|
|
function twoTimeDuration(start, end) {
|
|
|
var time = Math.floor((end - start) / 1000);
|
|
var time = Math.floor((end - start) / 1000);
|
|
|
- time = time<1?1:time
|
|
|
|
|
|
|
+ time = time < 1 ? 1 : time
|
|
|
const hours = Math.floor(time / 3600);
|
|
const hours = Math.floor(time / 3600);
|
|
|
const minutes = Math.floor((time % 3600) / 60);
|
|
const minutes = Math.floor((time % 3600) / 60);
|
|
|
const seconds = Math.floor(time % 60);
|
|
const seconds = Math.floor(time % 60);
|
|
@@ -63,44 +82,47 @@ export default function Component() {
|
|
|
return count;
|
|
return count;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getValue_backup(item) {
|
|
|
|
|
- var list = item.values
|
|
|
|
|
- if ((record as any).items[0].format == 'TIME_SECONDS') {
|
|
|
|
|
- return ''
|
|
|
|
|
- // return list[0].value+'小时'+list[1].value+'分钟'+list[2].value+'秒'
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var count = 1
|
|
|
|
|
- var unit = ''
|
|
|
|
|
- for (var i = 0; i < list.length; i++) {
|
|
|
|
|
- count = count * (parseInt(list[i].value + ''))
|
|
|
|
|
- unit = unit + list[i].unit + '·'
|
|
|
|
|
- }
|
|
|
|
|
- var result = count + unit
|
|
|
|
|
- return result.substring(0, result.length - 1)
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
function getValue(item) {
|
|
function getValue(item) {
|
|
|
var list = item.values
|
|
var list = item.values
|
|
|
if ((record as any).items[0].format == 'TIME_SECONDS') {
|
|
if ((record as any).items[0].format == 'TIME_SECONDS') {
|
|
|
- return ''
|
|
|
|
|
|
|
+ var time = Math.floor((item.end.timestamp - item.start.timestamp) / 1000);
|
|
|
|
|
+ time = time < 1 ? 1 : time
|
|
|
|
|
+ debugger
|
|
|
|
|
+ var obj = TimeFormatter.workoutTimeAndUnitList(time)
|
|
|
|
|
+ return <MultiText values={obj.values}
|
|
|
|
|
+ units={obj.units}
|
|
|
|
|
+ color={router.params.themeColor + ''}
|
|
|
|
|
+ valueSize={rpxToPx(48)}
|
|
|
|
|
+ unitSize={rpxToPx(32)} />
|
|
|
// return list[0].value+'小时'+list[1].value+'分钟'+list[2].value+'秒'
|
|
// return list[0].value+'小时'+list[1].value+'分钟'+list[2].value+'秒'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var str = ''
|
|
|
|
|
- for (var i = 0; i < list.length; i++) {
|
|
|
|
|
- str += (list[i].value+list[i].unit+'·')
|
|
|
|
|
- }
|
|
|
|
|
- return str.substring(0, str.length - 1)
|
|
|
|
|
-
|
|
|
|
|
- // var count = 1
|
|
|
|
|
- // var unit = ''
|
|
|
|
|
|
|
+ // var str = ''
|
|
|
// for (var i = 0; i < list.length; i++) {
|
|
// for (var i = 0; i < list.length; i++) {
|
|
|
- // count = count * (parseInt(list[i].value + ''))
|
|
|
|
|
- // unit = unit + list[i].unit + '·'
|
|
|
|
|
|
|
+ // str += (list[i].value + list[i].unit + '·')
|
|
|
// }
|
|
// }
|
|
|
- // var result = count + unit
|
|
|
|
|
- // return result.substring(0, result.length - 1)
|
|
|
|
|
|
|
+ // return str.substring(0, str.length - 1)
|
|
|
|
|
+
|
|
|
|
|
+ return <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ list.map((item, index) => {
|
|
|
|
|
+ return <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
|
|
+ <MultiText values={[item.value]}
|
|
|
|
|
+ units={[item.unit]}
|
|
|
|
|
+ color={router.params.themeColor + ''}
|
|
|
|
|
+ valueSize={rpxToPx(48)}
|
|
|
|
|
+ unitSize={rpxToPx(32)} />
|
|
|
|
|
+ {
|
|
|
|
|
+ index<list.length-1 && <IconX width={rpxToPx(32)} color={router.params.themeColor+''} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ index<list.length-1 && <View style={{ width: 1 }} />
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function del() {
|
|
function del() {
|
|
@@ -125,29 +147,26 @@ export default function Component() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getTotalValue(){
|
|
|
|
|
|
|
+ function getTotalValue() {
|
|
|
if (!record) return ''
|
|
if (!record) return ''
|
|
|
- if (!(record as any).items[0].summary_stats || (record as any).items[0].summary_stats.length==0){
|
|
|
|
|
|
|
+ if (!(record as any).items[0].summary_stats || (record as any).items[0].summary_stats.length == 0) {
|
|
|
return ''
|
|
return ''
|
|
|
}
|
|
}
|
|
|
if ((record as any).items[0].format == 'TIME_SECONDS') {
|
|
if ((record as any).items[0].format == 'TIME_SECONDS') {
|
|
|
var time = (record as any).items[0].summary_stats[0].value
|
|
var time = (record as any).items[0].summary_stats[0].value
|
|
|
- const hours = Math.floor(time / 3600);
|
|
|
|
|
- const minutes = Math.floor((time % 3600) / 60);
|
|
|
|
|
- const seconds = Math.floor(time % 60);
|
|
|
|
|
- var str = ''
|
|
|
|
|
- if (hours > 0) {
|
|
|
|
|
- str = str + hours + '小时'
|
|
|
|
|
- }
|
|
|
|
|
- if (minutes > 0) {
|
|
|
|
|
- str = str + minutes + '分钟'
|
|
|
|
|
- }
|
|
|
|
|
- if (seconds > 0) {
|
|
|
|
|
- str = str + seconds + '秒'
|
|
|
|
|
- }
|
|
|
|
|
- return str
|
|
|
|
|
|
|
+ var obj = TimeFormatter.workoutTimeAndUnitList(time)
|
|
|
|
|
+ return <MultiText values={obj.values}
|
|
|
|
|
+ units={obj.units}
|
|
|
|
|
+ color={router.params.themeColor + ''}
|
|
|
|
|
+ valueSize={rpxToPx(48)}
|
|
|
|
|
+ unitSize={rpxToPx(32)} />
|
|
|
}
|
|
}
|
|
|
- return (record as any).items[0].summary_stats[0].value+(record as any).items[0].summary_stats[0].unit
|
|
|
|
|
|
|
+ return <MultiText values={[(record as any).items[0].summary_stats[0].value]}
|
|
|
|
|
+ units={[(record as any).items[0].summary_stats[0].unit]}
|
|
|
|
|
+ color={router.params.themeColor + ''}
|
|
|
|
|
+ valueSize={rpxToPx(48)}
|
|
|
|
|
+ unitSize={rpxToPx(32)} />
|
|
|
|
|
+ // return (record as any).items[0].summary_stats[0].value + (record as any).items[0].summary_stats[0].unit
|
|
|
// var count = 0
|
|
// var count = 0
|
|
|
// histories.map(item=>{
|
|
// histories.map(item=>{
|
|
|
// if (item.type=='WORK'){
|
|
// if (item.type=='WORK'){
|
|
@@ -157,66 +176,113 @@ export default function Component() {
|
|
|
// return count
|
|
// return count
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getRealDuration(){
|
|
|
|
|
|
|
+ function getRealDuration() {
|
|
|
if (!record) return ''
|
|
if (!record) return ''
|
|
|
|
|
|
|
|
var seconds = 0
|
|
var seconds = 0
|
|
|
- histories.map(item=>{
|
|
|
|
|
|
|
+ histories.map(item => {
|
|
|
var time = Math.floor((item.end.timestamp - item.start.timestamp) / 1000);
|
|
var time = Math.floor((item.end.timestamp - item.start.timestamp) / 1000);
|
|
|
- if (time<1){
|
|
|
|
|
|
|
+ if (time < 1) {
|
|
|
time = 1
|
|
time = 1
|
|
|
}
|
|
}
|
|
|
- seconds+=time
|
|
|
|
|
|
|
+ seconds += time
|
|
|
})
|
|
})
|
|
|
// var seconds = Math.floor((histories[histories.length-1].end.timestamp-histories[0].start.timestamp)/1000)
|
|
// var seconds = Math.floor((histories[histories.length-1].end.timestamp-histories[0].start.timestamp)/1000)
|
|
|
- return TimeFormatter.workoutTime(seconds)
|
|
|
|
|
|
|
+ var obj = TimeFormatter.workoutTimeAndUnitList(seconds)
|
|
|
|
|
+ return <MultiText values={obj.values}
|
|
|
|
|
+ units={obj.units}
|
|
|
|
|
+ color={router.params.themeColor + ''}
|
|
|
|
|
+ valueSize={rpxToPx(48)}
|
|
|
|
|
+ unitSize={rpxToPx(32)} />
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getPlanDuration(){
|
|
|
|
|
|
|
+ function getPlanDuration() {
|
|
|
if (!record) return ''
|
|
if (!record) return ''
|
|
|
- var seconds = (record as any).items[0].duration/1000
|
|
|
|
|
- return TimeFormatter.workoutTime(seconds)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column' }}>
|
|
|
|
|
- <Text className="result_detail_text" style={{ color: router.params.themeColor }}>{router.params.title}</Text>
|
|
|
|
|
- <Text className="result_type">计时训练</Text>
|
|
|
|
|
- <Text className="result_group_text">训练统计</Text>
|
|
|
|
|
- <View style={{ marginLeft: rpxToPx(32), display: 'flex', flexDirection: 'column',marginBottom:rpxToPx(56) }}>
|
|
|
|
|
- <Text className="result_summary_title">总量</Text>
|
|
|
|
|
- <Text className="result_summary_total" style={{ color: router.params.themeColor }}>{getTotalValue()}</Text>
|
|
|
|
|
- <Text className="result_summary_title">用时</Text>
|
|
|
|
|
- <View style={{ flexDirection: 'row', display: 'flex', width: '100%' }}>
|
|
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
- <Text className="result_summary_time" style={{ color: router.params.themeColor }}>{getRealDuration()}</Text>
|
|
|
|
|
- <Text className="result_summary_desc">实际</Text>
|
|
|
|
|
- </View>
|
|
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginLeft:rpxToPx(90) }}>
|
|
|
|
|
- <Text className="result_summary_time" style={{ color: router.params.themeColor }}>{getPlanDuration()}</Text>
|
|
|
|
|
- <Text className="result_summary_desc">计划</Text>
|
|
|
|
|
- </View>
|
|
|
|
|
|
|
+ var seconds = (record as any).items[0].duration / 1000
|
|
|
|
|
+ return TimeFormatter.formateDurationBySeconds(seconds)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ function detail() {
|
|
|
|
|
+ return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column' }}>
|
|
|
|
|
+ <Text className="result_detail_text" style={{ color: router.params.themeColor, fontSize: rpxToPx(56) }}>{router.params.title}</Text>
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', color: '#fff', marginLeft: rpxToPx(46) }}>
|
|
|
|
|
+ <Text style={{ fontSize: rpxToPx(40), fontWeight: 'bold', marginBottom: rpxToPx(6) }}>训练统计</Text>
|
|
|
|
|
+ <Text className="train_summary_title">总量</Text>
|
|
|
|
|
+ {
|
|
|
|
|
+ getTotalValue()
|
|
|
|
|
+ }
|
|
|
|
|
+ {/* <Text className="train_summary_value" style={{ color: workout.item.theme_color }}></Text> */}
|
|
|
|
|
+ <Text className="train_summary_title">用时</Text>
|
|
|
|
|
+ {
|
|
|
|
|
+ getRealDuration()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
</View>
|
|
</View>
|
|
|
|
|
+ <Text className="result_group_text" style={{ marginBottom: rpxToPx(48), marginTop: rpxToPx(112) }}>详情</Text>
|
|
|
|
|
+
|
|
|
|
|
+ {/* <View style={{ position: 'relative' }}>
|
|
|
|
|
+ <Box key={index} >
|
|
|
|
|
+ <View>
|
|
|
|
|
+ <Text className="working_index">{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginTop: item.type == 'REST' ? rpxToPx(60) : 0, marginBottom: item.type == 'REST' ? rpxToPx(28) : 0 }}>
|
|
|
|
|
+ {item.type == 'REST' && workout.item.schemas[0].format != 'TIME_SECONDS' &&
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ <MultiText values={[parseInt(item.value)]} units={[workout.item.schemas[0].values[0].unit]} color={workout.item.theme_color} valueSize={rpxToPx(48)} unitSize={rpxToPx(32)} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ item.value2 && <IconX width={rpxToPx(32)} color={workout.item.theme_color} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ item.value2 && <View style={{width:1}} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ item.value2 && <MultiText values={[parseInt(item.value2)]} units={[workout.item.schemas[0].values[1].unit]} color={workout.item.theme_color} valueSize={rpxToPx(48)} unitSize={rpxToPx(32)} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ item.value3 && <MultiText values={[parseInt(item.value3)]} units={[workout.item.schemas[0].values[2].unit]} color={workout.item.theme_color} valueSize={rpxToPx(48)} unitSize={rpxToPx(32)} />
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ // <Text className="working_group_value" style={{ color: workout.item.theme_color }}>{getGroupValue(item)}</Text>
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ item.type == 'REST' && workout.item.schemas[0].format == 'TIME_SECONDS' &&
|
|
|
|
|
+ <MultiText values={twoTimeFormateList(groups[index - 1].time,item.time).values} units={twoTimeFormateList(groups[index - 1].time,item.time).units} color={workout.item.theme_color} valueSize={rpxToPx(48)} unitSize={rpxToPx(32)} />
|
|
|
|
|
+ }
|
|
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
|
|
+
|
|
|
|
|
+ <Text className="working_group_duration" style={{ opacity: item.type != 'REST' || workout.item.schemas[0].format != 'TIME_SECONDS' ? 0.4 : 0 }}>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
|
|
|
|
|
+
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </Box>
|
|
|
|
|
+ </View> */}
|
|
|
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ histories.map((item, index) => {
|
|
|
|
|
+ return <View style={{ position: 'relative' }}>
|
|
|
|
|
+ <Box key={index} >
|
|
|
|
|
+ <View>
|
|
|
|
|
+ <Text className="working_index">{item.type == 'WORK' ? `第${getIndex(index)}组` : '组间休息'}</Text>
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginTop: item.type == 'WORK' ? rpxToPx(60) : 0, marginBottom: item.type == 'WORK' ? rpxToPx(0) : 0 }}>
|
|
|
|
|
+ {item.type == 'WORK' && getValue(item)}
|
|
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
|
|
+ <Text className="working_group_duration" style={{ opacity: item.type == 'WORK' && (record as any).items[0].format == 'TIME_SECONDS' ? 0 : 0.4 }}>{twoTimeDuration(item.start.timestamp, item.end.timestamp)}</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </Box>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ <View style={{ width: 0, height: 0 }} ref={myRef} id='footId' />
|
|
|
|
|
+ <Text className={delPosition == 'absolute' ? "result_del" : 'resule_del_relative'} style={{ opacity: showDel ? 1 : 0 }} onClick={del}>删除训练记录</Text>
|
|
|
</View>
|
|
</View>
|
|
|
- {/* <View>
|
|
|
|
|
- <Text>用时</Text>
|
|
|
|
|
- <Text style={{ color: router.params.themeColor }}>111</Text>
|
|
|
|
|
- </View> */}
|
|
|
|
|
- <Text className="result_group_text" style={{marginBottom:rpxToPx(48),marginTop:0}}>训练详情</Text>
|
|
|
|
|
- {/* {
|
|
|
|
|
- histories.length > 0 && <Text className="result_count">共{getCount()}组</Text>
|
|
|
|
|
- } */}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- {
|
|
|
|
|
- histories.map((item, index) => {
|
|
|
|
|
- return <View key={index} className={item.type == 'WORK' ? 'result_item' : 'result_item result_item_rest'}>
|
|
|
|
|
- <Text>{item.type == 'WORK' ? `第${getIndex(index)}组` : '组间休息'}</Text>
|
|
|
|
|
- {item.type == 'WORK' && <Text className="workout_result_value" style={{ color: router.params.themeColor }}>{getValue(item)}</Text>}
|
|
|
|
|
- <Text className="result_time">{twoTimeDuration(item.start.timestamp, item.end.timestamp)}</Text>
|
|
|
|
|
- </View>
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- <Text className="result_del" onClick={del}>删除训练记录</Text>
|
|
|
|
|
- </View>
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return <Layout children={detail()}
|
|
|
|
|
+ title={router.params.title}
|
|
|
|
|
+ type={TemplateType.customHeader}
|
|
|
|
|
+ titleShowStyle={NaviBarTitleShowType.scrollToShow}
|
|
|
|
|
+ />
|
|
|
}
|
|
}
|