Leon 2 rokov pred
rodič
commit
ad9da83e62

+ 1 - 1
src/features/trackSomething/components/Activity.tsx

@@ -21,7 +21,7 @@ import Modal from "@/components/layout/Modal";
 import MoveList from "./MoveList";
 import { ColorType } from "@/context/themes/color";
 import SetGoal from "@/features/workout/SetGoal";
-import Working from "@/features/workout/Working";
+import Working from "@/features/workout/WorkoutStopWatch";
 import { startSuccess } from "@/store/workout";
 import { workoutGroups } from "@/services/workout";
 // import { useNavigation } from "@react-navigation/native";

+ 1 - 0
src/features/trackSomething/components/Metric.tsx

@@ -248,6 +248,7 @@ export default function Component(props: any) {
     }
 
     function metricModalContent() {
+        debugger
         switch (modalType) {
             case MetricModalType.choose:
                 return <MetricModalChoose

+ 7 - 9
src/features/workout/Result.tsx

@@ -9,9 +9,10 @@ export default function Component(){
 
     useEffect(()=>{
         var  list = JSON.parse(router.params.detail  as any)
-        if (list[list.length-2].type=='end'){
-            list.splice(list.length-1,1)
-        }
+        // if (list.length>=2&&list[list.length-2].type=='REST'){
+        //     list.splice(list.length-1,1)
+        // }
+        // console.log(list)
         setHistories(list)
     },[])
 
@@ -42,13 +43,10 @@ export default function Component(){
 
         {
             histories.map((item, index) => {
-                if (index == 0) {
-                    return <View />
-                }
                 return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
-                    <Text>{item.type == 'end' ? `第${item.index}组` : '组间休息'}</Text>
-                    {item.type == 'end'  && <Text style={{ color: ColorType.workout }}>{item.value}x{item.value2}</Text>}
-                    <Text>{twoTimeDuration(histories[index - 1].time, item.time)}</Text>
+                    <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>
                 </View>
             })
         }

+ 6 - 0
src/features/workout/SetGoal.scss

@@ -0,0 +1,6 @@
+.set_goal_title{
+    font-size: 36px;
+    line-height: 48px;
+    font-weight: bold;
+    margin-bottom: 40px;
+}

+ 10 - 7
src/features/workout/SetGoal.tsx

@@ -5,9 +5,10 @@ import { ColorType } from "@/context/themes/color";
 import { View, Text } from "@tarojs/components";
 import { useState } from "react";
 import { ChooseScenarioBtn } from "../common/SpecBtns";
+import './SetGoal.scss'
 
-export default function Component(props: { start: Function,duration:number }) {
-    const [goalTime, setGoalTime] = useState(props.duration/1000)
+export default function Component(props: { start: Function, duration: number, themeColor: string }) {
+    const [goalTime, setGoalTime] = useState(props.duration / 1000)
     const [showPicker, setShowPicker] = useState(false)
     const [sportPickerValue, setSportPickerValue] = useState([14])
     function minus() {
@@ -80,16 +81,18 @@ export default function Component(props: { start: Function,duration:number }) {
         props.start(goalTime)
     }
 
-    return <View style={{ color: ColorType.workout }}>
-        <Text>设置训练时长</Text>
+    return <View style={{ color: props.themeColor,display:'flex',flexDirection:'column' }}>
+        <Text className="set_goal_title">设置训练时长</Text>
         <Stepper minus={minus} plus={plus}
-            themeColor={ColorType.workout}
+            themeColor={props.themeColor}
             disableMinus={disableMinus()}
             disablePlus={disablePlus()} >
-            <Text className="stepper_text" style={{ color: ColorType.workout, opacity: 1 }} onClick={showDurationPicker}>{durationFormate()}</Text>
+            <Text className="stepper_text" style={{ color: props.themeColor, opacity: 1 }} onClick={showDurationPicker}>{durationFormate()}</Text>
         </Stepper>
+        <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
+            <ChooseScenarioBtn onClick={start} title="开始计时" background={props.themeColor} />
+        </View>
 
-        <ChooseScenarioBtn onClick={start} title="开始计时" background={ColorType.workout} />
         {
             showPicker && <Modal dismiss={() => setShowPicker(false)} confirm={() => setShowPicker(false)}>
                 {

+ 69 - 14
src/features/workout/Workout.tsx

@@ -18,7 +18,7 @@ import TitleView from "@/features/trackTimeDuration/components/TitleView";
 import Modal from "@/components/layout/Modal";
 import { ColorType } from "@/context/themes/color";
 import SetGoal from "@/features/workout/SetGoal";
-import Working from "@/features/workout/Working";
+import Working from "@/features/workout/WorkoutStopWatch";
 import { setCurrentWorkoutItem, startSuccess } from "@/store/workout";
 import { workoutCards, workoutFollows, workoutGroups } from "@/services/workout";
 import { setAuth } from "../trackSomething/hooks/werun";
@@ -62,8 +62,8 @@ export default function Component(props: any) {
     const [orders, setOrders] = useState([])
     const [newOrders, setNewOrders] = useState([])
     const [resultOrders, setResultOrders] = useState([])
-
-    const [selItem,setSelItem] = useState(null)
+    const [themeColor, setThemeColor] = useState('#00ffff')
+    const [selItem, setSelItem] = useState(null)
 
     let navigation;
     if (useNavigation) {
@@ -122,7 +122,7 @@ export default function Component(props: any) {
                     var workoutObj = workouts[0]
                     dispatch(startSuccess({
                         start: workoutObj.time,
-                        id: 1
+                        code: workoutObj.code,
                     }));
 
                     timer = setInterval(() => {
@@ -154,6 +154,24 @@ export default function Component(props: any) {
                 }
             }
             setLoaded(true)
+
+            if ((res as any).cards.length > 0) {
+                var obj = (res as any).cards[0]
+                setThemeColor(obj.theme_color)
+            }
+
+            var list: any = [];
+            (res as any).cards.map(item => {
+                list.push({
+                    name: item.name,
+                    code: item.code,
+                    is_following: true
+                })
+            })
+            setOrders(list)
+            setResultOrders(list)
+
+
         }).catch(e => {
             setTriggered(false)
             if (list.length == 0) {
@@ -162,10 +180,10 @@ export default function Component(props: any) {
             setLoaded(true)
         })
 
-        
+
     }
 
-    function getGroups(){
+    function getGroups() {
         workoutGroups().then(res => {
             var array = (res as any).groups
             setOrignalGroups(JSON.parse(JSON.stringify(array)))
@@ -202,7 +220,7 @@ export default function Component(props: any) {
 
     function tapBtn(item) {
         if (user.isLogin) {
-            if (item.code!='_walk'){
+            if (item.code != '_walk') {
                 setSelItem(item)
                 dispatch(setCurrentWorkoutItem(item))
                 workoutStart()
@@ -220,6 +238,10 @@ export default function Component(props: any) {
         }
     }
 
+    function timeStart() {
+        Taro.navigateTo({ url: '/pages/workout/Working?type=timer' })
+    }
+
     function successAuth() {
         Taro.setStorage({ key: 'auth', data: true })
         setAllowRun(true)
@@ -486,13 +508,23 @@ export default function Component(props: any) {
                         }
                     }
 
+                    var strTitle = btnTitle;
+                    if (item.code != '_walk') {
+                        isEnable = true
+                        strTitle = '计时训练'
+
+                        if (item.code == workout.code && workout.status == 'ing') {
+                            strTitle = TimeFormatter.formateTimeNow(workout.start)
+                        }
+                    }
+
 
                     return <MetricItem title={item.name}
                         // value={allowRun ? stepInfo ? (stepInfo as any).step : '' : '未开启'}
                         value={value}
                         unit={unit}
                         desc={desc}
-                        btnText={btnTitle}
+                        btnText={strTitle}
                         isDisabled={!isEnable}
                         themeColor={item.theme_color}
                         onClickDetail={() => { goDetail(item) }}
@@ -505,6 +537,26 @@ export default function Component(props: any) {
                 })
             }
 
+            <MetricItem title='TABATA'
+                // value={allowRun ? stepInfo ? (stepInfo as any).step : '' : '未开启'}
+                value={10}
+                unit={''}
+                desc={'total time'}
+                btnText={'开始计时'}
+                isDisabled={false}
+                themeColor={themeColor}
+                onClickDetail={() => {
+                    // Taro.navigateTo({
+                    //     url: '/pages/workout/History'
+                    // })
+                }}
+                showBadge={showErrorBadge && checkResult.type == 'idle'}
+                showDetail={false}
+                onClick={() => {
+                    timeStart()
+                }}
+            />
+
             {/* <MetricItem title='平板支撑'
                 // value={allowRun ? stepInfo ? (stepInfo as any).step : '' : '未开启'}
                 value={10}
@@ -512,7 +564,7 @@ export default function Component(props: any) {
                 desc={'昨天'}
                 btnText={'计时训练'}
                 isDisabled={false}
-                themeColor={ColorType.workout}
+                themeColor={themeColor}
                 onClickDetail={() => {
                     Taro.navigateTo({
                         url: '/pages/workout/History'
@@ -568,7 +620,7 @@ export default function Component(props: any) {
         switch (modalType) {
             case MetricModalType.choose:
                 return <MetricModalChoose
-                    themeColor={ColorType.workout}
+                    themeColor={themeColor}
                     cancel={modalCancel}
                     confirm={modalConfirm}
                     array={groups}
@@ -578,7 +630,7 @@ export default function Component(props: any) {
                 />
             case MetricModalType.order:
                 return <MetricModalOrder
-                    themeColor={ColorType.workout}
+                    themeColor={themeColor}
                     cancel={modalOrderCancel}
                     confirm={modalOrderConfirm}
                     array={resultOrders} />
@@ -588,7 +640,6 @@ export default function Component(props: any) {
 
     function onPageContainerCancel() {
         if (modalType == MetricModalType.choose || modalType == MetricModalType.order) {
-            debugger
             var array: any = [];
             list.map(item => {
                 array.push({
@@ -597,7 +648,6 @@ export default function Component(props: any) {
                     is_following: true
                 })
             })
-            // debugger
             setOrders(array)
             setNewOrders([])
             setGroups(JSON.parse(JSON.stringify(orignalGroups)))
@@ -622,7 +672,12 @@ export default function Component(props: any) {
                 setShowModal(false)
             }} confirm={() => { }} modalType={ModalType.center}>
                 {
-                    !isStart && <SetGoal duration={(selItem as any).schemas[0].default_duration} start={(count) => { setTargetTime(count); setShowModal(false); Taro.navigateTo({ url: '/pages/workout/Working?count=' + count }) }} />
+                    !isStart && <SetGoal duration={(selItem as any).schemas[0].default_duration} themeColor={themeColor}
+                        start={(count) => {
+                            setTargetTime(count);
+                            setShowModal(false);
+                            Taro.navigateTo({ url: '/pages/workout/Working?type=stop_watch&count=' + count })
+                        }} />
                 }
                 {
                     isStart && <Working targetCount={targetTime} type={WorkoutType.multi} end={() => {

+ 5 - 0
src/features/workout/WorkoutContent.tsx

@@ -0,0 +1,5 @@
+import { View } from "@tarojs/components";
+
+export default function Component(){
+    return  <View></View>
+}

+ 41 - 0
src/features/workout/WorkoutStopWatch.scss

@@ -0,0 +1,41 @@
+.working_title {
+    font-size: 48px;
+    line-height: 48px;
+    font-weight: bold;
+    margin-left: 32px;
+}
+
+.working_subtitle {
+    color: #fff;
+    font-size: 32px;
+    line-height: 32px;
+    margin-top: 20px;
+    margin-left: 32px;
+    margin-bottom: 36px;
+}
+
+.working_index{
+    font-size: 34px;
+    line-height: 40px;
+    color: #fff;
+}
+
+.working_duration{
+    margin-top: 36px;
+    font-size: 72px;
+    line-height: 72px;
+    color: #fff;
+    font-weight: bold;
+    width: 100%;
+    text-align: center;
+    margin-bottom: 58px;
+}
+
+.working_end{
+    color: #FA5151;
+    width: 100%;
+    text-align: center;
+    font-size: 32px;
+    line-height: 40px;
+    margin-top: 40px;
+}

+ 167 - 59
src/features/workout/Working.tsx → src/features/workout/WorkoutStopWatch.tsx

@@ -8,7 +8,10 @@ import { WorkoutType } from "@/utils/types";
 import Modal from "@/components/layout/Modal";
 import PickerViews from "@/components/input/PickerViews";
 import { useDispatch, useSelector } from "react-redux";
-import { startSuccess } from "@/store/workout";
+import { endSuccess, startSuccess } from "@/store/workout";
+import { uploadWorkout } from "@/services/workout";
+import './WorkoutStopWatch.scss'
+import Box from "@/components/layout/Box";
 
 
 var timer
@@ -27,23 +30,45 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
     const [isPaused, setIsPaused] = useState(false);
     const dispatch = useDispatch();
 
-    const items = [[1, 2, 3, 4, 5, 6]]
-    const [selIndex, setSelIndex] = useState([1])
-    const multiItems = [[10, 20, 30, 40], [1, 2, 3, 4, 5]]
-    const multiSel = [1, 1]
+    const [pickerItems, setPickerItems] = useState<any[]>([])
+    const [pickerValue, setPcikerValue] = useState<any[]>([])
 
     useEffect(() => {
         var array = [{
+            code: workout.item.code,
             index: index,
             time: startTime,
-            type: 'start'
+            type: 'GROUP'
         }]
         setGroups(array)
         saveCache(array)
         dispatch(startSuccess({
             start: startTime,
-            id: 1
+            code: workout.item.code,
         }))
+
+
+        var item = workout.item
+        var items: any = []
+        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 defaultV = parseInt(obj.default_value)
+            for (var i = min; i <= max; i = i + step) {
+                list.push(i + obj.unit)
+                if (defaultV==i+min){
+                    selects.push(i)
+                }
+            }
+            items.push(list)
+            
+        })
+        debugger
+        setPcikerValue(selects)
+        setPickerItems(items)
     }, [])
 
     useEffect(() => {
@@ -103,9 +128,10 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         var array = groups;
         var time = new Date().getTime()
         array.push({
+            code: workout.item.code,
             index: index,
             time: time,
-            type: 'end'
+            type: 'REST'
         })
         setIsDoing(false)
         setStartTime(time)
@@ -117,9 +143,10 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         var array = groups;
         var time = new Date().getTime()
         array.push({
+            code: workout.item.code,
             index: index + 1,
             time: time,
-            type: 'start'
+            type: 'GROUP'
         })
         setStartTime(time)
         setIndex(index + 1)
@@ -139,12 +166,108 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         Taro.removeStorage({ key: 'lastWorkout' })
     }
 
-    function checkEnd() {
-        if (groups[groups.length - 1].type == 'end') {
+    function formateDate(date) {
+        return (date.getFullYear() + '') + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
+    }
+
+    function getValue(str, unit) {
+        var i = str.indexOf(unit)
+        return str.substring(0, 1)
+    }
+
+    function postData() {
+        var date = new Date()
+        var strDate = formateDate(date)
+
+        var records: any = []
+
+        for (var i = 0; i < groups.length; i++) {
+            var obj = groups[i]
+            if (obj.type == 'GROUP') {
+                obj.start = obj.time
+                obj.end = groups[i + 1].time
+                obj.value = groups[i + 1].value
+                obj.value2 = groups[i + 1].value2
+                obj.value3 = groups[i + 1].value3
+            }
+            else {
+                if (i != groups.length - 1) {
+                    obj.start = obj.time
+                    obj.end = groups[i + 1].time
+                }
+
+            }
+        }
+
+        for (var i = groups.length - 1; i >= 0; i--) {
+            var obj = groups[i]
+            if (obj.type == 'REST') {
+                groups.splice(i, 1)
+            }
+            else {
+                break;
+            }
+        }
+
+        var units = workout.item.schemas[0].values
+        for (var i = 0; i < groups.length; i++) {
+            var obj = groups[i]
+            var values: any = []
+            if (obj.type == 'GROUP') {
+                values.push({
+                    value: getValue(obj.value, units[0].unit)
+                })
+                if (obj.value2) {
+                    values.push({
+                        value: getValue(obj.value2, units[1].unit)
+                    })
+                }
+                if (obj.value3) {
+                    values.push({
+                        value: getValue(obj.value3, units[2].unit)
+                    })
+                }
+            }
+
+
+            records.push({
+                type: obj.type,
+                start: {
+                    date: formateDate(new Date(obj.start)),
+                    timestamp: obj.start
+                },
+                end: {
+                    date: formateDate(new Date(obj.end)),
+                    timestamp: obj.end
+                },
+                values: values
+            })
+        }
+
+        var params = {
+            date: strDate,
+            timestamp: date.getTime(),
+            code: workout.item.code,
+            items: [
+                {
+                    code: workout.item.code,
+                    groups: records
+                }
+            ]
+        }
+        uploadWorkout(params).then(res => {
+            dispatch(endSuccess())
             Taro.redirectTo({
                 url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(groups)
             })
             props.end()
+        }).catch(e => { })
+
+    }
+
+    function checkEnd() {
+        if (groups[groups.length - 1].type == 'REST') {
+            postData()
             return
         }
         setNeedTerminal(true)
@@ -168,15 +291,12 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
                     array.push({
                         index: index,
                         time: time,
-                        type: 'end'
+                        type: 'REST'
                     })
                     setIsDoing(false)
                     setGroups(array)
 
-                    Taro.redirectTo({
-                        url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(array)
-                    })
-                    props.end()
+                    postData()
                 } else if (res.cancel) {
                     resume()
                     console.log('用户点击取消')
@@ -193,16 +313,14 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         array.push({
             index: index,
             time: tempTime,
-            value: e.length > 0 ? multiItems[0][e[0]] : items[e[0]],
-            value2: e.length > 0 ? multiItems[1][e[1]] : null,
-            type: 'end'
+            value: e.length > 0 ? pickerItems[0][e[0]] : pickerItems[e[0]],
+            value2: e.length > 1 ? pickerItems[1][e[1]] : null,
+            value3: e.length > 2 ? pickerItems[2][e[2]] : null,
+            type: 'REST'
         })
         setIsDoing(false)
         if (needTerminal) {
-            Taro.redirectTo({
-                url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(groups)
-            })
-            props.end()
+            postData()
             return;
         }
 
@@ -213,26 +331,15 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
     }
 
     function pickerContent() {
-        var item = workout.item
-        console.log(item)
-        var color = ColorType.workout
+        var color = workout.item.theme_color
         var title = '本组训练'
 
-        var items:any = []
-        var selects:any=[]
-        item.schemas[0].values.map(obj=>{
-            var list:any = []
-            for (var i=obj.min;i<=obj.max;i=i+obj.step){
-                list.push(i+obj.unit)
-            }
-            items.push(list)
-            selects.push(0)
-        })
+
         return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
             <PickerViews
                 onChange={numChange}
-                items={items}
-                value={selects}
+                items={pickerItems}
+                value={pickerValue}
                 themeColor={color}
                 title={title}
                 showBtns={true}
@@ -243,37 +350,38 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
         </View>
     }
 
-    return <View style={{ color: ColorType.workout, flexDirection: 'column', display: 'flex' }}>
-        <Text>平板支撑</Text>
-        <Text>计时训练</Text>
+    return <View style={{ color: workout.item.theme_color, flexDirection: 'column', display: 'flex' }}>
+        <Text className="working_title">{workout.item.name}</Text>
+        <Text className="working_subtitle">计时训练</Text>
         {
             groups.length > 1 && groups.map((item, index) => {
                 if (index == 0) {
                     return <View />
                 }
                 return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
-                    <Text>{item.type == 'end' ? `第${item.index}组` : '组间休息'}</Text>
-                    {item.type == 'end' && props.type == WorkoutType.number && <Text style={{ color: ColorType.workout }}>{item.value}</Text>}
-                    {item.type == 'end' && props.type == WorkoutType.multi && <Text style={{ color: ColorType.workout }}>{item.value}x{item.value2}个</Text>}
+                    <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>}
                     <Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
                 </View>
             })
         }
-        {
-            isDoing && <View style={{ display: 'flex', flexDirection: 'column' }}>
-                <Text>第{index}组</Text>
-                <Text>{durationTime()}</Text>
-                <ChooseScenarioBtn onClick={finish} title="完成本组" background={ColorType.workout} />
-            </View>
-        }
-        {
-            !isDoing && <View style={{ display: 'flex', flexDirection: 'column' }}>
-                <Text>组间休息</Text>
-                <Text>{durationTime()}</Text>
-                <ChooseScenarioBtn onClick={start} title="开始下一组" background={ColorType.workout} />
-            </View>
-        }
-        <Text style={{ color: 'red' }} onClick={terminal}>结束训练</Text>
+        <Box>
+            {
+                isDoing ? <View style={{ display: 'flex', flexDirection: 'column' }}>
+                    <Text className="working_index">第{index}组</Text>
+                    <Text className="working_duration">{durationTime()}</Text>
+                    <ChooseScenarioBtn onClick={finish} title="完成本组" background={workout.item.theme_color} />
+                </View> :
+                    <View style={{ display: 'flex', flexDirection: 'column' }}>
+                        <Text className="working_index">组间休息</Text>
+                        <Text className="working_duration">{durationTime()}</Text>
+                        <ChooseScenarioBtn onClick={start} title="开始下一组" background={workout.item.theme_color} />
+                    </View>
+            }
+        </Box>
+
+        <Text className="working_end" onClick={terminal}>结束训练</Text>
         <View style={{ height: 50 }} />
         <Text>总用时</Text>
         <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%' }}>

+ 129 - 0
src/features/workout/WorkoutTimer.tsx

@@ -0,0 +1,129 @@
+import { View, Text } from "@tarojs/components";
+import './WorkoutStopWatch.scss'
+import { useEffect, useState } from "react";
+import Box from "@/components/layout/Box";
+import { ChooseScenarioBtn } from "../common/SpecBtns";
+import { ColorType } from "@/context/themes/color";
+
+var timer
+export default function Component() {
+    const schedules = [{
+        type: 'group',
+        time: 5,
+        index: 1,
+    }, {
+        type: 'rest',
+        time: 5,
+    }, {
+        type: 'group',
+        time: 3,
+        index: 2
+    }, {
+        type: 'rest',
+        time: 2,
+    }, {
+        type: 'group',
+        time: 5,
+        index: 3
+    }, {
+        type: 'group',
+        time: 2,
+        index: 4
+    }, {
+        type: 'group',
+        time: 3,
+        index: 5
+    }]
+    const [current, setCurrent] = useState(0)
+    const [isDoing, setIsDoing] = useState(false)
+    const [records, setRecords] = useState<any>([])
+    const [countdown, setCountdown] = useState('')
+
+    const [count, setCount] = useState(0)
+
+    useEffect(() => {
+        if (records.length == 0) {
+            return
+        }
+        var record = records[records.length - 1]
+        record.count += 1
+        if (record.count == schedules[current].time) {
+            if (current == schedules.length - 1) {
+                clearInterval(timer)
+                setCountdown('00:00:00')
+                return
+            }
+            setCurrent(current + 1)
+            records.push({
+                start: new Date().getTime(),
+                count: 0
+            })
+            setRecords(records)
+        }
+        countdownText()
+        // console.log(count)
+        // console.log(record)
+    }, [count])
+
+
+    function start() {
+        setIsDoing(true)
+        setRecords([{
+            start: new Date().getTime(),
+            count: 0
+        }])
+        timer = setInterval(() => {
+            setCount(count => count + 1)
+        }, 1000)
+    }
+
+    function pause() {
+
+    }
+
+    function resmue() {
+
+    }
+
+    function terminal() {
+
+    }
+
+    function countdownText() {
+        var count = 0
+        var index = current
+        if (records.length > 0) {
+            count = records[records.length - 1].count
+            if (count == 0 && records.length > 1) {
+                count = records[records.length - 2].count
+                // index -= 1
+            }
+        }
+        var left = schedules[index].time - count
+
+
+        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) + ''
+        setCountdown(str)
+        // console.log(left,str)
+        // return str
+    }
+
+    return <View style={{ display: 'flex', flexDirection: 'column', color: '#fff' }}>
+        <Box>
+            <View style={{ display: 'flex', flexDirection: 'column' }}>
+                <Text>第{current + 1}组</Text>
+                <Text className="working_duration">{countdown}</Text>
+                {!isDoing && <ChooseScenarioBtn onClick={start} title="开始" background={ColorType.workout} />}
+            </View>
+        </Box>
+        <Text className="working_end" onClick={terminal}>结束训练</Text>
+    </View>
+}

+ 14 - 3
src/pages/workout/Working.tsx

@@ -1,11 +1,22 @@
-import Working from "@/features/workout/Working";
+import WorkoutContent from "@/features/workout/WorkoutContent";
+import WorkoutStopWatch from "@/features/workout/WorkoutStopWatch";
+import WorkoutTimer from "@/features/workout/WorkoutTimer";
 import { WorkoutType } from "@/utils/types";
 import { View } from "@tarojs/components";
 import { useRouter } from "@tarojs/taro";
 
-export default function Page(){
+export default function Page() {
     const router = useRouter();
     return <View>
-        <Working targetCount={router.params.count} type={WorkoutType.multi} end={(e)=>{}}/>
+        {
+            router.params.type == 'timer' && <WorkoutTimer />
+        }
+        {
+            router.params.type == 'stop_watch' && <WorkoutStopWatch targetCount={router.params.count} type={WorkoutType.multi} end={(e) => { }} />
+        }
+        {
+            router.params.type == 'content' && <WorkoutContent />
+        }
+
     </View>
 }

+ 17 - 2
src/services/workout.tsx

@@ -2,7 +2,7 @@ import { API_WORKOUT_CARDS, API_WORKOUT_FOLLOWS, API_WORKOUT_GROUPS, API_WORKOUT
 import { request } from "./http/request";
 
 
-export const workoutGroups = ()=>{
+export const workoutGroups = () => {
     return new Promise((resolve) => {
         request({
             url: API_WORKOUT_GROUPS, method: 'GET', data: {}
@@ -13,7 +13,7 @@ export const workoutGroups = ()=>{
     })
 }
 
-export const workoutFollows= (params) => {
+export const workoutFollows = (params) => {
     return new Promise((resolve) => {
         request({
             url: API_WORKOUT_FOLLOWS, method: 'POST', data: { ...params }
@@ -46,4 +46,19 @@ export const workoutRecords = (params) => {
             // dispatch(loginSuccess(res));
         })
     })
+}
+
+export const uploadWorkout = (params) => {
+    return new Promise((resolve, reject) => {
+        request({
+            url: API_WORKOUT_RECORDS, method: 'POST', data: { ...params }
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        }).catch(err => {
+            reject(err)
+            global.postBtnUpdateStatus('idle')
+
+        })
+    })
 }

+ 3 - 3
src/store/workout.tsx

@@ -2,14 +2,14 @@ import { createSlice } from "@reduxjs/toolkit";
 
 interface WorkoutState {
     start: number;
-    id: number;
+    code: string;
     status: string;
     item:any;
 }
 
 const initialState: WorkoutState = {
     start: 0,
-    id: 0,
+    code: '0',
     status: 'idle',
     item:null
 }
@@ -25,7 +25,7 @@ const worktoutSlice = createSlice({
         startSuccess(state, action) {
             state.status = 'ing'
             state.start = action.payload.start;
-            state.id = action.payload.id;
+            state.code = action.payload.code;
         },
 
         endSuccess(state) {