Leon 2 年之前
父節點
當前提交
ea1052dbde

+ 1 - 0
src/components/input/PickerViews.tsx

@@ -41,6 +41,7 @@ const Component = forwardRef((props: {
         if (process.env.TARO_ENV == 'weapp') {
             e.stopPropagation()
         }
+        debugger
         props.onChange(v)
     }
 

+ 15 - 8
src/components/layout/Modal.scss

@@ -17,6 +17,21 @@
 
 /* #ifdef rn */
 
+.modal {
+    position: absolute;
+    top: -2px;
+    left: 0;
+    z-index: 100000;
+    right: 0;
+    bottom: 0;
+    overflow: hidden;
+    display: flex;
+    flex-direction: column;
+    background-color: red;
+    // background-color: rgba($color: #000000, $alpha: 0);
+    // animation: modalBgAnim 0.2s linear forwards;
+}
+
 /* #endif */
 
 @keyframes modalBgAnim {
@@ -38,14 +53,6 @@
 }
 
 
-/* #endif */
-
-
-/* #ifdef rn */
-.modal {}
-
-/* #endif */
-
 .modal_center_container {
     align-items: center;
     justify-content: center;

+ 53 - 4
src/features/workout/Result.tsx

@@ -7,6 +7,7 @@ import Taro from "@tarojs/taro";
 import { useTranslation } from "react-i18next";
 import { deleteWorkoutRecord } from "@/services/workout";
 import { rpxToPx } from "@/utils/tools";
+import { TimeFormatter } from "@/utils/time_format";
 
 export default function Component() {
     const router = useRouter();
@@ -23,7 +24,7 @@ export default function Component() {
     }, [])
 
     function twoTimeDuration(start, end) {
-        var time = Math.floor((end - start) / 1000);
+        var time = Math.round((end - start) / 1000);
         const hours = Math.floor(time / 3600);
         const minutes = Math.floor((time % 3600) / 60);
         const seconds = Math.floor(time % 60);
@@ -63,6 +64,10 @@ export default function Component() {
 
     function getValue(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+'秒'
+        }
+        
         var count = 1
         var unit = ''
         for (var i = 0; i < list.length; i++) {
@@ -95,21 +100,65 @@ export default function Component() {
         })
     }
 
+    function getTotalValue(){
+        if (!record) return ''
+        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') {
+            var time = (record as any).items[0].summary_stats[0].value
+            const hours = Math.floor(time / 3600);
+            const minutes = Math.floor((time % 3600) / 60);
+            const seconds = Math.floor(time % 60);
+            var str = ''
+            if (hours > 0) {
+                str = str + hours + '小时'
+            }
+            if (minutes > 0) {
+                str = str + minutes + '分钟'
+            }
+            if (seconds > 0) {
+                str = str + seconds + '秒'
+            }
+            return str
+        }
+        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'){
+        //         count += parseInt(item.values[0].value)
+        //     }
+        // })
+        // return count
+    }
+
+    function getRealDuration(){
+        if (!record) return ''
+        var seconds = Math.round((histories[histories.length-1].end.timestamp-histories[0].start.timestamp)/1000)
+        return TimeFormatter.workoutTime(seconds)
+    }
+
+    function getPlanDuration(){
+        if (!record) return ''
+        var seconds = (record as any).items[0].duration/1000
+        return TimeFormatter.workoutTime(seconds)
+    }    
+
     return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column' }}>
         <Text className="result_detail_text" style={{ color: router.params.themeColor }}>{router.params.title}</Text>
         <Text className="result_detail_text" style={{ color: '#fff', opacity: 0.4, marginTop: rpxToPx(10), marginBottom: rpxToPx(20) }}>计时训练</Text>
         <Text className="result_detail_text">训练统计</Text>
         <View style={{ marginLeft: rpxToPx(32), display: 'flex', flexDirection: 'column' }}>
             <Text>总量</Text>
-            <Text style={{ color: router.params.themeColor }}>111</Text>
+            <Text style={{ color: router.params.themeColor }}>{getTotalValue()}</Text>
             <Text>用时</Text>
             <View style={{ flexDirection: 'row', display: 'flex', width: '100%' }}>
                 <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', flex: 1 }}>
-                    <Text style={{ color: router.params.themeColor }}>111</Text>
+                    <Text style={{ color: router.params.themeColor }}>{getRealDuration()}</Text>
                     <Text>实际</Text>
                 </View>
                 <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', flex: 1 }}>
-                    <Text style={{ color: router.params.themeColor }}>111</Text>
+                    <Text style={{ color: router.params.themeColor }}>{getPlanDuration()}</Text>
                     <Text>计划</Text>
                 </View>
             </View>

+ 41 - 12
src/features/workout/Workout.tsx

@@ -113,7 +113,7 @@ export default function Component(props: any) {
         if (list.length > 0) {
             checkAuth()
         }
-        if (!timer){
+        if (!timer) {
             loadWorkoutCache()
         }
     })
@@ -127,7 +127,7 @@ export default function Component(props: any) {
                     dispatch(startSuccess({
                         start: workoutObj.time,
                         code: workoutObj.code,
-                        duration:workoutObj.duration
+                        duration: workoutObj.duration
                     }));
 
                     timer = setInterval(() => {
@@ -235,21 +235,22 @@ export default function Component(props: any) {
             if (item.code != '_walk') {
                 setSelItem(item)
                 dispatch(setCurrentWorkoutItem(item))
+                var count = Taro.getStorageSync('lastWorkoutDuration') ?? 60 * 50
                 //进行中的处理
                 if (item.code == workout.code && workout.status == 'ing') {
-                    Taro.navigateTo({ url: '/pages/workout/Working?type=stop_watch&restore=true' })
+                    Taro.navigateTo({ url: '/pages/workout/Working?type=stop_watch&restore=true&count=' + count })
                 }
                 else {
-                    if (workout.status == 'ing'){
+                    if (workout.status == 'ing') {
                         Taro.showModal({
-                            content:t('feature.workout.finish_current'),
-                            showCancel:false
+                            content: t('feature.workout.finish_current'),
+                            showCancel: false
                         })
                         return
                     }
                     workoutStart()
                 }
-                
+
                 return
             }
             if (allowRun) {
@@ -462,7 +463,7 @@ export default function Component(props: any) {
             .then(res => {
                 switch (res.tapIndex) {
                     case 0:
-                        
+
                         chooseMore()
                         break;
                     case 1:
@@ -478,7 +479,7 @@ export default function Component(props: any) {
 
     }
 
-    function chooseMore(){
+    function chooseMore() {
         global.metricAdd = true
         setModalType(MetricModalType.choose)
         setShowPageContainer(true)
@@ -555,11 +556,38 @@ export default function Component(props: any) {
                             unit = ''
                         }
                         else {
-                            if (!item.latest_record){
+                            if (!item.latest_record) {
                                 value = '暂无记录'
                                 desc = ''
                                 showDetail = false
                             }
+                            else {
+                                unit = ''
+                                if (item.latest_record.items[0].summary_stats) {
+                                    if (item.latest_record.items[0].log_type == '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 (minutes>0){
+                                            str = str+minutes+'分钟'
+                                        }
+                                        if(seconds>0){
+                                            str = str+seconds+'秒'
+                                        }
+                                        value = str
+                                    }
+                                    else {
+                                        value = item.latest_record.items[0].summary_stats[0].value
+                                        unit = item.latest_record.items[0].summary_stats[0].unit
+                                    }
+
+                                }
+                            }
                         }
                     }
 
@@ -599,7 +627,7 @@ export default function Component(props: any) {
             /> */}
 
             {
-                user.isLogin && list.length>0 &&<View className="add_more" onClick={chooseMore}>
+                user.isLogin && list.length > 0 && <View className="add_more" onClick={chooseMore}>
                     <Image style={{ width: rpxToPx(48), height: rpxToPx(48) }} src={require('@assets/images/add2.png')} />
                     <Text className="add_more_text">{t('feature.workout.add_more')}</Text>
                 </View>
@@ -726,11 +754,12 @@ export default function Component(props: any) {
                         start={(count) => {
                             setTargetTime(count);
                             setShowModal(false);
+                            Taro.setStorageSync('lastWorkoutDuration', count)
                             Taro.navigateTo({ url: '/pages/workout/Working?type=stop_watch&count=' + count })
                         }} />
                 }
                 {
-                    isStart && <Working targetCount={targetTime} type={WorkoutType.multi} end={() => {
+                    isStart && <Working targetCount={targetTime} end={() => {
                         setIsStart(false)
                         setShowModal(false)
                     }} />

+ 21 - 3
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 }) {
     const user = useSelector((state: any) => state.user);
     const [list, setList] = useState(props.records)
     const [selRecord, setSelRecord] = useState(null)
@@ -60,6 +60,24 @@ export default function Component(props: { records: any,count:number }) {
     }
 
     function getWorkoutCount(record) {
+        if (!record) return ''
+        if (record.items[0].log_type == 'TIME_SECONDS') {
+            var time = 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 (minutes > 0) {
+                str = str + minutes + '分钟'
+            }
+            if (seconds > 0) {
+                str = str + seconds + '秒'
+            }
+            return str
+        }
         var list = record.items[0].groups
         var count = 0
         var unit = ''
@@ -93,7 +111,7 @@ export default function Component(props: { records: any,count:number }) {
     function goDetail(record) {
         setSelRecord(record)
         Taro.navigateTo({
-            url: '/pages/workout/WorkoutDetail?title='+router.params.title+'&themeColor='+router.params.themeColor+'&detail=' + JSON.stringify(record)
+            url: '/pages/workout/WorkoutDetail?title=' + router.params.title + '&themeColor=' + router.params.themeColor + '&detail=' + JSON.stringify(record)
         })
     }
 
@@ -130,7 +148,7 @@ export default function Component(props: { records: any,count:number }) {
                             return <RecordItem delete={() => deleteRecord(record)} onClick={() => goDetail(record)}>
 
                                 <View className="workout_record_item">
-                                    <Text style={{ color: 'white' }}>第 次</Text>
+                                    <Text style={{ color: 'white' }}>第{record.index}次</Text>
                                     <View className="workout_history_content">
                                         <View className="workout_history_item">
                                             <Text>训练总量</Text>

+ 60 - 9
src/features/workout/WorkoutStopWatch.tsx

@@ -42,7 +42,6 @@ export default function Component(props: { targetCount: any, end: Function }) {
             Taro.getStorage({
                 key: 'lastWorkout', success: function (res) {
                     var workouts = JSON.parse(res.data)
-                    debugger
                     setGroups(workouts)
                     var workObj = workouts[workouts.length - 1]
                     setIndex(workObj.index)
@@ -146,8 +145,9 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function finish() {
+        setTempTime(new Date().getTime())
         if (workout.item.schemas[0].values.length > 0) {
-            setTempTime(new Date().getTime())
+            
             clearInterval(timer)
             setShowModal(true)
             return
@@ -202,6 +202,45 @@ export default function Component(props: { targetCount: any, end: Function }) {
         return str.substring(0, i)
     }
 
+    function getUnit() {
+        var schema = workout.item.schemas[0]
+        var units = schema.values
+        if (schema.log_type == 'TIME_SECONDS') {
+            return units[units.length - 1].unit
+        }
+        else {
+            return units.map(obj => obj.unit).join('·')
+        }
+    }
+
+    function totalValue() {
+        var count = 0
+        var schema = workout.item.schemas[0]
+        for (var i = 0; i < groups.length; i++) {
+            var obj = groups[i]
+            if (obj.type == 'GROUP') {
+                var temp = 0
+                if (schema.log_type == 'TIME_SECONDS') {
+                    temp = parseInt(obj.value + '') * 3600 + parseInt(obj.value2 + '') * 60 + parseInt(obj.value3 + '')
+                }
+                else {
+                    if (obj.value) {
+                        temp = parseInt(obj.value + '')
+                    }
+                    if (obj.value2) {
+                        temp *= parseInt(obj.value2 + '')
+                    }
+                    if (obj.value3) {
+                        temp *= parseInt(obj.value3 + '')
+                    }
+                }
+
+                count += temp
+            }
+        }
+        return count
+    }
+
     function postData() {
         var date = new Date()
         var strDate = formateDate(date)
@@ -244,7 +283,8 @@ export default function Component(props: { targetCount: any, end: Function }) {
                 if (obj.value) {
                     if (units) {
                         values.push({
-                            value: getValue(obj.value, units[0].unit)
+                            value: getValue(obj.value, units[0].unit),
+                            unit: units[0].unit
                         })
                     }
                     else {
@@ -257,12 +297,14 @@ export default function Component(props: { targetCount: any, end: Function }) {
 
                 if (obj.value2) {
                     values.push({
-                        value: getValue(obj.value2, units[1].unit)
+                        value: getValue(obj.value2, units[1].unit),
+                        unit: units[1].unit
                     })
                 }
                 if (obj.value3) {
                     values.push({
-                        value: getValue(obj.value3, units[2].unit)
+                        value: getValue(obj.value3, units[2].unit),
+                        unit: units[2].unit
                     })
                 }
             }
@@ -289,6 +331,13 @@ export default function Component(props: { targetCount: any, end: Function }) {
             items: [
                 {
                     code: workout.item.code,
+                    duration: props.targetCount * 1000,
+                    summary_stats: [
+                        {
+                            unit: getUnit(),
+                            value: totalValue()
+                        }
+                    ],
                     groups: records
                 }
             ]
@@ -302,13 +351,13 @@ export default function Component(props: { targetCount: any, end: Function }) {
             //     url: '/pages/common/RecordsHistory?type=workout&refreshList=getCards&title=' + item.name + '&code=' + item.code + '&themeColor=' + item.theme_color
             // })
 
-            setTimeout(()=>{
-                Taro.navigateTo({
+            setTimeout(() => {
+                Taro.redirectTo({
                     url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify((res as any).latest_record)
                 })
-            },0)
+            }, 0)
+
 
-            
             props.end()
             global.refreshWorkout()
         }).catch(e => { })
@@ -327,6 +376,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
 
     function terminal() {
         clearInterval(timer)
+        setTempTime(new Date().getTime())
         Taro.showModal({
             title: '提示',
             content: '确认结束?',
@@ -359,6 +409,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
     }
 
     function numChange(e) {
+        debugger
         setShowModal(false)
         var array = groups;
         array.push({

+ 0 - 12
src/pages/clock/Clock.weapp.tsx → src/pages/clock/Clock.tsx

@@ -30,15 +30,12 @@ import Box from '@/components/layout/Box'
 import Layout from '@/components/layout/layout'
 import { CheckBoxType, NaviBarTitleShowType, TemplateType } from '@/utils/types'
 import { updateScenario } from '@/store/time'
-import { showModal } from '@/store/modal'
 import { ConsoleType, changeConsoleStatus } from '@/store/console'
 import TitleView from '@/features/trackTimeDuration/components/TitleView'
 import StatusIndicator from '@/features/trackTimeDuration/components/StatusIndicator'
 import { useTranslation } from 'react-i18next'
-import TableCellHeader from '@/components/layout/TableCellHeader'
 import SectionHeader from '@/components/layout/SectionHeader'
 import Header from '@/components/layout/Header'
-import { TimeFormatter } from '@/utils/time_format'
 import NoData from '@/components/view/NoData'
 import { ColorType } from '@/context/themes/color'
 import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
@@ -459,7 +456,6 @@ export default function IndexPage() {
           {
             needShowAddTip && showTip && <Tooltip title="添加到我的小程序" closeTip={() => { setNeedShowAddTip(false) }} />
           }
-          {/* <View style={{ width: '100%', height: 400, backgroundColor: 'gray' }}></View> */}
 
           <Box>
             <View className='clock_bg' onClick={tapClock}>
@@ -471,11 +467,6 @@ export default function IndexPage() {
               <ChooseScenarioBtn title='登录体验' background={ColorType.fast} onClick={tapLogin} />
             </View>
           }
-          {/* <Box>
-            <View className='clock_bg' onClick={tapClock}>
-              <Clocks />
-            </View>
-          </Box> */}
           {
             errorView()
           }
@@ -549,9 +540,6 @@ export default function IndexPage() {
     )
   }
 
-  if (process.env.TARO_ENV == 'rn')
-    return <View />
-
   return <View>
     {detail()}
     <Tabbar index={0} />

+ 0 - 0
src/pages/clock/Clock.rn.tsx → src/pages/clock/Clock111.rn.tsx


+ 1 - 1
src/pages/rn/RNMain.tsx

@@ -3,7 +3,7 @@ import { NavigationContainer } from '@react-navigation/native';
 import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
 import { createStackNavigator } from '@react-navigation/stack';
 
-import Clock from '../clock/Clock.rn'
+import Clock from '../clock/Clock'
 import Metric from '../metric/Metric'
 import Activity from '../activity/Activity'
 import Profile from '../account/Profile'