Leon 2 anni fa
parent
commit
cbe6d4cf0a

+ 28 - 0
src/app.scss

@@ -1,4 +1,6 @@
 /* #ifdef weapp */
+@import '@/utils/common.scss';
+
 page {
     background-color: #000;
 }
@@ -180,6 +182,32 @@ page {
     text-align: center;
 }
 
+.add_more{
+    width: 320px;
+    height: 290px;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+    border-radius: $boxBorderRadius;
+    padding-left: 36px;
+    padding-right: 36px;
+    padding-top: 24px;
+    padding-bottom: 24px;
+    background-color: #1c1c1c;
+    box-sizing: border-box;
+    margin-bottom: 20px;
+}
+
+.add_more_text{
+    margin-top: 32px;
+    color: #fff;
+    font-weight: bold;
+    font-size: 32px;
+    line-height: 36px;
+    opacity: 0.8;
+}
+
 
 // @media only screen and (-webkit-min-device-pixel-ratio: 2.0) {
 //     .px1Width::after {

BIN
src/assets/images/add2.png


+ 8 - 2
src/features/trackSomething/components/Metric.tsx

@@ -1,4 +1,4 @@
-import { View, Text, ScrollView, PageContainer } from "@tarojs/components";
+import { View, Text, Image, PageContainer } from "@tarojs/components";
 import './Metric.scss'
 import { useDispatch, useSelector } from "react-redux";
 import { useEffect, useRef, useState } from "react";
@@ -18,6 +18,7 @@ import MetricModalOrder from './MetricModalOrder';
 import MetricModalAdd from "./MetricModalAdd";
 import MetricModalTime from "./MetricModalTime";
 import Modal from "@/components/layout/Modal";
+import { rpxToPx } from "@/utils/tools";
 
 let useNavigation;
 if (process.env.TARO_ENV == 'rn') {
@@ -209,7 +210,12 @@ export default function Component(props: any) {
                         />
                     })
                 }
-
+                {
+                    user.isLogin && <View className="add_more" onClick={addBtnClick}>
+                        <Image style={{ width: rpxToPx(48), height: rpxToPx(48) }} src={require('@assets/images/add2.png')} />
+                        <Text className="add_more_text">添加更多</Text>
+                    </View>
+                }
 
             </View>
             <View className="space_width" ></View>

+ 3 - 1
src/features/trackSomething/components/MetricModalChoose.tsx

