Leon 1 год назад
Родитель
Сommit
2c76a816a6
3 измененных файлов с 135 добавлено и 4 удалено
  1. 122 3
      src/features/health/MainConsole.tsx
  2. 12 1
      src/services/health.tsx
  3. 1 0
      src/services/http/api.js

+ 122 - 3
src/features/health/MainConsole.tsx

@@ -1,18 +1,32 @@
 import { WindowType } from "@/utils/types";
 import { WindowType } from "@/utils/types";
 import { View, Text } from "@tarojs/components";
 import { View, Text } from "@tarojs/components";
 import dayjs from "dayjs";
 import dayjs from "dayjs";
-import { useEffect } from "react";
+import { useEffect, useRef, useState } from "react";
 import { useSelector } from "react-redux";
 import { useSelector } from "react-redux";
 import './MainConsole.scss'
 import './MainConsole.scss'
 import { jumpPage } from "../trackTimeDuration/hooks/Common";
 import { jumpPage } from "../trackTimeDuration/hooks/Common";
+import Modal from "@/components/layout/Modal.weapp";
+import { MainColorType } from "@/context/themes/color";
+import ConsolePicker from "../trackTimeDuration/components/ConsolePicker";
+import { clockTimes } from "@/services/health";
 
 
 let useNavigation;
 let useNavigation;
