|
|
@@ -5,14 +5,17 @@ import RecordItem from "../common/RecordItem";
|
|
|
import { deleteWorkoutRecord } from "@/services/workout";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
import './WorkoutHistory.scss';
|
|
|
-import Taro from "@tarojs/taro";
|
|
|
+import Taro, { useRouter } from "@tarojs/taro";
|
|
|
|
|
|
-export default function Component(props: { records: any }) {
|
|
|
+export default function Component(props: { records: any,count:number }) {
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
const [list, setList] = useState(props.records)
|
|
|
- const [selRecord,setSelRecord] = useState(null)
|
|
|
+ const [selRecord, setSelRecord] = useState(null)
|
|
|
+ const router = useRouter();
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
setList(props.records)
|
|
|
+ console.log(props.records)
|
|
|
}, [props.records])
|
|
|
|
|
|
|
|
|
@@ -34,7 +37,7 @@ export default function Component(props: { records: any }) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- global.delWorkoutRecord=()=>{
|
|
|
+ global.delWorkoutRecord = () => {
|
|
|
var record = selRecord
|
|
|
list.map(item => {
|
|
|
var index = item.records.findIndex(item => item.id == (record as any).id);
|
|
|
@@ -60,20 +63,20 @@ export default function Component(props: { records: any }) {
|
|
|
var list = record.items[0].groups
|
|
|
var count = 0
|
|
|
var unit = ''
|
|
|
- list.map(item=>{
|
|
|
- if (item.values.length==1){
|
|
|
- count += parseInt(item.values[0].value+'')
|
|
|
+ list.map(item => {
|
|
|
+ if (item.values.length == 1) {
|
|
|
+ count += parseInt(item.values[0].value + '')
|
|
|
unit = item.values[0].unit
|
|
|
}
|
|
|
})
|
|
|
- return count+unit
|
|
|
+ return count + unit
|
|
|
}
|
|
|
|
|
|
function getDuration(record) {
|
|
|
var list = record.items[0].groups
|
|
|
var start = list[0].start.timestamp
|
|
|
- var end = list[list.length-1].end.timestamp
|
|
|
- var left = (end-start)/1000
|
|
|
+ var end = list[list.length - 1].end.timestamp
|
|
|
+ var left = (end - start) / 1000
|
|
|
const hours = Math.floor(left / (60 * 60));
|
|
|
const minutes = Math.floor((left % (60 * 60)) / 60);
|
|
|
const seconds = Math.floor(left % 60);
|
|
|
@@ -87,19 +90,31 @@ export default function Component(props: { records: any }) {
|
|
|
return str
|
|
|
}
|
|
|
|
|
|
- function goDetail(record){
|
|
|
+ function goDetail(record) {
|
|
|
setSelRecord(record)
|
|
|
Taro.navigateTo({
|
|
|
- url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(record)
|
|
|
+ url: '/pages/workout/WorkoutDetail?title='+router.params.title+'&themeColor='+router.params.themeColor+'&detail=' + JSON.stringify(record)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
|
|
|
- var lastYearStr = '2023年'
|
|
|
+ var lastYearStr = '2024年'
|
|
|
return <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
{
|
|
|
user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => global.clearHistory()}>删除全部</Text>
|
|
|
}
|
|
|
+ {
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row' }}>
|
|
|
+ <View className="workout_summary">
|
|
|
+ <Text className="workout_summary_title">累积训练总量</Text>
|
|
|
+ <Text className="workout_summary_value" style={{ color: router.params.themeColor ?? 'white' }}>1</Text>
|
|
|
+ </View>
|
|
|
+ <View className="workout_summary">
|
|
|
+ <Text className="workout_summary_title">累积次数</Text>
|
|
|
+ <Text className="workout_summary_value" style={{ color: router.params.themeColor ?? 'white' }}>{props.count}次</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
{
|
|
|
(list as any).map(item => {
|
|
|
var showYear = lastYearStr != TimeFormatter.getYearByDate(item.date)
|
|
|
@@ -108,21 +123,22 @@ export default function Component(props: { records: any }) {
|
|
|
{
|
|
|
showYear && <Text className="year" style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>{TimeFormatter.getYearByDate(item.date)}</Text>
|
|
|
}
|
|
|
+
|
|
|
<Text className="operate_day" style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>{TimeFormatter.getMonthAndDayByDate(item.date)}</Text>
|
|
|
{
|
|
|
item.records.map(record => {
|
|
|
- return <RecordItem delete={() => deleteRecord(record)} onClick={()=>goDetail(record)}>
|
|
|
+ return <RecordItem delete={() => deleteRecord(record)} onClick={() => goDetail(record)}>
|
|
|
|
|
|
<View className="workout_record_item">
|
|
|
<Text style={{ color: 'white' }}>第 次</Text>
|
|
|
<View className="workout_history_content">
|
|
|
<View className="workout_history_item">
|
|
|
<Text>训练总量</Text>
|
|
|
- <Text className="workout_item_value">{getWorkoutCount(record)}</Text>
|
|
|
+ <Text className="workout_item_value" style={{ color: router.params.themeColor ?? 'white' }}>{getWorkoutCount(record)}</Text>
|
|
|
</View>
|
|
|
<View className="workout_history_item">
|
|
|
<Text>训练用时</Text>
|
|
|
- <Text className="workout_item_value">{getDuration(record)}</Text>
|
|
|
+ <Text className="workout_item_value" style={{ color: router.params.themeColor ?? 'white' }}>{getDuration(record)}</Text>
|
|
|
</View>
|
|
|
</View>
|
|
|
<Text className="workout_history_time">{formateHourMinutes(record.timestamp)}</Text>
|