@@ -42,6 +42,7 @@ export default function Component(props: {
     }
 
     function tapItem(obj) {
+        
         var check = !obj.is_following
         var count = 0;
         oldList.map(item => {
@@ -59,7 +60,8 @@ export default function Component(props: {
             if (max == count) {
                 Taro.showToast({
                     icon: 'none',
-                    title: t('feature.common.toast.max_metric_count',{count:count}),
+                    title:`高级会员可选择${count}项以上`
+                    // title: t('feature.common.toast.max_metric_count',{count:count}),
                 })
                 return
             }

+ 52 - 0
src/features/workout/Result.scss

@@ -0,0 +1,52 @@
+.result_detail_text{
+    color: #fff;
+    font-size: 40px;
+    line-height: 40px;
+    font-weight: bold;
+    margin-left: 32px;
+}
+
+.result_count{
+    margin-top: 14px;
+    color: #fff;
+    opacity: 0.4;
+    font-size: 32px;
+    line-height: 32px;
+    font-weight: bold;
+    margin-left: 32px;
+    margin-bottom: 18px;
+}
+
+.result_item{
+    margin-left: 32px;
+    margin-right: 32px;
+    margin-bottom: 28px;
+    background-color: #1c1c1c;
+    padding-left: 40px;
+    padding-right: 40px;
+    padding-top: 28px;
+    padding-bottom: 28px;
+    display: flex;
+    flex-direction: column;
+    color: #fff;
+    position: relative;
+}
+
+.result_item_rest{
+    background-color: #121212;
+}
+
+.result_time{
+    position: absolute;
+    right: 32px;
+    bottom: 28px;
+}
+
+.result_del{
+    position: absolute;
+    left: 0;
+    right: 0;
+    bottom: 120px;
+    color: #FA5151;
+    text-align: center;
+}

+ 79 - 20
src/features/workout/Result.tsx

@@ -1,20 +1,25 @@
 import { ColorType } from "@/context/themes/color";
-import { View,Text } from "@tarojs/components";
+import { View, Text } from "@tarojs/components";
 import { useRouter } from "@tarojs/taro";
 import { useEffect, useState } from "react";
+import './Result.scss';
+import Taro from "@tarojs/taro";
+import { useTranslation } from "react-i18next";
+import { deleteWorkoutRecord } from "@/services/workout";
 
-export default function Component(){
+export default function Component() {
     const router = useRouter();
-    const [histories,setHistories] = useState<any>([])
-
-    useEffect(()=>{
-        var  list = JSON.parse(router.params.detail  as any)
-        // if (list.length>=2&&list[list.length-2].type=='REST'){
-        //     list.splice(list.length-1,1)
-        // }
-        // console.log(list)
+    const [histories, setHistories] = useState<any>([])
+    const [record,setRecord] = useState(null)
+    const {t} = useTranslation()
+
+    useEffect(() => {
+        var data = JSON.parse(router.params.detail as any)
+        console.log(data)
+        setRecord(data)
+        var list = data.items[0].groups
         setHistories(list)
-    },[])
+    }, [])
 
     function twoTimeDuration(start, end) {
         var time = Math.floor((end - start) / 1000);
@@ -31,24 +36,78 @@ export default function Component(){
         if (seconds > 0) {
             strDuration += `${seconds}秒`
         }
-        return strDuration.length==0?'1秒':strDuration
+        return strDuration.length == 0 ? '1秒' : strDuration
+    }
+
+    function getCount() {
+        var count = 0
+        histories.map(item => {
+            if (item.type == 'GROUP') {
+                count++
+            }
+        })
+
+        return count
+    }
+
+    function getIndex(index) {
+        var count = 0
+        for (var i = 0; i <= index; i++) {
+            if (histories[i].type == 'GROUP') {
+                count++
+            }
+        }
+        return count;
     }
 
-    return <View  style={{color:'#fff',display:'flex',flexDirection:'column'}}>
-        <Text>训练组</Text>
+    function getValue(item) {
+        var list = item.values
+        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 del() {
+        Taro.showModal({
+            title: t('feature.common.modal.delete_item_title'),
+            content: t('feature.common.modal.delete_item_content'),
+            success: function (res) {
+                if (res.confirm) {
+                    delData()
+                }
+            }
+        })
+    }
+
+    function delData(){
+        deleteWorkoutRecord({ id: (record as any).id }).then(res => {
+            global.delWorkoutRecord()
+            global.refreshWorkout()
+            Taro.navigateBack()
+        })
+    }
+
+    return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column' }}>
+        <Text className="result_detail_text">训练组</Text>
         {
-            histories.length>0 && <Text>共{histories[histories.length-1].index}组</Text>
+            histories.length > 0 && <Text className="result_count">共{getCount()}组</Text>
         }
-        
+
 
         {
             histories.map((item, index) => {
-                return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
-                    <Text>{item.type == 'GROUP' ? `第${item.index}组` : '组间休息'}</Text>
-                    {item.type == 'GROUP'  && <Text style={{ color: ColorType.workout }}>{item.value}x{item.value2}</Text>}
-                    <Text>{twoTimeDuration(item.start, item.end)}</Text>
+                return <View key={index} className={item.typ == 'GROUP' ? 'result_item' : 'result_item result_item_rest'}>
+                    <Text>{item.type == 'GROUP' ? `第${getIndex(index)}组` : '组间休息'}</Text>
+                    {item.type == 'GROUP' && <Text style={{ color: ColorType.workout }}>{getValue(item)}</Text>}
+                    <Text className="result_time">{twoTimeDuration(item.start.timestamp, item.end.timestamp)}</Text>
                 </View>
             })
         }
+        <Text className="result_del" onClick={del}>删除训练记录</Text>
     </View>
 }

+ 40 - 3
src/features/workout/Workout.tsx

@@ -1,4 +1,4 @@
-import { View, Text, ScrollView } from "@tarojs/components";
+import { View, Text, ScrollView, Image } from "@tarojs/components";
 import './Workout.scss'
 import { useDidShow, useReady } from "@tarojs/taro";
 import { useDispatch, useSelector } from "react-redux";
@@ -24,6 +24,7 @@ import { workoutCards, workoutFollows, workoutGroups } from "@/services/workout"
 import { setAuth } from "../trackSomething/hooks/werun";
 import MetricModalOrder from "../trackSomething/components/MetricModalOrder";
 import MetricModalChoose from "../trackSomething/components/MetricModalChoose";
+import { rpxToPx } from "@/utils/tools";
 // import { useNavigation } from "@react-navigation/native";
 
 let useNavigation;
@@ -123,6 +124,7 @@ export default function Component(props: any) {
                     dispatch(startSuccess({
                         start: workoutObj.time,
                         code: workoutObj.code,
+                        duration:workoutObj.duration
                     }));
 
                     timer = setInterval(() => {
@@ -140,6 +142,11 @@ export default function Component(props: any) {
         getGroups()
     }
 
+    global.refreshWorkout = () => {
+        getCards()
+        getGroups()
+    }
+
     function getCards() {
         setTriggered(true)
         workoutCards().then(res => {
@@ -223,7 +230,14 @@ export default function Component(props: any) {
             if (item.code != '_walk') {
                 setSelItem(item)
                 dispatch(setCurrentWorkoutItem(item))
-                workoutStart()
+                //进行中的处理
+                if (item.code == workout.code && workout.status == 'ing') {
+                    Taro.navigateTo({ url: '/pages/workout/Working?type=stop_watch&restore=true' })
+                }
+                else {
+                    workoutStart()
+                }
+                
                 return
             }
             if (allowRun) {
@@ -363,6 +377,10 @@ export default function Component(props: any) {
 
     function goDetail(item) {
         if (user.isLogin) {
+            if (item.code != '_walk') {
+                jumpPage('/pages/common/RecordsHistory?type=workout&refreshList=getCards&title=' + item.name + '&code=' + item.code + '&themeColor=' + item.theme_color)
+                return
+            }
             if (!allowRun) {
                 return;
             }
@@ -514,7 +532,18 @@ export default function Component(props: any) {
                         strTitle = '计时训练'
 
                         if (item.code == workout.code && workout.status == 'ing') {
-                            strTitle = TimeFormatter.formateTimeNow(workout.start)
+                            showDetail = true
+                            strTitle = '进入'
+                            value = TimeFormatter.formateTimeNow(workout.start)
+                            desc = '计时训练中'
+                            unit = ''
+                        }
+                        else {
+                            if (!item.latest_record){
+                                value = '暂无记录'
+                                desc = ''
+                                showDetail = false
+                            }
                         }
                     }
 
@@ -557,6 +586,14 @@ export default function Component(props: any) {
                 }}
             />
 
+            {
+                user.isLogin && <View className="add_more" onClick={addBtnClick}>
+                    <Image style={{ width: rpxToPx(48), height: rpxToPx(48) }} src={require('@assets/images/add2.png')} />
+                    <Text className="add_more_text">添加更多</Text>
+                </View>
+            }
+
+
             {/* <MetricItem title='平板支撑'
                 // value={allowRun ? stepInfo ? (stepInfo as any).step : '' : '未开启'}
                 value={10}

+ 47 - 0
src/features/workout/WorkoutHistory.scss

@@ -0,0 +1,47 @@
+@import '@/utils/common.scss';
+
+.workout_record_item{
+    display: flex;
+    margin-left: 46px;
+    margin-right: 46px;
+    display: flex;
+    flex-direction: column;
+    background-color: #1C1C1C;
+    border-radius: $boxBorderRadius;
+    padding-left: 40px;
+    padding-right: 40px;
+    margin-top: 16px;
+    padding-top: 40px;
+    padding-bottom: 60px;
+}
+.workout_history_time{
+    font-size: 28px;
+    color: rgba($color: #ffffff, $alpha: 0.4);
+    font-weight: 400;
+    position: absolute;
+    right: 76px;
+    bottom: 20px;
+}
+
+.workout_history_content{
+    display: flex;
+    flex-direction: row;
+    width: 100%;
+
+}
+
+.workout_history_item{
+    display: flex;
+    flex: 1;
+    flex-direction: column;
+    align-items: center;
+    color: rgba($color: #ffffff, $alpha: 0.4);
+}
+
+.workout_item_value{
+    font-size: 40px;
+    line-height: 40px;
+    color: #EEC01F;
+    font-weight: bold;
+    margin-top: 10px;
+}

+ 139 - 0
src/features/workout/WorkoutHistory.tsx

@@ -0,0 +1,139 @@
+import { View, Text } from "@tarojs/components";
+import { useEffect, useState } from "react";
+import { useSelector } from "react-redux";
+import RecordItem from "../common/RecordItem";
+import { deleteWorkoutRecord } from "@/services/workout";
+import { TimeFormatter } from "@/utils/time_format";
+import './WorkoutHistory.scss';
+import Taro from "@tarojs/taro";
+
+export default function Component(props: { records: any }) {
+    const user = useSelector((state: any) => state.user);
+    const [list, setList] = useState(props.records)
+    const [selRecord,setSelRecord] = useState(null)
+    useEffect(() => {
+        setList(props.records)
+    }, [props.records])
+
+
+    function deleteRecord(record: any) {
+        deleteWorkoutRecord({ id: record.id }).then(res => {
+            list.map(item => {
+                var index = item.records.findIndex(item => item.id == record.id);
+                if (index >= 0)
+                    item.records.splice(index, 1)
+            })
+            for (let i = list.length; i > 0; i--) {
+                if (list[i - 1].records.length == 0) {
+                    list.splice(i - 1, 1)
+                }
+            }
+            // console.log(list)
+            setList(JSON.parse(JSON.stringify(list)))
+            global.refreshWorkout()
+        })
+    }
+
+    global.delWorkoutRecord=()=>{
+        var record = selRecord
+        list.map(item => {
+            var index = item.records.findIndex(item => item.id == (record as any).id);
+            if (index >= 0)
+                item.records.splice(index, 1)
+        })
+        for (let i = list.length; i > 0; i--) {
+            if (list[i - 1].records.length == 0) {
+                list.splice(i - 1, 1)
+            }
+        }
+        setList(JSON.parse(JSON.stringify(list)))
+    }
+
+    function formateHourMinutes(timestamp: number) {
+        var date = new Date(timestamp)
+        var hour = date.getHours()
+        var minutes = date.getMinutes()
+        return `${hour < 10 ? '0' + hour : hour}:${minutes < 10 ? '0' + minutes : minutes}`
+    }
+
+    function getWorkoutCount(record) {
+        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+'')
+                unit = item.values[0].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
+        const hours = Math.floor(left / (60 * 60));
+        const minutes = Math.floor((left % (60 * 60)) / 60);
+        const seconds = Math.floor(left % 60);
+
+        var str = hours > 10 ? hours : '0' + hours
+        str += ':'
+        str += (minutes > 10 ? minutes : '0' + minutes) + ''
+        str += ':'
+        str += (seconds > 10 ? seconds : '0' + seconds) + ''
+
+        return str
+    }
+
+    function goDetail(record){
+        setSelRecord(record)
+        Taro.navigateTo({
+            url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(record)
+        })
+    }
+
+
+    var lastYearStr = '2023年'
+    return <View style={{ display: 'flex', flexDirection: 'column' }}>
+        {
+            user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => global.clearHistory()}>删除全部</Text>
+        }
+        {
+            (list as any).map(item => {
+                var showYear = lastYearStr != TimeFormatter.getYearByDate(item.date)
+                lastYearStr = TimeFormatter.getYearByDate(item.date)
+                return <View style={{ display: 'flex', flexDirection: 'column' }}>
+                    {
+                        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)}>
+
+                                <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>
+                                        </View>
+                                        <View className="workout_history_item">
+                                            <Text>训练用时</Text>
+                                            <Text className="workout_item_value">{getDuration(record)}</Text>
+                                        </View>
+                                    </View>
+                                    <Text className="workout_history_time">{formateHourMinutes(record.timestamp)}</Text>
+
+                                </View>
+                            </RecordItem>
+                        })
+                    }
+                </View>
+            })
+        }
+
+    </View>
+}

+ 49 - 28
src/features/workout/WorkoutStopWatch.tsx

@@ -3,7 +3,7 @@ import { TimeFormatter } from "@/utils/time_format";
 import { View, Text } from "@tarojs/components";
 import { useEffect, useState } from "react";
 import { ChooseScenarioBtn } from "../common/SpecBtns";
-import Taro from "@tarojs/taro";
+import Taro, { useRouter } from "@tarojs/taro";
 import { WorkoutType } from "@/utils/types";
 import Modal from "@/components/layout/Modal";
 import PickerViews from "@/components/input/PickerViews";
@@ -16,7 +16,9 @@ import Box from "@/components/layout/Box";
 
 var timer
 var lastStrTime
-export default function Component(props: { targetCount: any, type: WorkoutType, end: Function }) {
+export default function Component(props: { targetCount: any, end: Function }) {
+    const router = useRouter();
+
     const workout = useSelector((state: any) => state.workout);
     const [index, setIndex] = useState(1)
     const [count, setCount] = useState(0)
@@ -30,22 +32,40 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
     const [isPaused, setIsPaused] = useState(false);
     const dispatch = useDispatch();
 
+
     const [pickerItems, setPickerItems] = useState<any[]>([])
     const [pickerValue, setPcikerValue] = useState<any[]>([])
 
+
     useEffect(() => {
-        var array = [{
-            code: workout.item.code,
-            index: index,
-            time: startTime,
-            type: 'GROUP'
-        }]
-        setGroups(array)
-        saveCache(array)
-        dispatch(startSuccess({
-            start: startTime,
-            code: workout.item.code,
-        }))
+        if (router.params.restore) {
+            Taro.getStorage({
+                key: 'lastWorkout', success: function (res) {
+                    var workouts = JSON.parse(res.data)
+                    debugger
+                    setGroups(workouts)
+                    setStartTime(workouts[workouts.length - 1].time)
+                }, fail: function (err) {
+                    console.log(err, 'no cache')
+                }
+            })
+        }
+        else {
+            var array = [{
+                code: workout.item.code,
+                index: index,
+                time: startTime,
+                duration: props.targetCount,
+                type: 'GROUP'
+            }]
+            setGroups(array)
+            saveCache(array)
+            dispatch(startSuccess({
+                start: startTime,
+                code: workout.item.code,
+                duration: props.targetCount
+            }))
+        }
 
 
         var item = workout.item
@@ -53,20 +73,19 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         var selects: any = []
         item.schemas[0].values.map(obj => {
             var list: any = []
-            var min = parseInt(obj.min+'')
-            var max = parseInt(obj.max+'')
-            var step = parseInt(obj.step+'')
+            var min = parseInt(obj.min + '')
+            var max = parseInt(obj.max + '')
+            var step = parseInt(obj.step + '')
             var defaultV = parseInt(obj.default_value)
             for (var i = min; i <= max; i = i + step) {
                 list.push(i + obj.unit)
-                if (defaultV==i+min){
+                if (defaultV == i + min) {
                     selects.push(i)
                 }
             }
             items.push(list)
-            
+
         })
-        debugger
         setPcikerValue(selects)
         setPickerItems(items)
     }, [])
@@ -119,7 +138,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
     }
 
     function finish() {
-        if (props.type != WorkoutType.normal) {
+        if (workout.item.schemas[0].values.length > 0) {
             setTempTime(new Date().getTime())
             clearInterval(timer)
             setShowModal(true)
@@ -172,7 +191,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
 
     function getValue(str, unit) {
         var i = str.indexOf(unit)
-        return str.substring(0, 1)
+        return str.substring(0, i)
     }
 
     function postData() {
@@ -256,11 +275,13 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
             ]
         }
         uploadWorkout(params).then(res => {
+            clearCache()
             dispatch(endSuccess())
             Taro.redirectTo({
-                url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(groups)
+                url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify((res as any).latest_record)
             })
             props.end()
+            global.refreshWorkout()
         }).catch(e => { })
 
     }
@@ -272,7 +293,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         }
         setNeedTerminal(true)
         setShowModal(true)
-        clearCache()
+
     }
 
     function terminal() {
@@ -282,10 +303,11 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
             content: '确认结束?',
             success: function (res) {
                 if (res.confirm) {
-                    if (props.type != WorkoutType.normal) {
+                    if (workout.item.schemas[0].values.length > 0) {
                         checkEnd()
                         return;
                     }
+
                     var array = groups;
                     var time = new Date().getTime()
                     array.push({
@@ -324,7 +346,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
             return;
         }
 
-
+        saveCache(array)
         setStartTime(tempTime)
         setGroups(array)
         resume()
@@ -360,8 +382,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
                 }
                 return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
                     <Text>{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
-                    {item.type == 'REST' && props.type == WorkoutType.number && <Text style={{ color: workout.item.theme_color }}>{item.value}</Text>}
-                    {item.type == 'REST' && props.type == WorkoutType.multi && <Text style={{ color: workout.item.theme_color }}>{item.value}x{item.value2}{item.value3?'x'+item.value3:''}</Text>}
+                    {item.type == 'REST' && <Text style={{ color: workout.item.theme_color }}>{item.value}{item.value2 ? 'x' + item.value2 : ''}{item.value3 ? 'x' + item.value3 : ''}</Text>}
                     <Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
                 </View>
             })

+ 39 - 27
src/pages/common/RecordsHistory.tsx

@@ -15,6 +15,8 @@ import RecordFastSleep from "@/features/trackTimeDuration/components/RecordFastS
 import './RecordsHistory.scss'
 import { useTranslation } from "react-i18next";
 import './RecordsHistory.scss'
+import { clearWorkoutRecords, workoutRecords } from "@/services/workout";
+import WorkoutHistory from "@/features/workout/WorkoutHistory";
 
 export default function Page() {
     const router = useRouter();
@@ -157,6 +159,26 @@ export default function Page() {
                 setIsLoading(false)
             })
         }
+        else if (router.params.type == 'workout') {
+            workoutRecords(
+                {
+                    page: page,
+                    limit: pageSize,
+                    code: router.params.code
+                }
+            ).then(res => {
+                Taro.stopPullDownRefresh()
+                setTriggered(false)
+                setLoaded(true)
+                setTotal((res as any).total)
+                if (page == 1) {
+                    setRecords((res as any).data)
+                } else {
+                    setRecords(records.concat((res as any).data))
+                }
+                setIsLoading(false)
+            })
+        }
 
     }
 
@@ -208,6 +230,16 @@ export default function Page() {
                 // Taro.getCurrentPages()[0].refresh()
             })
         }
+        else if (router.params.type == 'workout') {
+            clearWorkoutRecords({
+                code: router.params.code
+            }).then(res => {
+                refresh()
+                global.refreshTime()
+                // global.refreshMetric()
+                // Taro.getCurrentPages()[0].refresh()
+            })
+        }
     }
 
     function detail() {
@@ -232,6 +264,9 @@ export default function Page() {
         if (router.params.type == 'activity') {
             return <ActivityHistory records={records} />
         }
+        if (router.params.type == 'workout') {
+            return <WorkoutHistory records={records} />
+        }
     }
 
     function getTitle() {
@@ -241,18 +276,18 @@ export default function Page() {
         else if (router.params.type == 'metric') {
             return t('page.records_history.metric_title', { title: router.params.title })
         }
+        else if (router.params.type == 'workout') {
+            return t('page.records_history.metric_title', { title: router.params.title })
+        }
         else {
             return t('page.records_history.activity_title', { title: router.params.title })
         }
     }
 
     return <View style={{ position: 'relative' }}>
-        {/* <PageMeta pageStyle='overflow:hidden'>
-            <NavigationBar frontColor='#ffffff' backgroundColor="#000000"/>
-        </PageMeta> */}
         <Layout children={showErrorPage ? <NoData refresh={() => { refresh() }} /> : detail()}
             // title={router.params.title}
-            isFastSleepTheme={router.params.type=='time'}
+            isFastSleepTheme={router.params.type == 'time'}
             secondPage={true}
             titleColor={router.params.themeColor ? router.params.themeColor : '#fff'}
             title={getTitle()}
@@ -272,27 +307,4 @@ export default function Page() {
             showModal && modalDetail
         }
     </View>
-
-    // return <View className="container">
-
-    //     {
-    //         (router.params.type == 'metric' || router.params.type == 'activity') && <View style={{ height: 50, fontSize: 30, color: '#fff' }} onClick={clear}>删除全部</View>
-    //     }
-    //     <ScrollView scrollY style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
-    //         onScrollToLower={more} enableFlex
-    //     // onRefresh={refresh}
-    //     >
-    //         {
-    //             router.params.type == 'time' && records.map((item, index) => {
-    //                 return <Schedule key={index} data={item} type="record" delSuccess={(item) => removeItem(item)} />
-    //             })
-    //         }
-    //         {
-    //             router.params.type == 'metric' && <MetricHistory records={records} />
-    //         }
-    //         {
-    //             router.params.type == 'activity' && <ActivityHistory records={records} />
-    //         }
-    //     </ScrollView>
-    // </View>;
 }

+ 1 - 1
src/pages/workout/Working.tsx

@@ -12,7 +12,7 @@ export default function Page() {
             router.params.type == 'timer' && <WorkoutTimer />
         }
         {
-            router.params.type == 'stop_watch' && <WorkoutStopWatch targetCount={router.params.count} type={WorkoutType.multi} end={(e) => { }} />
+            router.params.type == 'stop_watch' && <WorkoutStopWatch targetCount={router.params.count??0} end={(e) => { }} />
         }
         {
             router.params.type == 'content' && <WorkoutContent />

+ 26 - 0
src/services/workout.tsx

@@ -61,4 +61,30 @@ export const uploadWorkout = (params) => {
 
         })
     })
+}
+
+export const clearWorkoutRecords = (params) => {
+    return new Promise((resolve) => {
+        request({
+            url: API_WORKOUT_RECORDS + '?code=' + params.code, method: 'DELETE', data: { ...params }
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        })
+    })
+
+
+}
+
+export const deleteWorkoutRecord = (params) => {
+    return new Promise((resolve) => {
+        request({
+            url: API_WORKOUT_RECORDS + '/' + params.id, method: 'DELETE', data: {}
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        })
+    })
+
+
 }

+ 3 - 0
src/store/workout.tsx

@@ -2,6 +2,7 @@ import { createSlice } from "@reduxjs/toolkit";
 
 interface WorkoutState {
     start: number;
+    duration:number;
     code: string;
     status: string;
     item:any;
@@ -9,6 +10,7 @@ interface WorkoutState {
 
 const initialState: WorkoutState = {
     start: 0,
+    duration:0,
     code: '0',
     status: 'idle',
     item:null
@@ -24,6 +26,7 @@ const worktoutSlice = createSlice({
         },
         startSuccess(state, action) {
             state.status = 'ing'
+            state.duration = action.payload.duration?action.payload.duration:0;
             state.start = action.payload.start;
             state.code = action.payload.code;
         },