Leon 2 年之前
父節點
當前提交
5714203f58

+ 14 - 3
src/features/food/FoodConsole.tsx

@@ -43,8 +43,8 @@ export default function Component(props: { addItem: Function, firstItem: any })
     useEffect(() => {
         if (firstData &&
             firstData.mindful_mode == 'AWARE' &&
-            firstData.status != 'PART_COMPLETED' &&
-            (!firstData.feel.post_meal || !firstData.feel.pre_meal)) {
+            (firstData.status != 'PART_COMPLETED' && firstData.status!='COMPLETED')
+            ) {
             setLastUnFinished(true)
             setModeOn(true)
         }
@@ -52,8 +52,19 @@ export default function Component(props: { addItem: Function, firstItem: any })
             setLastUnFinished(false)
             var isOn = Taro.getStorageSync('food_switch')
             setModeOn(isOn)
-            // Taro.setStorageSync('food_switch',e.detail.value)
         }
+        // if (firstData &&
+        //     firstData.mindful_mode == 'AWARE' &&
+        //     firstData.status != 'PART_COMPLETED' &&
+        //     (!firstData.feel.post_meal || !firstData.feel.pre_meal)) {
+        //     setLastUnFinished(true)
+        //     setModeOn(true)
+        // }
+        // else {
+        //     setLastUnFinished(false)
+        //     var isOn = Taro.getStorageSync('food_switch')
+        //     setModeOn(isOn)
+        // }
     }, [firstData])
 
     useEffect(() => {

+ 5 - 5
src/features/food/FoodTimelineItem.tsx

@@ -233,7 +233,7 @@ export default function Component(props: {
             }
         }
         editFoodJournal(params, detail.id).then(res => {
-            
+
             if (isPreMeal) {
                 (res as any).showDate = props.data.showDate
                 setDetail(res)
@@ -390,12 +390,12 @@ export default function Component(props: {
         {
             detail.mindful_mode == 'AWARE' && detail.status == 'WAIT_FOR_POSTMEAL' &&
             <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(60), position: 'relative' }}>
-                <Slider onChanged={(value) => { updateFeel(value, false) }} value={detail.feel.pre_meal} isPreMeal={false} isPostMeal={true}/>
+                <Slider onChanged={(value) => { updateFeel(value, false) }} value={detail.feel.pre_meal} isPreMeal={false} isPostMeal={true} />
                 <Image src={require('@assets/images/more-vertical.png')} className="food_timeline_more" onClick={more} />
             </View>
         }
         {
-            detail.mindful_mode == 'AWARE' && detail.status=='COMPLETED' &&
+            detail.mindful_mode == 'AWARE' && detail.status == 'COMPLETED' &&
             <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
                 <View style={{ width: rpxToPx(375) }} />
                 <View className="food_item_point" style={{ backgroundColor: ColorType.food }} />
@@ -442,13 +442,13 @@ export default function Component(props: {
 
         </View>
         {
-            detail.mindful_mode == 'AWARE' && detail.status=='WAIT_FOR_PREMEAL' &&
+            detail.mindful_mode == 'AWARE' && detail.status == 'WAIT_FOR_PREMEAL' &&
             <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: rpxToPx(60) }}>
                 <Slider onChanged={(value) => { updateFeel(value, true) }} isPreMeal={true} />
             </View>
         }
         {
-            detail.mindful_mode == 'AWARE' && detail.feel.pre_meal &&
+            detail.mindful_mode == 'AWARE' && (detail.status == 'WAIT_FOR_POSTMEAL' || detail.status == 'COMPLETED' || detail.status == 'PART_COMPLETED') &&
             <View style={{
                 display: 'flex', flexDirection: 'row', alignItems: 'center',
                 marginBottom: rpxToPx(60), marginTop: -rpxToPx(60)

+ 29 - 5
src/features/workout/Result.tsx

@@ -6,12 +6,13 @@ import './Result.scss';
 import Taro from "@tarojs/taro";
 import { useTranslation } from "react-i18next";
 import { deleteWorkoutRecord } from "@/services/workout";
+import { rpxToPx } from "@/utils/tools";
 
 export default function Component() {
     const router = useRouter();
     const [histories, setHistories] = useState<any>([])
-    const [record,setRecord] = useState(null)
-    const {t} = useTranslation()
+    const [record, setRecord] = useState(null)
+    const { t } = useTranslation()
 
     useEffect(() => {
         var data = JSON.parse(router.params.detail as any)
@@ -84,7 +85,7 @@ export default function Component() {
         })
     }
 
-    function delData(){
+    function delData() {
         deleteWorkoutRecord({ id: (record as any).id }).then(res => {
             global.delWorkoutRecord()
             global.refreshWorkout()
@@ -93,7 +94,30 @@ export default function Component() {
     }
 
     return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column' }}>
-        <Text className="result_detail_text">训练组</Text>
+        <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>用时</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>实际</Text>
+                </View>
+                <View style={{display:'flex',flexDirection:'column',alignItems:'center',flex:1}}>
+                    <Text style={{ color: router.params.themeColor }}>111</Text>
+                    <Text>计划</Text>
+                </View>
+            </View>
+
+        </View>
+        {/* <View>
+            <Text>用时</Text>
+            <Text style={{ color: router.params.themeColor }}>111</Text>
+        </View> */}
+        <Text className="result_detail_text">训练详情</Text>
         {
             histories.length > 0 && <Text className="result_count">共{getCount()}组</Text>
         }
@@ -103,7 +127,7 @@ 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: ColorType.workout }}>{getValue(item)}</Text>}
+                    {item.type == 'GROUP' && <Text style={{ color: router.params.themeColor }}>{getValue(item)}</Text>}
                     <Text className="result_time">{twoTimeDuration(item.start.timestamp, item.end.timestamp)}</Text>
                 </View>
             })

+ 2 - 6
src/features/workout/Workout.tsx

@@ -566,8 +566,7 @@ export default function Component(props: any) {
                 })
             }
 
-            <MetricItem title='TABATA'
-                // value={allowRun ? stepInfo ? (stepInfo as any).step : '' : '未开启'}
+            {/* <MetricItem title='TABATA'
                 value={10}
                 unit={''}
                 desc={'total time'}
@@ -575,16 +574,13 @@ export default function Component(props: any) {
                 isDisabled={false}
                 themeColor={themeColor}
                 onClickDetail={() => {
-                    // Taro.navigateTo({
-                    //     url: '/pages/workout/History'
-                    // })
                 }}
                 showBadge={showErrorBadge && checkResult.type == 'idle'}
                 showDetail={false}
                 onClick={() => {
                     timeStart()
                 }}
-            />
+            /> */}
 
             {
                 user.isLogin && <View className="add_more" onClick={addBtnClick}>

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

@@ -44,4 +44,26 @@
     color: #EEC01F;
     font-weight: bold;
     margin-top: 10px;
+}
+
+.workout_summary{
+    display: flex;
+    flex-direction: column;
+    padding-left: 38px;
+    flex: 1;
+}
+
+.workout_summary_title{
+    color: #fff;
+    opacity: 0.8;
+    font-weight: bold;
+    font-size: 32px;
+    line-height: 32px;
+}
+
+.workout_summary_value{
+    margin-top: 10px;
+    font-size: 48px;
+    line-height: 48px;
+    font-weight: bold;
 }

+ 32 - 16
src/features/workout/WorkoutHistory.tsx

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

+ 3 - 1
src/pages/common/RecordsHistory.tsx

@@ -34,6 +34,7 @@ export default function Page() {
     const [isLoading, setIsLoading] = useState(false)
     const [loaded, setLoaded] = useState(false)
     const user = useSelector((state: any) => state.user);
+    const [count,setCount] = useState(0)
     const { t } = useTranslation()
 
 
@@ -173,6 +174,7 @@ export default function Page() {
                 setTotal((res as any).total)
                 if (page == 1) {
                     setRecords((res as any).data)
+                    setCount((res as any).total)
                 } else {
                     setRecords(records.concat((res as any).data))
                 }
@@ -265,7 +267,7 @@ export default function Page() {
             return <ActivityHistory records={records} />
         }
         if (router.params.type == 'workout') {
-            return <WorkoutHistory records={records} />
+            return <WorkoutHistory records={records} count={count}/>
         }
     }
 

+ 1 - 1
src/pages/workout/Workout.config.ts

@@ -3,7 +3,7 @@ export default definePageConfig({
       // 'ec-canvas': '../../lib/ec-canvas/ec-canvas',
       // 'demo':'../../components/demo'
     },
-    "disableScroll": true,
+    "enablePullDownRefresh":true,
     "navigationBarTitleText":""
   })
   

+ 30 - 25
src/pages/workout/Workout.tsx

@@ -1,37 +1,42 @@
 import { View, Text } from "@tarojs/components";
-import { useDidShow, useReady, useShareAppMessage } from "@tarojs/taro";
+import { useDidShow, usePullDownRefresh, useReady, useShareAppMessage } from "@tarojs/taro";
 import Tabbar from "@/components/navigation/TabBar";
 import { useTranslation } from "react-i18next";
 import Workout from "@/features/workout/Workout";
 
 export default function Page() {
 
-    const { t } = useTranslation()
-    // useReady(()=>{
-    //     activityCards().then(res=>{
+  const { t } = useTranslation()
+  // useReady(()=>{
+  //     activityCards().then(res=>{
 
-    //     })
-    // })
-    if (process.env.TARO_ENV == 'weapp') {
-        useShareAppMessage((e) => {
-          return {
-            title: t('share.title'),
-            path: 'pages/clock/Clock'
-          }
-        })
+  //     })
+  // })
+  if (process.env.TARO_ENV == 'weapp') {
+    useShareAppMessage((e) => {
+      return {
+        title: t('share.title'),
+        path: 'pages/clock/Clock'
       }
-
-    useDidShow(() => {
-        // global.updateTab(2)
     })
+  }
+
+  useDidShow(() => {
+    // global.updateTab(2)
+  })
+
+  usePullDownRefresh(() => {
+
+    global.refreshWorkout()
+  })
 
-    function refresh() {
-        console.log('refresh')
-    }
-    return (
-        <View>
-            <Workout />
-            <Tabbar index={2} />
-        </View>
-    )
+  function refresh() {
+    console.log('refresh')
+  }
+  return (
+    <View>
+      <Workout />
+      <Tabbar index={2} />
+    </View>
+  )
 }

+ 2 - 7
src/services/http/request.ts

@@ -40,7 +40,7 @@ async function getStorage(key: string) {
 
 
 export async function request<T>(param: RequestParam): Promise<T> {
-    const kTimeout = 4000;
+    const kTimeout = 8000;
     const kRetryCount = 2;
 
     let retryCount = 0;
@@ -73,17 +73,12 @@ export async function request<T>(param: RequestParam): Promise<T> {
             console.log('timeout');
             if (retryCount < kRetryCount) {
                 // Retry the request
-                console.log(`Retrying request (${retryCount + 1}/3)...`);
+                console.log(`Retrying request (${retryCount + 1}/2)...`);
                 retryCount++;
                 performRequest(resolve, reject);
                 return;
             }
-            // global.postBtnUpdateStatus('idle')
             ToastUtil.getInstance().showToast(method == 'GET' ? '网络连接失败,请检查网络' : '操作失败,请检查网络');
-            // Taro.showToast({
-            //     icon:'none',
-            //     title: method=='GET'?'网络连接失败,请检查网络':'操作失败,请检查网络',
-            // })
             reject('timeout');
         }, kTimeout);