Leon 2 éve
szülő
commit
ad28e297fc

+ 18 - 6
src/components/basic/Buttons.tsx

@@ -31,7 +31,8 @@ export default function Buttons(props: {
     openType?: string,
     btnStyle?: any,
     showLoading?: boolean,
-    lightLoading?: boolean
+    lightLoading?: boolean,
+    longClick?: Function
 }) {
 
     function onClick(e) {
@@ -43,13 +44,23 @@ export default function Buttons(props: {
         props.onClick()
     }
 
+    function onLongClick(e) {
+        if (process.env.TARO_ENV == 'weapp') {
+            e.stopPropagation()
+        }
+        if (props.disabled) return
+        if (props.longClick) {
+            props.longClick()
+        }
+    }
+
 
     var mainClass = 'elevated'
     var textClass = 'elevated_text'
 
     if (props.type == ButtonType.text) {
         mainClass = 'texted'
-        return <View style={{ opacity: (props.lowLight || props.disabled) ? 0.4 : 1 }} onClick={onClick}>
+        return <View style={{ opacity: (props.lowLight || props.disabled) ? 0.4 : 1 }} onClick={onClick} onLongPress={onLongClick}>
             <Text
                 style={{
                     ...props.btnStyle,
@@ -63,7 +74,7 @@ export default function Buttons(props: {
         textClass = 'outlined_text'
 
         return (
-            <View className={mainClass} style={{ ...props.btnStyle, opacity: props.lowLight ? 0.4 : 1 }} onClick={onClick}>
+            <View className={mainClass} style={{ ...props.btnStyle, opacity: props.lowLight ? 0.4 : 1 }} onClick={onClick} onLongPress={onLongClick}>
                 {
                     props.showLoading && <View style={{ marginBottom: 2, marginRight: 5 }}>
                         <AtActivityIndicator size={32} color={props.btnStyle.color} />
@@ -80,10 +91,11 @@ export default function Buttons(props: {
             </View>
         )
     }
-
-    
     return (
-        <View className={mainClass} style={{ ...props.btnStyle, opacity: (props.lowLight || props.disabled) ? 0.4 : 1 }} onClick={onClick}>
+        <View className={mainClass}
+            style={{ ...props.btnStyle, opacity: (props.lowLight || props.disabled) ? 0.4 : 1 }}
+            onClick={onClick}
+            onLongPress={onLongClick}>
             {
                 props.showLoading && <View style={{ marginBottom: 2, marginRight: 5 }}>
                     <AtActivityIndicator size={32} color={props.lightLoading ? '#999' : '#000'} />

+ 3 - 1
src/features/common/PostBtn.tsx

@@ -9,7 +9,8 @@ export default function Component(props: {
     lowLight?: boolean,
     title: string,
     btnStyle: any,
-    lightLoading?: boolean
+    lightLoading?: boolean,
+    longClick?:Function
 }) {
     //idle normal abnormal
     const [btnStatus, setBtnStatus] = useState('idle')
@@ -61,6 +62,7 @@ export default function Component(props: {
                 showLoading={btnStatus == 'abnormal'}
                 btnStyle={props.btnStyle}
                 lightLoading={props.lightLoading}
+                longClick={props.longClick}
             />
         </View>
     )

+ 4 - 2
src/features/common/SpecBtns.tsx

@@ -139,10 +139,11 @@ export const SetScheduleBtn = (props: { onClick: Function, title: string, isFast
     )
 }
 
-export const ChooseScenarioBtn = (props: { onClick: Function, title: string, background: string, disable?: boolean }) => {
+export const ChooseScenarioBtn = (props: { onClick: Function, title: string, background: string, disable?: boolean,longClick?:Function }) => {
     return (
         <Buttons title={props.title} type={ButtonType.elevated}
             onClick={() => { props.onClick() }}
+            longClick={props.longClick}
             disabled={props.disable}
             btnStyle={{
                 height: 50,
@@ -163,11 +164,12 @@ export const ChooseScenarioBtn = (props: { onClick: Function, title: string, bac
     )
 }
 
-export const RecordMetricBtn = (props: { onClick: Function, title: string, themeColor: string, isDisable?: boolean }) => {
+export const RecordMetricBtn = (props: { onClick: Function, title: string, themeColor: string, isDisable?: boolean,longClick?:Function }) => {
     return (
         <PostBtn title={props.title} type={ButtonType.elevated}
             onClick={() => { props.onClick() }}
             lowLight={props.isDisable}
+            longClick={props.longClick}
             btnStyle={{
                 height: 42,
                 // width: 100,

+ 23 - 7
src/features/trackSomething/components/MetricItem.tsx

@@ -1,4 +1,4 @@
-import { View, Text,Image } from "@tarojs/components";
+import { View, Text, Image } from "@tarojs/components";
 import './MetricItem.scss'
 import { RecordMetricBtn } from "@/features/common/SpecBtns";
 
@@ -13,9 +13,10 @@ export default function Component(props: {
     onClickDetail: Function,
     onClick: Function,
     showBadge?: boolean,
-    showDetail?:boolean
+    showDetail?: boolean,
+    longClick?: Function,
 }) {
-    
+
     function clickBtn() {
         if (props.isDisabled) {
             return
@@ -23,6 +24,16 @@ export default function Component(props: {
         props.onClick()
     }
 
+    function longClickBtn() {
+        if (props.isDisabled) {
+            return;
+        }
+        if (props.longClick) {
+            props.longClick()
+        }
+
+    }
+
     return <View className="metric_bg">
         <Text className="metric_title" style={{ color: props.themeColor }} onClick={() => props.onClickDetail()}>{props.title}</Text>
         <View className="metric_value_bg" onClick={() => props.onClickDetail()}>
@@ -31,12 +42,17 @@ export default function Component(props: {
         <View className="metric_desc_bg" onClick={() => props.onClickDetail()}>
             <Text className="mteric_desc">{props.desc}</Text>
             {
-                props.showDetail && <Image src={require('@assets/images/arrow3.png')} className="metric_arrow"/>
+                props.showDetail && <Image src={require('@assets/images/arrow3.png')} className="metric_arrow" />
             }
-            
+
         </View>
-        <View style={{ position: 'relative',marginTop:10 }} >
-            <RecordMetricBtn themeColor={props.themeColor} title={props.btnText} onClick={clickBtn} isDisable={props.isDisabled}/>
+        <View style={{ position: 'relative', marginTop: 10 }} >
+            <RecordMetricBtn themeColor={props.themeColor}
+                title={props.btnText}
+                onClick={clickBtn}
+                isDisable={props.isDisabled}
+                longClick={longClickBtn}
+            />
             {
                 props.showBadge && <View className="badge"></View>
             }

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

@@ -166,7 +166,7 @@ export default function Component(props: {
                                         <Text className='modal_item_text' style={{ color: color, marginLeft: 10 }}>{obj.name}</Text>
                                         <View style={{ flex: 1 }} />
                                         {
-                                            user.test_user && <Text>{obj.is_following ? codeIndex(obj.code) : ''}</Text>
+                                            user.test_user && <Text style={{color:'#fff'}}>{obj.is_following ? codeIndex(obj.code) : ''}</Text>
                                         }
                                         {
                                             user.test_user && <Text style={{ color: 'green' }}>{obj.is_following ? codeNewIndex(obj.code) : ''}</Text>

+ 47 - 13
src/features/workout/Result.tsx

@@ -24,7 +24,8 @@ export default function Component() {
     }, [])
 
     function twoTimeDuration(start, end) {
-        var time = Math.round((end - start) / 1000);
+        var time = Math.floor((end - start) / 1000);
+        time = time<1?1:time
         const hours = Math.floor(time / 3600);
         const minutes = Math.floor((time % 3600) / 60);
         const seconds = Math.floor(time % 60);
@@ -38,13 +39,13 @@ export default function Component() {
         if (seconds > 0) {
             strDuration += `${seconds}秒`
         }
-        return strDuration.length == 0 ? '1秒' : strDuration
+        return strDuration
     }
 
     function getCount() {
         var count = 0
         histories.map(item => {
-            if (item.type == 'GROUP') {
+            if (item.type == 'WORK') {
                 count++
             }
         })
@@ -55,17 +56,18 @@ export default function Component() {
     function getIndex(index) {
         var count = 0
         for (var i = 0; i <= index; i++) {
-            if (histories[i].type == 'GROUP') {
+            if (histories[i].type == 'WORK') {
                 count++
             }
         }
         return count;
     }
 
-    function getValue(item) {
+    function getValue_backup(item) {
         var list = item.values
-        if ((record as any).items[0].log_type == 'TIME_SECONDS') {
-            return list[0].value+'小时'+list[1].value+'分钟'+list[2].value+'秒'
+        if ((record as any).items[0].format == 'TIME_SECONDS') {
+            return ''
+            // return list[0].value+'小时'+list[1].value+'分钟'+list[2].value+'秒'
         }
         
         var count = 1
@@ -78,6 +80,29 @@ export default function Component() {
         return result.substring(0, result.length - 1)
     }
 
+    function getValue(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  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 = ''
+        // 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'),
@@ -105,7 +130,7 @@ export default function Component() {
         if (!(record as any).items[0].summary_stats || (record as any).items[0].summary_stats.length==0){
             return ''
         }
-        if ((record as any).items[0].log_type == 'TIME_SECONDS') {
+        if ((record as any).items[0].format == 'TIME_SECONDS') {
             var time = (record as any).items[0].summary_stats[0].value
             const hours = Math.floor(time / 3600);
             const minutes = Math.floor((time % 3600) / 60);
@@ -125,7 +150,7 @@ export default function Component() {
         return (record as any).items[0].summary_stats[0].value+(record as any).items[0].summary_stats[0].unit
         // var count = 0
         // histories.map(item=>{
-        //     if (item.type=='GROUP'){
+        //     if (item.type=='WORK'){
         //         count += parseInt(item.values[0].value)
         //     }
         // })
@@ -134,7 +159,16 @@ export default function Component() {
 
     function getRealDuration(){
         if (!record) return ''
-        var seconds = Math.round((histories[histories.length-1].end.timestamp-histories[0].start.timestamp)/1000)
+
+        var seconds = 0
+        histories.map(item=>{
+            var time = Math.floor((item.end.timestamp - item.start.timestamp) / 1000);
+            if (time<1){
+                time = 1
+            }
+            seconds+=time
+        })
+        // var seconds = Math.floor((histories[histories.length-1].end.timestamp-histories[0].start.timestamp)/1000)
         return TimeFormatter.workoutTime(seconds)
     }
 
@@ -176,9 +210,9 @@ export default function Component() {
 
         {
             histories.map((item, index) => {
-                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: router.params.themeColor }}>{getValue(item)}</Text>}
+                return <View key={index} className={item.typ == 'WORK' ? 'result_item' : 'result_item result_item_rest'}>
+                    <Text>{item.type == 'WORK' ? `第${getIndex(index)}组` : '组间休息'}</Text>
+                    {item.type == 'WORK' && <Text style={{ color: router.params.themeColor }}>{getValue(item)}</Text>}
                     <Text className="result_time">{twoTimeDuration(item.start.timestamp, item.end.timestamp)}</Text>
                 </View>
             })

+ 44 - 10
src/features/workout/Workout.tsx

@@ -495,7 +495,7 @@ export default function Component(props: any) {
     }
 
     function detail() {
-        return <View className="activity_container">
+        return <View className="activity_container" style={{ marginBottom: 50 }}>
             {
                 list.map((item: any, index) => {
                     var value = '0'
@@ -564,20 +564,20 @@ export default function Component(props: any) {
                             else {
                                 unit = ''
                                 if (item.latest_record.items[0].summary_stats) {
-                                    if (item.latest_record.items[0].log_type == 'TIME_SECONDS') {
+                                    if (item.latest_record.items[0].format == 'TIME_SECONDS') {
                                         var time = item.latest_record.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 (hours > 0) {
+                                            str = str + hours + '小时'
                                         }
-                                        if (minutes>0){
-                                            str = str+minutes+'分钟'
+                                        if (minutes > 0) {
+                                            str = str + minutes + '分钟'
                                         }
-                                        if(seconds>0){
-                                            str = str+seconds+'秒'
+                                        if (seconds > 0) {
+                                            str = str + seconds + '秒'
                                         }
                                         value = str
                                     }
@@ -603,6 +603,24 @@ export default function Component(props: any) {
                         onClickDetail={() => { goDetail(item) }}
                         showBadge={showErrorBadge && checkResult.type == 'idle'}
                         showDetail={showDetail}
+                        longClick={() => {
+
+                            if (item.code != '_walk' && user.isLogin) {
+                                Taro.showActionSheet({
+                                    itemList: ['content only mode'],
+                                }).then(res => {
+                                    switch (res.tapIndex) {
+                                        case 0:
+                                            setSelItem(item)
+                                            dispatch(setCurrentWorkoutItem(item))
+                                            Taro.navigateTo({ url: '/pages/workout/Working?count=0&type=stop_watch&content_only=true' })
+                                            break
+                                    }
+                                })
+                            }
+
+                            // console.log('long press')
+                        }}
                         onClick={() => {
                             tapBtn(item)
                         }}
@@ -610,8 +628,8 @@ export default function Component(props: any) {
                 })
             }
 
-            {/* <MetricItem title='TABATA'
-                value={10}
+            <MetricItem title='TABATA'
+                value={'wait'}
                 unit={''}
                 desc={'total time'}
                 btnText={'开始计时'}
@@ -624,6 +642,22 @@ export default function Component(props: any) {
                 onClick={() => {
                     timeStart()
                 }}
+            />
+
+            {/* <MetricItem title='Content only'
+                value={'wait'}
+                unit={''}
+                desc={'content only'}
+                btnText={'开始使用'}
+                isDisabled={false}
+                themeColor={themeColor}
+                onClickDetail={() => {
+                }}
+                showBadge={showErrorBadge && checkResult.type == 'idle'}
+                showDetail={false}
+                onClick={() => {
+                    timeStart()
+                }}
             /> */}
 
             {

+ 73 - 33
src/features/workout/WorkoutHistory.tsx

@@ -7,7 +7,7 @@ import { TimeFormatter } from "@/utils/time_format";
 import './WorkoutHistory.scss';
 import Taro, { useRouter } from "@tarojs/taro";
 
-export default function Component(props: { records: any, count: number }) {
+export default function Component(props: { records: any, count: number,summary_stats:any }) {
     const user = useSelector((state: any) => state.user);
     const [list, setList] = useState(props.records)
     const [selRecord, setSelRecord] = useState(null)
@@ -34,22 +34,24 @@ export default function Component(props: { records: any, count: number }) {
             // console.log(list)
             setList(JSON.parse(JSON.stringify(list)))
             global.refreshWorkout()
+            global.reloadWorkoutList()
         })
     }
 
     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)))
+        global.reloadWorkoutList()
+        // 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) {
@@ -61,7 +63,7 @@ export default function Component(props: { records: any, count: number }) {
 
     function getWorkoutCount(record) {
         if (!record) return ''
-        if (record.items[0].log_type == 'TIME_SECONDS') {
+        if (record.items[0].format == 'TIME_SECONDS') {
             var time = record.items[0].summary_stats[0].value
             const hours = Math.floor(time / 3600);
             const minutes = Math.floor((time % 3600) / 60);
@@ -78,32 +80,47 @@ export default function Component(props: { records: any, count: number }) {
             }
             return str
         }
-        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
+
+        var obj  =  record.items[0].summary_stats[0]
+        return obj.value+obj.unit
+
+
+        // var list = record.items[0].groups
+        // var count = 0
+        // var unit = ''
+        // debugger
+        // list.map(item => {
+        //     if (item.values.length >0) {
+        //         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
+        // var start = list[0].start.timestamp
+        // var end = list[list.length - 1].end.timestamp
+        // var left = (end - start) / 1000
+        var  left = 0
+        list.map(item=>{
+            var time = Math.floor((item.end.timestamp - item.start.timestamp) / 1000);
+            if (time<1){
+                time = 1
+            }
+            left+=time
+        })
+
         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
+        var str = hours >= 10 ? hours : '0' + hours
         str += ':'
-        str += (minutes > 10 ? minutes : '0' + minutes) + ''
+        str += (minutes >= 10 ? minutes : '0' + minutes) + ''
         str += ':'
-        str += (seconds > 10 ? seconds : '0' + seconds) + ''
+        str += (seconds >= 10 ? seconds : '0' + seconds) + ''
 
         return str
     }
@@ -115,6 +132,29 @@ export default function Component(props: { records: any, count: number }) {
         })
     }
 
+    function summaryTotal(){
+        if (props.summary_stats[0].format=='TIME_SECONDS'){
+            var time = props.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
+        }
+        else {
+            return props.summary_stats[0].value+props.summary_stats[0].unit
+        }
+    }
+
 
     var lastYearStr = '2024年'
     return <View style={{ display: 'flex', flexDirection: 'column' }}>
@@ -122,14 +162,14 @@ export default function Component(props: { records: any, count: number }) {
             user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => global.clearHistory()}>删除全部</Text>
         }
         {
-            <View style={{ display: 'flex', flexDirection: 'row' }}>
+            props.count>0&&<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>
+                    <Text className="workout_summary_value" style={{ color: router.params.themeColor ?? 'white' }}>{summaryTotal()}</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>
+                    <Text className="workout_summary_value" style={{ color: router.params.themeColor ?? 'white' }}>{props.summary_stats[0].count}次</Text>
                 </View>
             </View>
         }

+ 125 - 42
src/features/workout/WorkoutStopWatch.tsx

@@ -30,11 +30,12 @@ export default function Component(props: { targetCount: any, end: Function }) {
     const [showModal, setShowModal] = useState(false)
     const [needTerminal, setNeedTerminal] = useState(false)
     const [isPaused, setIsPaused] = useState(false);
+    const [isPosting,setIsPosting] = useState(false)
     const dispatch = useDispatch();
 
 
     const [pickerItems, setPickerItems] = useState<any[]>([])
-    const [pickerValue, setPcikerValue] = useState<any[]>([])
+    const [pickerValue, setPickerValue] = useState<any[]>([])
 
 
     useEffect(() => {
@@ -60,7 +61,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
                 index: index,
                 time: startTime,
                 duration: props.targetCount,
-                type: 'GROUP'
+                type: 'WORK'
             }]
             setGroups(array)
             saveCache(array)
@@ -93,7 +94,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
             }
 
         })
-        setPcikerValue(selects)
+        setPickerValue(selects)
         setPickerItems(items)
     }, [])
 
@@ -101,16 +102,21 @@ export default function Component(props: { targetCount: any, end: Function }) {
         if (!isPaused) {
             timer = setInterval(() => {
                 setCount((count) => count + 1)
-            }, 1000)
+            }, 500)
         }
 
         return () => clearInterval(timer)
     }, [isPaused])
 
     function resume() {
+        debugger
+        if (timer){
+            clearInterval(timer)
+            timer = null
+        }
         timer = setInterval(() => {
             setCount((count) => count + 1)
-        }, 1000)
+        }, 500)
     }
 
     function planTime() {
@@ -120,7 +126,6 @@ export default function Component(props: { targetCount: any, end: Function }) {
 
     function durationTime() {
         var str = TimeFormatter.formateTimeNow(startTime)
-        // setLastStrTime(str)
         lastStrTime = str
         return str
 
@@ -145,13 +150,18 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function finish() {
+        
         setTempTime(new Date().getTime())
-        if (workout.item.schemas[0].values.length > 0) {
-            
+        var schema = workout.item.schemas[0]
+        if (workout.item.schemas[0].values.length > 0 && schema.format != 'TIME_SECONDS') {
+
             clearInterval(timer)
             setShowModal(true)
             return
         }
+        clearInterval(timer)
+        timer = null
+        resume()
         var array = groups;
         var time = new Date().getTime()
         array.push({
@@ -167,13 +177,17 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function start() {
+        console.log(new Date().getTime())
+        clearInterval(timer)
+        timer = null
+        resume()
         var array = groups;
         var time = new Date().getTime()
         array.push({
             code: workout.item.code,
             index: index + 1,
             time: time,
-            type: 'GROUP'
+            type: 'WORK'
         })
         setStartTime(time)
         setIndex(index + 1)
@@ -205,7 +219,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
     function getUnit() {
         var schema = workout.item.schemas[0]
         var units = schema.values
-        if (schema.log_type == 'TIME_SECONDS') {
+        if (schema.format == 'TIME_SECONDS') {
             return units[units.length - 1].unit
         }
         else {
@@ -214,13 +228,36 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function totalValue() {
+
+
         var count = 0
         var schema = workout.item.schemas[0]
+        if (schema.format == 'TIME_SECONDS') {
+            // for (var i=0;i<groups.length;i++){
+            //     var obj = groups[i]
+            //     if (obj.type=='REST'){
+            //         count+= Math.floor((obj.time-groups[i-1].time)/1000)
+            //     }
+            // }
+
+            debugger
+
+            groups.map(item => {
+                if (item.type == 'WORK') {
+                    var t = Math.floor((item.end - item.start) / 1000)
+                    t = t<1?1:t
+                    console.log(t)
+                    count += t
+                }
+            })
+            return count
+        }
+
         for (var i = 0; i < groups.length; i++) {
             var obj = groups[i]
-            if (obj.type == 'GROUP') {
+            if (obj.type == 'WORK') {
                 var temp = 0
-                if (schema.log_type == 'TIME_SECONDS') {
+                if (schema.format == 'TIME_SECONDS') {
                     temp = parseInt(obj.value + '') * 3600 + parseInt(obj.value2 + '') * 60 + parseInt(obj.value3 + '')
                 }
                 else {
@@ -242,6 +279,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function postData() {
+        setIsPosting(true)
         var date = new Date()
         var strDate = formateDate(date)
 
@@ -249,7 +287,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
 
         for (var i = 0; i < groups.length; i++) {
             var obj = groups[i]
-            if (obj.type == 'GROUP') {
+            if (obj.type == 'WORK') {
                 obj.start = obj.time
                 obj.end = groups[i + 1].time
                 obj.value = groups[i + 1].value
@@ -279,7 +317,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
         for (var i = 0; i < groups.length; i++) {
             var obj = groups[i]
             var values: any = []
-            if (obj.type == 'GROUP') {
+            if (obj.type == 'WORK') {
                 if (obj.value) {
                     if (units) {
                         values.push({
@@ -360,7 +398,9 @@ export default function Component(props: { targetCount: any, end: Function }) {
 
             props.end()
             global.refreshWorkout()
-        }).catch(e => { })
+        }).catch(e => { 
+            setIsPosting(false)
+        })
 
     }
 
@@ -376,29 +416,32 @@ export default function Component(props: { targetCount: any, end: Function }) {
 
     function terminal() {
         clearInterval(timer)
-        setTempTime(new Date().getTime())
+        var tempTimestamp = new Date().getTime()
+        setTempTime(tempTimestamp)
         Taro.showModal({
             title: '提示',
             content: '确认结束?',
             success: function (res) {
                 if (res.confirm) {
-                    if (workout.item.schemas[0].values.length > 0) {
+                    var schema = workout.item.schemas[0]
+                    if (workout.item.schemas[0].values.length > 0 && schema.format != 'TIME_SECONDS') {
                         checkEnd()
                         return;
                     }
 
                     var array = groups;
-                    var time = new Date().getTime()
+                    // var time = new Date().getTime()
                     array.push({
                         index: index,
-                        time: time,
+                        time: tempTimestamp,
                         type: 'REST'
                     })
-                    setIsDoing(false)
+                    // setIsDoing(false)
                     setGroups(array)
 
                     postData()
                 } else if (res.cancel) {
+                    debugger
                     resume()
                     console.log('用户点击取消')
                 }
@@ -409,7 +452,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function numChange(e) {
-        debugger
+        setPickerValue(e)
         setShowModal(false)
         var array = groups;
         array.push({
@@ -433,6 +476,26 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function total() {
+        var schema = workout.item.schemas[0]
+        if (schema.format == 'TIME_SECONDS') {
+            var count = 0
+            // groups.map(item => {
+            //     if (item.type == 'REST') {
+            //         count += parseInt(item.value) * 3600 + parseInt(item.value2) * 60 + parseInt(item.value3)
+            //     }
+            // })
+
+            for (var i = 0; i < groups.length; i++) {
+                var obj = groups[i]
+                if (obj.type == 'REST') {
+                    count += Math.floor((obj.time - groups[i - 1].time) / 1000)
+                }
+            }
+            if (!count) {
+                return '0小时0分钟0秒'
+            }
+            return TimeFormatter.workoutTime(count)
+        }
         var count = 0
         for (var i = 0; i < groups.length; i++) {
             var obj = groups[i]
@@ -459,6 +522,15 @@ export default function Component(props: { targetCount: any, end: Function }) {
         return count + unit.substring(0, unit.length - 1)
     }
 
+    function getGroupValue(item) {
+        var schema = workout.item.schemas[0]
+        if (schema.format == 'TIME_SECONDS') {
+            return ''
+            return item.value + item.value2 + item.value3
+        }
+        return item.value + (item.value2 ? 'x' + item.value2 : '') + (item.value3 ? 'x' + item.value3 : '')
+    }
+
     function pickerContent() {
         var color = workout.item.theme_color
         var title = '本组训练'
@@ -474,6 +546,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
                 showBtns={true}
                 onCancel={() => {
                     resume()
+                    setNeedTerminal(false)
                     setShowModal(false)
                 }} />
         </View>
@@ -489,7 +562,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
                 }
                 return <View key={index} className={item.type == 'REST' ? 'item_group' : 'item_group item_rest'} style={{ justifyContent: 'space-between', color: '#fff' }}>
                     <Text>{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
-                    {item.type == 'REST' && <Text style={{ color: workout.item.theme_color }}>{item.value}{item.value2 ? 'x' + item.value2 : ''}{item.value3 ? 'x' + item.value3 : ''}</Text>}
+                    {item.type == 'REST' && <Text style={{ color: workout.item.theme_color }}>{getGroupValue(item)}</Text>}
                     <Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
                 </View>
             })
@@ -498,13 +571,13 @@ export default function Component(props: { targetCount: any, end: Function }) {
             {
                 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} />
+                    <Text className="working_duration">{isPosting?lastStrTime:durationTime()}</Text>
+                    <ChooseScenarioBtn onClick={finish} disable={isPosting} 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} />
+                        <Text className="working_duration" >{isPosting?lastStrTime:durationTime()}</Text>
+                        <ChooseScenarioBtn onClick={start} disable={isPosting} title="开始下一组" background={workout.item.theme_color} />
                     </View>
             }
         </View>
@@ -512,24 +585,34 @@ export default function Component(props: { targetCount: any, end: Function }) {
         <Text className="working_end" onClick={terminal}>结束训练</Text>
         <View style={{ height: 50 }} />
 
-        <Text>实时训练统计</Text>
-        <Text>总量</Text>
-        <Text>{total()}</Text>
-        <Text>总用时</Text>
-        <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%' }}>
-            <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
-                <Text>计划用时</Text>
-                <Text>{planTime()}</Text>
-            </View>
-            <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
-                <Text>已进行</Text>
-                <Text>{groups.length > 0 && TimeFormatter.formateTimeNow(groups[0].time)}</Text>
+
+        {
+            !router.params.content_only && <View style={{ display: 'flex', flexDirection: 'column' }}>
+                <Text>实时训练统计</Text>
+                <Text>总量</Text>
+                <Text>{total()}</Text>
+                <Text>总用时</Text>
             </View>
-            <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
-                <Text>{groups.length > 0 && new Date().getTime() > groups[0].time + props.targetCount * 1000 ? '已超时' : '距结束'}</Text>
-                <Text>{groups.length > 0 && TimeFormatter.countdown(groups[0].time + props.targetCount * 1000)}</Text>
+        }
+
+
+        {
+            !router.params.content_only && <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%' }}>
+                <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
+                    <Text>计划用时</Text>
+                    <Text>{planTime()}</Text>
+                </View>
+                <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
+                    <Text>已进行</Text>
+                    <Text>{groups.length > 0 && TimeFormatter.formateTimeNow(groups[0].time)}</Text>
+                </View>
+                <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
+                    <Text>{groups.length > 0 && new Date().getTime() > groups[0].time + props.targetCount * 1000 ? '已超时' : '距结束'}</Text>
+                    <Text>{groups.length > 0 && TimeFormatter.countdown(groups[0].time + props.targetCount * 1000)}</Text>
+                </View>
             </View>
-        </View>
+        }
+
         {
             showModal && <Modal dismiss={() => {
                 setShowModal(false)

+ 1 - 0
src/pages/clock/Clock.tsx

@@ -238,6 +238,7 @@ export default function IndexPage() {
 
   useDidShow(() => {
     // global.updateTab(0)
+    global.showModal = false;
     if (user.isLogin) {
       checkWXPubFollow()
       // getCheckData();

+ 26 - 4
src/pages/common/RecordsHistory.tsx

@@ -33,11 +33,11 @@ export default function Page() {
     const [total, setTotal] = useState(0)
     const [isLoading, setIsLoading] = useState(false)
     const [loaded, setLoaded] = useState(false)
+    const [summary_stats, setSummaryStats] = useState(null)
     const user = useSelector((state: any) => state.user);
-    const [count,setCount] = useState(0)
+    const [count, setCount] = useState(0)
     const { t } = useTranslation()
 
-
     global.showModal = (isShow: boolean, detail: any) => {
         setShowModal(isShow)
         setModalDetail(detail)
@@ -98,6 +98,27 @@ export default function Page() {
         getHistory(page)
     }
 
+    global.reloadWorkoutList = () => {
+        workoutRecords(
+            {
+                page: 1,
+                limit: pageIndex * pageSize,
+                code: router.params.code
+            }
+        ).then(res => {
+            Taro.stopPullDownRefresh()
+            setTriggered(false)
+            setLoaded(true)
+            setTotal((res as any).total)
+            setSummaryStats((res as any).summary_stats)
+
+            setRecords((res as any).data)
+            setCount((res as any).total)
+
+            setIsLoading(false)
+        })
+    }
+
     function getHistory(page = pageIndex) {
         if (page == 1)
             setTriggered(true)
@@ -172,6 +193,7 @@ export default function Page() {
                 setTriggered(false)
                 setLoaded(true)
                 setTotal((res as any).total)
+                setSummaryStats((res as any).summary_stats)
                 if (page == 1) {
                     setRecords((res as any).data)
                     setCount((res as any).total)
@@ -237,7 +259,7 @@ export default function Page() {
                 code: router.params.code
             }).then(res => {
                 refresh()
-                global.refreshTime()
+                global.refreshWorkout()
                 // global.refreshMetric()
                 // Taro.getCurrentPages()[0].refresh()
             })
@@ -267,7 +289,7 @@ export default function Page() {
             return <ActivityHistory records={records} />
         }
         if (router.params.type == 'workout') {
-            return <WorkoutHistory records={records} count={count}/>
+            return <WorkoutHistory records={records} count={count} summary_stats={summary_stats} />
         }
     }
 

+ 8 - 0
src/pages/workout/WorkoutDetail.config.ts

@@ -0,0 +1,8 @@
+export default definePageConfig({
+    usingComponents:{
+      // 'ec-canvas': '../../lib/ec-canvas/ec-canvas',
+      // 'demo':'../../components/demo'
+    },
+    "navigationBarTitleText":""
+  })
+