leon před 2 roky
rodič
revize
504654173d

+ 40 - 5
src/features/trackSomething/components/Activity.tsx

@@ -28,7 +28,6 @@ export default function Component(props: any) {
     }, [user.isLogin])
 
     useEffect(() => {
-        debugger
         console.log('checkResult.type:' + checkResult.type)
     }, [
         checkResult.type
@@ -64,7 +63,7 @@ export default function Component(props: any) {
                         var time = Taro.getStorageSync('lastUploadStepsTime')
                         if (time) {
                             var now = new Date().getTime()
-                            if (now - time >= 48 * 24 * 3600 * 1000) {
+                            if (now - time >= 30 * 24 * 3600 * 1000) {
                                 getWeRunData(true)
                             }
                         }
@@ -157,6 +156,34 @@ export default function Component(props: any) {
     }
 
     // checkResult.type == 'ing' && setStrBtnTitle('打卡中...')
+    var btnTitle = '';
+    var isEnable = true;
+    if (allowRun){
+        if (checkResult.type == 'idle'){
+            btnTitle =  '打卡'
+            isEnable = true
+        }
+        else if (checkResult.type == 'ing'){
+            btnTitle = '打卡中...'
+            isEnable = false;
+        }
+        else if (checkResult.type == 'success'){
+            btnTitle = '打卡成功'
+            isEnable = false
+        }
+        else if (checkResult.type == 'fail'){
+            btnTitle = '打卡失败'
+            isEnable = false
+        }
+        else if (checkResult.type == 'countdown'){
+            btnTitle = checkResult.title+'s'
+            isEnable = false;
+        }
+    }
+    else {
+        btnTitle =  '开启';
+        isEnable = true;
+    }
 
     return <View>
         {
@@ -165,7 +192,13 @@ export default function Component(props: any) {
                 var desc = ''
                 if ((item as any).latest_record) {
                     value = (item as any).latest_record.items[0].value
-                    desc = TimeFormatter.formatTimestamp((item as any).latest_record.timestamp)
+                    if ((item as any).latest_record.timestamp==0){
+                        desc = '今天待打卡'
+                    }
+                    else {
+                        desc = TimeFormatter.formatTimestamp((item as any).latest_record.timestamp)
+                    }
+                    
                 }
 
                 if (!allowRun) {
@@ -178,9 +211,11 @@ export default function Component(props: any) {
                     value={value}
                     unit={(allowRun && stepInfo) ? '步' : ''}
                     desc={desc}
+                    btnText={btnTitle}
+                    isDisabled={!isEnable}
                     // desc={allowRun ? stepInfo ? TimeFormatter.formatTimestamp(lastTime) : '' : '开启步数仅自己可见'}
-                    btnText={allowRun ? isCheking ? '打卡中...' : '打卡' : '开启'}
-                    isDisabled={isCheking}
+                    // btnText={allowRun ? isCheking ? '打卡中...' : '打卡' : '开启'}
+                    // isDisabled={isCheking}
                     themeColor='#EEC01F'
                     onClickDetail={goDetail}
                     onClick={checkout}

+ 3 - 2
src/features/trackSomething/components/ActivityHistory.tsx

@@ -3,7 +3,6 @@ import './MetricHistory.scss'
 
 export default function Component(props: { records: any[] }) {
     function formateDate(date: string) {
-        debugger
         //yyyyMMdd转换成日期,如果是今天,返回今天,如果是昨天,返回昨天,如果是昨天之前,返回日期
         const dt = new Date(date.substring(0,4) + '/' + 
         date.substring(4,6) + '/' +
@@ -19,7 +18,9 @@ export default function Component(props: { records: any[] }) {
         } else if (diff < 2 * day) {
             return '昨天';
         } else {
-            return dt.toISOString().slice(0, 10);
+            return date.substring(0,4) + '-' + 
+            date.substring(4,6) + '-' +
+            date.substring(6)//dt.toISOString().slice(0, 10);
         }
     }
     function formateHourMinutes(timestamp: number) {

+ 20 - 2
src/pages/Metric.tsx

@@ -2,9 +2,11 @@ import { View, Text, CoverView, Button } from "@tarojs/components";
 import { useState } from "react";
 import Modal from "@/components/Modal";
 import PickerViews from "@/components/PickerViews";
+import LimitPickers from "@/components/LimitPickers";
 
 export default function Page() {
     const [isModalOpen, setIsModalOpen] = useState(false);
+    const [isTimePickerOpen, setIsTimePickerOpen] = useState(false);
     const [pickerValue, setPickerValue] = useState([]);
     const [pickerItems, setPickerItems] = useState([]);
     const [isPoint, setIsPoint] = useState(false)
@@ -32,7 +34,7 @@ export default function Page() {
         }
 
         setPickerItems([items] as any)
-
+        setIsPoint(false)
 
         openModal()
     }
@@ -62,6 +64,7 @@ export default function Page() {
 
         setPickerValue([value0Index, value1Index] as any)
         setPickerItems([items, items2] as any)
+        setIsPoint(false)
         openModal()
     }
 
@@ -99,6 +102,11 @@ export default function Page() {
         console.log(e)
         closeModal()
     }
+
+    function showTimePicker() {
+        setIsTimePickerOpen(true)
+    }
+    const limit = new Date().getTime() - 7 * 3600 * 1000 * 24;
     return (
         <View className="container">
             <Text onClick={openModal}>Metric Page</Text>
@@ -114,7 +122,7 @@ export default function Page() {
                         width: '100%', height: '50%', color: '#000'
                     }}>
                         <Text style={{ textAlign: 'center' }}>指标Title</Text>
-                        <Text style={{ textAlign: 'center' }}>22:22</Text>
+                        <Text style={{ textAlign: 'center' }} onClick={showTimePicker}>22:22</Text>
                         <View style={{ position: 'relative' }}>
                             <PickerViews onChange={pickerChanged}
                                 items={pickerItems}
@@ -132,6 +140,16 @@ export default function Page() {
                     </View>
                 </Modal>
             }
+            {
+                 
+                isTimePickerOpen && <Modal dismiss={() => setIsTimePickerOpen(false)}>
+                    <LimitPickers limit={limit} onCancel={()=>{setIsTimePickerOpen(false)}} onChange={(e) => {
+                         console.log(new Date(e))
+                        //  pickerConfirm(e)
+                        //  hidePicker()
+                     }} />
+                </Modal>
+            }
         </View>
     )
 }

+ 28 - 48
src/store/action_results.tsx

@@ -1,4 +1,4 @@
-import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
+import { PayloadAction, createAsyncThunk, createSlice } from "@reduxjs/toolkit";
 import { useDispatch } from "react-redux";
 
 export enum ResultType {
@@ -21,8 +21,8 @@ const initialState: ResultState = {
     seconds: 0
 }
 
-const resultTime = 2;
-const countdownTime = 20;
+const resultTime = 1;
+const countdownTime = 5;
 
 const resultSlice = createSlice({
     name: 'result',
@@ -32,49 +32,14 @@ const resultSlice = createSlice({
             state.type = ResultType.ing;
         },
         checkSuccess(state) {
-            debugger
-            console.log('9527')
-            // state.type = ResultType.success;
-            // var count = resultTime;
-            // var timer = setInterval(()=>{
-            //     count--;
-            //     if (count <= 0) {
-            //         clearInterval(timer);
-            //         state.type = ResultType.countdown;
-            //         var count2 = countdownTime;
-            //         var timer2 = setInterval(()=>{
-            //             count2--;
-            //             if (count2 <= 0) {
-            //                 clearInterval(timer2);
-            //                 state.type = ResultType.idle;
-            //             }
-            //         },1000)
-            //     }
-            // },1000)
+            state.type = ResultType.success;
         },
         checkFail(state) {
             state.type = ResultType.fail;
-            var count = resultTime;
-            var timer = setInterval(()=>{
-                count--;
-                if (count <= 0) {
-                    clearInterval(timer);
-                    state.type = ResultType.idle;
-                }
-            },1000)
         },
-        checkCountdown(state) {
-            debugger
+        checkCountdown(state,action: PayloadAction<any>) {
+            state.title = action.payload;
             state.type = ResultType.countdown;
-            var count = 20;
-            var timer = setInterval(()=>{
-                count--;
-                if (count <= 0) {
-                    clearInterval(timer);
-                    state.type = ResultType.idle;
-                }
-            },1000)
-            // state.seconds = action.payload;
         },
         checkCountdownEnd(state) {
             state.type = ResultType.idle;
@@ -92,16 +57,31 @@ export const { checkStart, checkSuccess, checkFail, checkCountdownEnd, checkCoun
 export default resultSlice.reducer;
 
 export const setResult = createAsyncThunk('result/action', async (payload: {isSuccess:boolean}, { dispatch }) => {
-    debugger
     if (payload.isSuccess) {
-        console.log('aaaa')
         dispatch(checkSuccess());
-        console.log('successdddd')
         setTimeout(() => {
-            dispatch(checkCountdown());
-            console.log('zzzzz')
-            debugger
-        }, 2000);
+            var count = countdownTime;
+            dispatch(checkCountdown(count));
+            
+            var timer = setInterval(()=>{
+                count--;
+                dispatch(checkCountdown(count));
+                if (count<0){
+                    clearInterval(timer);
+                    dispatch(resetStatus())
+                }
+            },1000)
+        }, resultTime*1000);
+
+        // setTimeout(()=>{
+        //     dispatch(resetStatus())
+        // },countdownTime*1000)
+    }
+    else {
+        dispatch(checkFail());
+        setTimeout(()=>{
+            dispatch(resetStatus());
+        },resultTime*1000)
     }
 
 });