+let min = 0
+let max = 0
+let defaultTimestamp = 0
+
 if (process.env.TARO_ENV == 'rn') {
 if (process.env.TARO_ENV == 'rn') {
     useNavigation = require("@react-navigation/native").useNavigation
     useNavigation = require("@react-navigation/native").useNavigation
 }
 }
 
 
 export default function MainConsole(props: { type: WindowType }) {
 export default function MainConsole(props: { type: WindowType }) {
     const health = useSelector((state: any) => state.health);
     const health = useSelector((state: any) => state.health);
+    const user = useSelector((state: any) => state.user);
+    const [showTimePicker, setShowTimePicker] = useState(false)
+    const [operateType, setOperateType] = useState('')
+    const [btnDisable, setBtnDisable] = useState(false)
+    const [selItem, setSelItem] = useState<any>(null)
+    const limitPickerRef = useRef(null)
 
 
     let navigation, showActionSheetWithOptions;
     let navigation, showActionSheetWithOptions;
     if (useNavigation) {
     if (useNavigation) {
@@ -26,19 +40,121 @@ export default function MainConsole(props: { type: WindowType }) {
 
 
 
 
     function record(item) {
     function record(item) {
+        if (!user.isLogin) {
+            jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
+            return
+        }
+
+        setSelItem(item)
+
+        switch (item.action) {
+            case 'START':
+                {
+                    defaultTimestamp = new Date().getTime()
+                    min = defaultTimestamp - 1 * 24 * 3600 * 1000
+                    max = defaultTimestamp
+
+                    setOperateType('startFast')
+                    setShowTimePicker(true)
+                }
+                return;
+            case 'END':
+                {
+                    defaultTimestamp = new Date().getTime()
+                    // defaultTimestamp = e ? new Date().getTime() : logEventTimestamp
+                    min = defaultTimestamp - 1 * 24 * 3600 * 1000
+                    max = defaultTimestamp
+                    setOperateType('endFast')
+                    setShowTimePicker(true)
+                }
+                return;
+
+        }
         jumpPage('/pages/clock/AddMoment?moment=' + JSON.stringify(item))
         jumpPage('/pages/clock/AddMoment?moment=' + JSON.stringify(item))
     }
     }
 
 
     function timelineItem(item: any, index: number) {
     function timelineItem(item: any, index: number) {
-        return <View key={index} className="timeline_item" onClick={() => record(item)}>
+        return <View key={index} className="timeline_item" >
             <View className="timeline_left">
             <View className="timeline_left">
                 <Text className="timeline_title">{item.title}</Text>
                 <Text className="timeline_title">{item.title}</Text>
                 <Text className="timeline_time">{dayjs(item.target.timestamp).format('HH:mm')}</Text>
                 <Text className="timeline_time">{dayjs(item.target.timestamp).format('HH:mm')}</Text>
             </View>
             </View>
-            <View className="timeline_operate">记录</View>
+            {
+                item.action && item.action != 'NA' && <View className="timeline_operate" onClick={() => record(item)}>记录</View>
+            }
+
         </View>
         </View>
     }
     }
 
 
+    function modalContent() {
+        global.set_time = new Date().getTime()
+        return <Modal
+            testInfo={null}
+            dismiss={() => {
+                setShowTimePicker(false)
+            }}
+            confirm={() => { }}>
+            {
+                timePickerContent()
+            }
+        </Modal>
+    }
+
+    function timePickerContent() {
+        var title = operateType == 'endFast' ? '结束断食' : '开始断食'
+        var color = MainColorType.fast
+        var endTimestamp = 0
+        if (operateType == 'endFast') {
+            endTimestamp = new Date().getTime()//fastData.target.end_time
+        }
+
+        var duration = 24*3600*1000//fastData.target.duration
+
+        return <View className="modal_content">
+            <ConsolePicker ref={limitPickerRef}
+                themeColor={color}
+                title={title}
+                onCancel={() => {
+                    setShowTimePicker(false)
+                }}
+                min={min}
+                max={max}
+                current={defaultTimestamp}
+                duration={duration}
+                endTimestamp={endTimestamp}
+                isFast={true}
+                isEnd={operateType == 'endFast'}
+                isTimeout={false}
+                isLoading={btnDisable}
+                onChange={(e) => {
+                    pickerConfirm(e, null)
+                    global.pauseIndexTimer = false
+                }}
+            />
+        </View>
+    }
+
+    function pickerConfirm(t1: number, event: any) {
+        if (btnDisable) {
+            return
+        }
+        global.scenario = 'FAST'
+        setBtnDisable(true)
+        clockTimes({
+            check_items: [{
+                schedule_id: selItem.schedule_id,
+                date: dayjs(t1).format('YYYYMMDD'),
+                timestamp: t1
+            }]
+        }).then(res => {
+            setBtnDisable(false)
+            setShowTimePicker(false)
+            global.refreshWindow()
+        }).catch(e => {
+            setBtnDisable(false)
+        })
+    }
+
     function detail() {
     function detail() {
         const { day, night } = health.windows.night_day
         const { day, night } = health.windows.night_day
         const { fast, eat } = health.windows.fast_eat
         const { fast, eat } = health.windows.fast_eat
@@ -99,5 +215,8 @@ export default function MainConsole(props: { type: WindowType }) {
         {
         {
             detail()
             detail()
         }
         }
+        {
+            showTimePicker && modalContent()
+        }
     </View>
     </View>
 }
 }

+ 12 - 1
src/services/health.tsx

@@ -1,4 +1,4 @@
-import { API_HEALTH_LABELS, API_HEALTH_MOMENT, API_HEALTH_RECORD, API_HEALTH_SCHEDULES, API_HEALTH_STREAKS, API_HEALTH_WINDOWS } from "./http/api";
+import { API_HEALTH_CLOCK, API_HEALTH_LABELS, API_HEALTH_MOMENT, API_HEALTH_RECORD, API_HEALTH_SCHEDULES, API_HEALTH_STREAKS, API_HEALTH_WINDOWS } from "./http/api";
 import { request } from "./http/request";
 import { request } from "./http/request";
 
 
 export const getLabels = (params) => {
 export const getLabels = (params) => {
@@ -114,4 +114,15 @@ export const createMoment = (params) =>{
             // dispatch(loginSuccess(res));
             // dispatch(loginSuccess(res));
         })
         })
     })
     })
+}
+
+export const clockTimes = (params) =>{
+    return new Promise((resolve) => {
+        request({
+            url: API_HEALTH_CLOCK, method: 'POST', data: { ...params }
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        })
+    })
 }
 }

+ 1 - 0
src/services/http/api.js

@@ -101,3 +101,4 @@ export const API_HEALTH_LABELS = `${baseUrl}/api/health/labels`
 export const API_HEALTH_RECORD = `${baseUrl}/api/health/records`
 export const API_HEALTH_RECORD = `${baseUrl}/api/health/records`
 export const API_HEALTH_STREAKS = `${baseUrl}/api/health/streaks`
 export const API_HEALTH_STREAKS = `${baseUrl}/api/health/streaks`
 export const API_HEALTH_WINDOWS = `${baseUrl}/api/health/windows`
 export const API_HEALTH_WINDOWS = `${baseUrl}/api/health/windows`
+export const API_HEALTH_CLOCK = `${baseUrl}/api/health/clocks`