Leon 2 年之前
父節點
當前提交
3aef1f69b3

+ 1 - 0
src/app.config.ts

@@ -11,6 +11,7 @@ const appConfig = defineAppConfig({
     'pages/Profile',
     'pages/Metric',
     'pages/Activity',
+    'pages/RecordsHistory'
   ],
   subPackages: [
     {

+ 0 - 1
src/components/LimitPickers.tsx

@@ -2,7 +2,6 @@ import { PickerView, PickerViewColumn, View, Text } from "@tarojs/components";
 import { useEffect, useState } from "react";
 
 export default function Component(props: { limit: number, onChange: Function, onCancel: Function }) {
-    console.log('oppsu')
     const days: string[] = [];
     const today = new Date();
     const [values, setValues] = useState([6, today.getHours(), today.getMinutes()])

+ 1 - 1
src/components/PickerViews.tsx

@@ -1,7 +1,7 @@
 import { PickerView, PickerViewColumn, View, Text } from "@tarojs/components";
 import { useEffect, useState } from "react";
 
-export default function Component(props: { value: number[], onChange: Function, items: any[], height?: number, showBtns?: boolean, onCancel?: Function, }) {
+export default function Component(props: { value: any, onChange: Function, items: any, height?: number, showBtns?: boolean, onCancel?: Function, }) {
     const [v, setV] = useState([0])
     useEffect(() => {
         setV(props.value)

+ 2 - 0
src/features/trackTimeDuration/actions/TrackTimeActions.tsx

@@ -2,6 +2,7 @@ import { recordCheck } from "@/services/trackTimeDuration";
 import trackTimeService, { machine } from "@/store/trackTimeMachine"
 
 export const startFast = (start_time: number, duration: number) => {
+    duration = duration<3600*1000?3600*1000:duration;
     // const duration = fastValues[0] * 3600 * 1000 + fastValues[1] * 60 * 1000
     const extra = {
         set_time: global.set_time,
@@ -35,6 +36,7 @@ export const endFast = (start_time: number) => {
 
 
 export const startSleep = (start_time: number, duration: number) => {
+    duration = duration<3600*1000?3600*1000:duration;
     // const duration = sleepValues[0] * 3600 * 1000 + sleepValues[1] * 60 * 1000
     const extra = {
         set_time: global.set_time,

+ 13 - 1
src/features/trackTimeDuration/components/ChooseScenario.tsx

@@ -12,7 +12,7 @@ import { useState } from "react";
 import { useReady } from "@tarojs/taro";
 import Taro from "@tarojs/taro";
 import { useDispatch, useSelector } from "react-redux";
-import { setScenario, setScenarioName } from "@/store/scenario";
+import { setScenario, setScenarioName, setStep } from "@/store/scenario";
 import { getPlans } from "@/services/trackTimeDuration";
 
 
@@ -27,12 +27,15 @@ export default function Component() {
         console.log(selScenario)
         if (selScenario) {
             if (selScenario.name == 'FAST_SLEEP'){
+                dispatch(setStep('sleep'))
                 setSelIndex(2)
             }
             else if (selScenario.name == 'SLEEP'){
+                dispatch(setStep('sleep'))
                 setSelIndex(1)
             }
             else {
+                dispatch(setStep('fast'))
                 setSelIndex(0)
             }
         }
@@ -108,6 +111,15 @@ export default function Component() {
     function handleItemSelect(index: number) {
         setSelIndex(index)
         dispatch(setScenario(scenarios[index]) as any)
+        if (index == 0){
+            dispatch(setStep('fast'))
+        }
+        else if (index == 1){
+            dispatch(setStep('sleep'))
+        }
+        else {
+            dispatch(setStep('sleep'))
+        }
         // dispatch(setScenarioName(scenarios[index].scenario) as any)
     }
 

+ 51 - 9
src/features/trackTimeDuration/components/Console.tsx

@@ -9,14 +9,14 @@ import Taro from "@tarojs/taro";
 import { AtFloatLayout } from "taro-ui";
 import LimitPickers from '@/components/LimitPickers';
 import { endFast, endSleep, startFast, startSleep } from "../actions/TrackTimeActions";
-import { pickerDurations } from "../hooks/Console";
+import { durationDatas, durationIndex, pickerDurations } from "../hooks/Console";
 import PickerViews from "@/components/PickerViews";
 
 export default function Component() {
     const [key, setKey] = useState('');
     const [value, setValue] = useState('');
     const user = useSelector((state: any) => state.user);
-
+    // const common = useSelector((state: any) => state.common);
     const [isFast, setIsFast] = useState(true);
     const [fastValues, setFastValues] = useState<number[]>([0, 0]);
     const [sleepValues, setSleepValues] = useState<number[]>([0, 0]);
@@ -26,8 +26,10 @@ export default function Component() {
     const [sleepStr, setSleepStr] = useState('00:00');
     const [isOpen, setIsOpen] = useState(false);
     const [showModal, setShowModal] = useState(false);
-    const [fastPickerValue, setFastPickerValue] = useState([0])
-    const [sleepPickerValue, setSleepPickerValue] = useState([0])
+    const [fastPickerValue, setFastPickerValue] = useState([0,0])
+    const [sleepPickerValue, setSleepPickerValue] = useState([0,0])
+
+    // const [pickerValue, setPickerValue] = useState([0,0])
 
     // const pickerDurations = pickerDurations();
 
@@ -91,7 +93,8 @@ export default function Component() {
                 setFastStr(fastTime);
                 var fastCount = current_record.fast.target_end_time - current_record.fast.target_start_time
                 setFastDuration(fastCount)
-                setFastPickerValue([fastCount / 60000 / 5 - 12])
+                // setFastPickerValue(durationIndex(current_record.fast.target_start_time, current_record.fast.target_end_time, common))
+                // setFastPickerValue([fastCount / 60000 / 5 - 12])
             }
 
             if (current_record.sleep) {
@@ -106,8 +109,8 @@ export default function Component() {
                 var sleepCount = current_record.sleep.target_end_time - current_record.sleep.target_start_time
 
                 setSleepDuration(sleepCount)
-
-                setSleepPickerValue([sleepCount / 60000 / 5 - 12])
+                // setSleepPickerValue(durationIndex(current_record.sleep.target_start_time, current_record.sleep.target_end_time, common))
+                // setSleepPickerValue([sleepCount / 60000 / 5 - 12])
             }
         }
     }
@@ -213,13 +216,41 @@ export default function Component() {
         })
     }
 
+    function durationFormate() {
+        if (isFast) {
+            var t = fastDuration / 60000
+            var hour = Math.floor(t / 60)
+            var minute = Math.floor(t % 60)
+            return `${hour > 0 ? hour + '小时' : ''}${minute > 0 ? minute + '分钟' : ''}`
+        }
+        else {
+            var t = sleepDuration / 60000
+            var hour = Math.floor(t / 60)
+            var minute = Math.floor(t % 60)
+            return `${hour > 0 ? hour + '小时' : ''}${minute > 0 ? minute + '分钟' : ''}`
+        }
+
+    }
+
+    function showDurationPicker() {
+
+    }
+
     if (!user.isLogin) {
         return <View style={{ display: 'flex', flexDirection: 'column', width: '100%', alignItems: 'center' }}>
-            <PickerViews onChange={() => { }} items={[pickerDurations()]} value={[12 * 15]} />
+            <Text>16:00</Text>
+            {/* <PickerViews onChange={() => { }} items={[pickerDurations()]} value={[12 * 15]} /> */}
             {/* <TimePickers time={isFast ? fastStr : sleepStr} content="" change={handlePickerChange} isPickerView={true} /> */}
             <Text style={{ color: '#AAFF00' }} onClick={login}>Start Fast</Text>
         </View>
     }
+
+    const [isOpenDurationPicker, setIsOpenDurationPicker] = useState(false)
+    function durationPickerContent() {
+        return <View style={{ color: '#000' }}>
+            {/* <PickerViews onChange={durationChange} items={durationDatas(common)} value={isFast?fastPickerValue:sleepPickerValue} height={200} showBtns={true} onCancel={() => { setIsOpenDurationPicker(false) }} /> */}
+        </View>
+    }
     return (
         <View style={{ display: 'flex', flexDirection: 'column', width: '100%', alignItems: 'center' }}>
             {
@@ -237,7 +268,8 @@ export default function Component() {
             }
             {
                 (value == 'ONGOING1' || value == 'WAIT_FOR_START') &&
-                <PickerViews onChange={durationChange} items={[pickerDurations()]} value={isFast ? [fastPickerValue] : [sleepPickerValue]} />
+                <Text onClick={showDurationPicker}>{durationFormate()}</Text>
+                // <PickerViews onChange={durationChange} items={[pickerDurations()]} value={isFast ? [fastPickerValue] : [sleepPickerValue]} />
                 // <TimePickers time={isFast ? fastStr : sleepStr} content="" change={handlePickerChange} isPickerView={true} />
             }
             {
@@ -277,6 +309,16 @@ export default function Component() {
                     }
                 </AtFloatLayout>
             }
+            <AtFloatLayout
+                isOpened={isOpenDurationPicker}
+                onClose={() => {
+                    setIsOpenDurationPicker(false)
+                }}
+                title="">
+                {
+                    durationPickerContent()
+                }
+            </AtFloatLayout>
 
         </View>
     )

+ 73 - 28
src/features/trackTimeDuration/components/SetSchedule.tsx

@@ -12,13 +12,19 @@ import Footer from "@/components/Footer";
 import PickerViews from "@/components/PickerViews";
 import { AtFloatLayout } from "taro-ui";
 import "taro-ui/dist/style/components/float-layout.scss";
-import { pickerDurations } from "../hooks/Console";
+import { durationDatas, durationIndex, durationTime, pickerDurations } from "../hooks/Console";
+import { TimeFormatter } from "@/utils/time_format";
 
 export default function Component() {
+  const isFastFirst = false;
   const dispatch = useDispatch();
   const scenario = useSelector((state: any) => state.scenario);
-  const [pickerValue, setPickerValue] = useState(0)
+  const common = useSelector((state: any) => state.common);
+
   const [isOpen, setIsOpen] = useState(false)
+
+  // const [count,setCount] = useState(0)
+  const [beginChange, setBeginChange] = useState(true)
   var scheduleObj: { start_time: any; end_time: any; };
   if (scenario.name == 'FAST') {
     scheduleObj = scenario.schedule.fast
@@ -37,6 +43,10 @@ export default function Component() {
 
   const [startTime, setStartTime] = useState(scheduleObj.start_time)
   const [endTime, setEndTime] = useState(scheduleObj.end_time)
+  const [pickerValue, setPickerValue] = useState(durationIndex(scheduleObj.start_time, scheduleObj.end_time, common))
+
+  const [hours, setHours] = useState(durationTime(scheduleObj.start_time, scheduleObj.end_time)[0])
+  const [minutes, setMinutes] = useState(durationTime(scheduleObj.start_time, scheduleObj.end_time)[1])
 
   function start() {
     if (scenario.name == 'FAST' || scenario.name == 'SLEEP') {
@@ -59,44 +69,71 @@ export default function Component() {
       })
     }
     else {
-      if (scenario.step == 'fast') {
+      if ((scenario.step == 'fast' && isFastFirst) || (scenario.step == 'sleep' && !isFastFirst)) {
         var obj = JSON.parse(JSON.stringify(scenario))
-        obj.schedule.fast = {
-          start_time: startTime,
-          end_time: endTime,
+        if (isFastFirst) {
+          obj.schedule.fast = {
+            start_time: startTime,
+            end_time: endTime,
+          }
+          dispatch(setStep('sleep'))
+          dispatch(setScenario(obj))
         }
-        dispatch(setStep('sleep'))
-        dispatch(setScenario(obj))
+        else {
+          obj.schedule.sleep = {
+            start_time: startTime,
+            end_time: endTime,
+          }
+          dispatch(setStep('fast'))
+          dispatch(setScenario(obj))
+        }
+
         Taro.navigateTo({
           url: '/pages/SetSchedule'
         })
       }
       else {
-        setPlan({
-          scenario: scenario.name,
-          schedule: {
-            fast: {
-              start_time: scenario.schedule.fast.start_time,
-              end_time: scenario.schedule.fast.end_time,
-            }, sleep: {
-              start_time: startTime,
-              end_time: endTime,
-            }
-          }
-        }).then(res => {
-          dispatch(setStep('fast'))
-          Taro.navigateBack({ delta: 4 })
-        })
+        commit()
       }
     }
   }
 
+  function commit() {
+    setPlan({
+      scenario: scenario.name,
+      schedule: {
+        fast: {
+          start_time: isFastFirst ? scenario.schedule.fast.start_time : startTime,
+          end_time: isFastFirst ? scenario.schedule.fast.end_time : endTime,
+        }, sleep: {
+          start_time: !isFastFirst ? scenario.schedule.sleep.start_time : startTime,
+          end_time: !isFastFirst ? scenario.schedule.sleep.end_time : endTime,
+          // start_time: startTime,
+          // end_time: endTime,
+        }
+      }
+    }).then(res => {
+      dispatch(setStep('fast'))
+      Taro.navigateBack({ delta: 4 })
+    })
+  }
+
   function onStartTimeChange(e: string) {
+    setBeginChange(true)
     setStartTime(e)
+
+    setPickerValue(durationIndex(e, endTime, common))
+    setHours(durationTime(e, endTime)[0])
+    setMinutes(durationTime(e, endTime)[1])
   }
 
   function onEndTimeChange(e: string) {
+    setBeginChange(false)
     setEndTime(e)
+
+    setPickerValue(durationIndex(startTime, e, common))
+    setHours(durationTime(startTime, e)[0])
+    setMinutes(durationTime(startTime, e)[1])
   }
 
   useReady(() => {
@@ -111,14 +148,22 @@ export default function Component() {
   }
 
   function durationChange(e) {
-    var count = e[0] * 5 + 60;
-    setPickerValue(e[0])
+    var list = durationDatas(common)
+    setHours(list[0][e[0]])
+    setMinutes(list[1][e[1]])
+    setPickerValue(e)
     setIsOpen(false)
+    if (beginChange) {
+      setEndTime(TimeFormatter.calculateTimeByTimeRange(list[0][e[0]] * 60 + list[1][e[1]], startTime, true));
+    }
+    else {
+      setStartTime(TimeFormatter.calculateTimeByTimeRange(list[0][e[0]] * 60 + list[1][e[1]], endTime, false));
+    }
   }
 
   function layoutContent() {
-    return <View style={{color:'#000'}}>
-      <PickerViews onChange={durationChange} items={[pickerDurations()]} value={[pickerValue]} height={200} showBtns={true} onCancel={()=>{setIsOpen(false)}}/>
+    return <View style={{ color: '#000' }}>
+      <PickerViews onChange={durationChange} items={durationDatas(common)} value={pickerValue} height={200} showBtns={true} onCancel={() => { setIsOpen(false) }} />
     </View>
   }
 
@@ -137,7 +182,7 @@ export default function Component() {
 
       </View>
       <View style={{ flex: 1 }} />
-      <Text className="duration" onClick={()=>{setIsOpen(true)}}>16 hours 00 mins</Text>
+      <Text className="duration" onClick={() => { setIsOpen(true) }}>{hours > 0 ? hours + ' hours ' : ''}{minutes > 0 ? minutes + ' minutes' : ''}</Text>
     </View>
 
     <Footer child={

+ 85 - 1
src/features/trackTimeDuration/hooks/Console.tsx

@@ -1,10 +1,94 @@
+import { TimeFormatter } from "@/utils/time_format";
+import { useSelector } from "react-redux";
+
+// const common = useSelector((state: any) => state.common);
+
 export const pickerDurations = () => {
     const list: string[] = [];
     for (let i = 0; i <= 22 * 12; i++) {
-        var count = i * 5+60;
+        var count = i * 5 + 60;
         var hour = Math.floor(count / 60);
         var minute = count % 60;
         list.push(`${hour > 0 ? hour + '小时' : ''}${minute > 0 ? minute + '分钟' : ''}`);
     }
     return list;
+}
+
+
+//获取picker的取值范围,返回二维数组
+export const durationDatas = (common: any) => {
+    var min: number = 1
+    var max: number = 23
+    var step: number = 5
+    
+    if (common.duration) {
+        min = common.duration.min
+        max = common.duration.max
+        step = common.duration.step
+    }
+    var minutes: number[] = []
+    for (let i = 0; i < 60; i += step) {
+        minutes.push(i)
+    }
+    var hours: number[] = []
+    for (let i = min; i <= max; i++) {
+        hours.push(i)
+    }
+    return [hours, minutes]
+}
+
+//通过开始时间和结束时间计算picker的index值,返回格式为[hourIndex,minuteIndex]
+export const durationIndex = (start: string, end: string,common: any) => {
+    if (start.indexOf(':') == -1) {
+        start = TimeFormatter.formatTime(new Date(parseInt(start+'')));
+    }
+    if (end.indexOf(':') == -1) {
+        end = TimeFormatter.formatTime(new Date(parseInt(end+'')));
+    }
+
+    var min: number = 1
+    var max: number = 23
+    var step: number = 5
+    // const common = useSelector((state: any) => state.common);
+    if (common.duration) {
+        min = common.duration.min
+        max = common.duration.max
+        step = common.duration.step
+    }
+
+
+    var startHour = parseInt(start.split(':')[0])
+    var startMinute = parseInt(start.split(':')[1])
+    var endHour = parseInt(end.split(':')[0])
+    var endMinute = parseInt(end.split(':')[1])
+    var startCount = startHour * 60 + startMinute
+    var endCount = endHour * 60 + endMinute
+    if (endCount < startCount) {
+        endCount += 24 * 60
+    }
+    var leftCount = endCount - startCount
+    var leftHour = Math.floor(leftCount / 60)
+    var leftMinute = leftCount % 60
+    leftHour = leftHour < min ? min : leftHour
+    leftHour = leftHour > max ? max : leftHour
+    return [leftHour - min, leftMinute / step]
+}
+
+//通过开始时间和结束时间计算duration,返回格式为[hour,minute]
+export const durationTime = (start: string, end: string) => {
+    var startHour = parseInt(start.split(':')[0])
+    var startMinute = parseInt(start.split(':')[1])
+    var endHour = parseInt(end.split(':')[0])
+    var endMinute = parseInt(end.split(':')[1])
+    var startCount = startHour * 60 + startMinute
+    var endCount = endHour * 60 + endMinute
+    if (endCount < startCount) {
+        endCount += 24 * 60
+    }
+    var leftCount = endCount - startCount
+    var leftHour = Math.floor(leftCount / 60)
+    var leftMinute = leftCount % 60
+    // leftHour = leftHour < 1 ? 1 : leftHour
+    // leftHour = leftHour > 23 ? 23 : leftHour
+    return [leftHour, leftMinute]
 }

+ 21 - 0
src/pages/RecordsHistory.tsx

@@ -0,0 +1,21 @@
+import { View } from "@tarojs/components";
+import { useReady } from "@tarojs/taro";
+
+export default function Page() {
+    // const router = useRouter();
+
+    // useEffect(() => {
+    //   console.log(router.params);
+    // }, [router.params]);
+
+    useReady(()=>{
+        getHistory()
+    })
+
+    function getHistory(){
+        
+    }
+
+    return <View className="container">
+    </View>;
+}

+ 12 - 2
src/pages/clock.tsx

@@ -9,7 +9,7 @@ import Rings from '@components/Rings';
 import { useDispatch, useSelector } from 'react-redux';
 import { getInfoSuccess } from '@/store/user';
 import { wxPubFollow } from '@/services/permission';
-import { staticResources } from '@/services/common';
+import { gobalConfigs, staticResources } from '@/services/common';
 import { use } from 'i18next';
 import Clocks from '@/features/trackTimeDuration/components/Clock';
 import Console from '@/features/trackTimeDuration/components/Console';
@@ -42,6 +42,8 @@ export default function IndexPage() {
   global.dispatch = dispatch;
   useEffect(() => {
     dispatch(staticResources() as any);
+    dispatch(gobalConfigs() as any);
+    // dispatch(gobalConfigs() as any);
     trackTimeService.onTransition(state => {
       if ((state.value as any).FAST_SLEEP == 'COMPLETED' ||
         (state.value as any).FAST == 'ONGOING' ||
@@ -88,6 +90,7 @@ export default function IndexPage() {
       setTimeout(() => {
         checkWXPubFollow()
         getCheckData()
+        
       }, 200)
     }
   })
@@ -229,13 +232,20 @@ export default function IndexPage() {
       <TitleBar />
       <Clocks />
       <View className='console_box'>
-        <Console />
+        {/* <Console /> */}
       </View>
 
       <More ref={global.moreRef}/>
       {
         !isFollowed && user.isLogin && <Text style={{ textAlign: 'center', width: '100%' }} onClick={() => followWxPub()}>去关注公众号</Text>
       }
+      {
+        user.isLogin && <Text onClick={()=>{
+          Taro.navigateTo({
+            url:'/pages/RecordsHistory'
+          })
+        }}>查看全部记录</Text>
+      }
       {
         checkData && schedule()
       }

+ 13 - 2
src/services/common.tsx

@@ -1,5 +1,5 @@
-import { setResources } from "@/store/common";
-import { API_STATIC_RESOURCES } from "./http/api";
+import { setResources,setConfigs } from "@/store/common";
+import { API_GLOBAL_CONFIGS, API_STATIC_RESOURCES } from "./http/api";
 import { request } from "./http/request";
 
 
@@ -11,4 +11,15 @@ export const staticResources = () => (dispatch: any) => {
         dispatch(setResources(res));
     })
 
+}
+
+export const gobalConfigs = () =>(dispatch:any) =>{
+    request({
+        url: API_GLOBAL_CONFIGS, method: 'GET', data: {
+            keys:'time_duration'
+        }
+    }).then(res => {
+        // resolve(res);
+        dispatch(setConfigs(res));
+    })
 }

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

@@ -13,6 +13,7 @@ export const API_REGISTER = `${baseUrl}/api/user/account`
 export const API_LOGOUT = `${baseUrl}/api/user/logout`
 export const API_CLEAR_USER = `${baseUrl}/api/user/account`
 export const API_STATIC_RESOURCES = `${baseUrl}/api/static-resource-urls`
+export const API_GLOBAL_CONFIGS = `${baseUrl}/api/system/global-configs`
 export const API_USER_INFO = `${baseUrl}/api/user/info`
 export const API_CLEAR_FAST = `${baseUrl}/api/clear/fasting`
 export const API_CLEAR_SLEEP = `${baseUrl}/api/sleep/clear-my-data`

+ 1 - 0
src/services/http/request.ts

@@ -66,6 +66,7 @@ export async function request<T>(param: RequestParam): Promise<T> {
                     resolve(resp);
                 }
                 else if (statusCode == 401) {
+                    debugger
                     global.dispatch(logoutSuccess());
                 }
                 else {

+ 21 - 0
src/services/trackTimeDuration.tsx

@@ -46,6 +46,17 @@ export const getClocks = () => {
     })
 }
 
+export const getHistory = ()=>{
+    return new Promise((resolve) => {
+        request({
+            url: API_FAST_CLOCKS, method: 'GET', data: {}
+        }).then(res => {
+            resolve(res);
+        })
+    })
+
+}
+
 export const recordCheck = (params: Record<string, any> | undefined) => {
     return new Promise((resolve) => {
         request({
@@ -54,4 +65,14 @@ export const recordCheck = (params: Record<string, any> | undefined) => {
             resolve(res);
         })
     })
+}
+
+export const delRecord = (id: string) => {
+    return new Promise((resolve) => {
+        request({
+            url: API_FAST_CLOCKS + '/' + id, method: 'DELETE', data: {}
+        }).then(res => {
+            resolve(res);
+        })
+    })
 }

+ 2 - 0
src/services/user.tsx

@@ -64,6 +64,7 @@ export const register = (name: string, email: string, password: string) => (disp
 }
 
 export const logout = () => (dispatch: any) => {
+    debugger
     request({
         url: API_LOGOUT, method: 'GET', data: {}
     }).then(_ => {
@@ -72,6 +73,7 @@ export const logout = () => (dispatch: any) => {
 }
 
 export const clear = () => (dispatch: any) => {
+    debugger
     request({
         url: API_CLEAR_USER, method: 'DELETE', data: {}
     }).then(_ => {

+ 24 - 1
src/store/common.tsx

@@ -2,10 +2,18 @@ import { createSlice } from "@reduxjs/toolkit";
 
 interface CommonState {
     resources: [] | null;
+    configs: any | null;
+    duration: {
+        min: number;
+        max: number;
+        step: number;
+    } | null;
 }
 
 const initialState: CommonState = {
     resources: [],
+    configs: null,
+    duration: null
 }
 
 const commonSlice = createSlice({
@@ -14,9 +22,24 @@ const commonSlice = createSlice({
     reducers: {
         setResources(state, action) {
             state.resources = action.payload;
+        },
+        setConfigs(state, action) {
+            state.configs = action.payload.data;
+            if (state.configs) {
+                var list = state.configs
+                list.map(item => {
+                    if (item.key == 'time_duration') {
+                        state.duration = {
+                            min: item.value.min_time / 60,
+                            max: item.value.max_time / 60,
+                            step: item.value.step_time
+                        }
+                    }
+                })
+            }
         }
     }
 });
 
 export default commonSlice.reducer;
-export const { setResources } = commonSlice.actions;
+export const { setResources, setConfigs } = commonSlice.actions;

+ 2 - 2
src/store/scenario.tsx

@@ -3,7 +3,7 @@ import { createSlice } from "@reduxjs/toolkit";
 
 interface ScenarioState {
     name: string | null;
-    step:'fast',
+    step:'sleep',
     schedule: {
         fast: {
             start_time: string | null;
@@ -18,7 +18,7 @@ interface ScenarioState {
 
 const initialState: ScenarioState = {
     name: null,
-    step:'fast',
+    step:'sleep',
     schedule: null,
 }
 

+ 2 - 0
src/store/user.tsx

@@ -47,6 +47,7 @@ const userSlice = createSlice({
             Taro.setStorage({ key: 'userData', data: JSON.stringify(action.payload) });
         },
         logoutSuccess(state) {
+            debugger
             state.id = null;
             state.nickname = null;
             state.avatar = null;
@@ -57,6 +58,7 @@ const userSlice = createSlice({
             Taro.clearStorage();
         },
         clearSuccess(state) {
+            debugger
             state.id = null;
             state.nickname = null;
             state.avatar = null;

+ 25 - 8
src/utils/time_format.ts

@@ -52,7 +52,7 @@ export class TimeFormatter {
   }
 
   //计算时间间隔
-  static calculateTimeDifference(startTimestamp: number, endTimestamp: number,ingoreSeconds?:boolean): string {
+  static calculateTimeDifference(startTimestamp: number, endTimestamp: number, ingoreSeconds?: boolean): string {
     const diff = Math.abs(endTimestamp - startTimestamp);
     // 计算小时、分钟和秒数
     const hours = Math.floor(diff / (1000 * 60 * 60));
@@ -70,9 +70,9 @@ export class TimeFormatter {
     }
   }
 
-  static formateTime(timestamp:number){
+  static formateTime(timestamp: number) {
     const date = new Date(timestamp);
-    return `${TimeFormatter.padZero(date.getMonth()+1)}-${TimeFormatter.padZero(date.getDate())} ${TimeFormatter.padZero(date.getHours())}:${TimeFormatter.padZero(date.getMinutes())}:${TimeFormatter.padZero(date.getSeconds())}`;
+    return `${TimeFormatter.padZero(date.getMonth() + 1)}-${TimeFormatter.padZero(date.getDate())} ${TimeFormatter.padZero(date.getHours())}:${TimeFormatter.padZero(date.getMinutes())}:${TimeFormatter.padZero(date.getSeconds())}`;
   }
 
   static formateHourMinute(startTimestamp: number, endTimestamp: number): string {
@@ -80,12 +80,12 @@ export class TimeFormatter {
     // 计算小时、分钟和秒数
     const hours = Math.floor(diff / (1000 * 60 * 60));
     const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
-    return (hours<10?`0${hours}`:`${hours}`)+':'+(minutes<10?`0${minutes}`:`${minutes}`);
+    return (hours < 10 ? `0${hours}` : `${hours}`) + ':' + (minutes < 10 ? `0${minutes}` : `${minutes}`);
   }
 
-  static countdown=(dt: number): string => {
+  static countdown = (dt: number): string => {
     const end = Date.now();
-    const time = end>dt?Math.floor((end-dt)/1000):Math.ceil((dt-end)/1000)//Math.ceil((end>dt?end-dt:dt-end)/1000);
+    const time = end > dt ? Math.floor((end - dt) / 1000) : Math.ceil((dt - end) / 1000)//Math.ceil((end>dt?end-dt:dt-end)/1000);
     const hours = Math.floor(time / 3600);
     const minutes = Math.floor((time % 3600) / 60);
     const seconds = Math.floor(time % 60);
@@ -95,7 +95,7 @@ export class TimeFormatter {
   //计算正计时
   static formateTimeNow = (dt: number): string => {
     const end = Date.now();
-    const time = Math.floor((end>dt?end-dt:dt-end)/1000);
+    const time = Math.floor((end > dt ? end - dt : dt - end) / 1000);
     const hours = Math.floor(time / 3600);
     const minutes = Math.floor((time % 3600) / 60);
     const seconds = Math.floor(time % 60);
@@ -104,5 +104,22 @@ export class TimeFormatter {
 
   static padZero = (num: number): string => {
     return num.toString().padStart(2, '0');
-  }; 
+  };
+
+  //根据时间段和一个时间,推算另外一个时间
+  static calculateTimeByTimeRange = (timeRange: number, strTime: string, isStart: boolean): string => {
+    var list = strTime.split(':');
+    var time = parseInt(list[0]) * 60 + parseInt(list[1]);
+    if (isStart) {
+      time = time + timeRange;
+    }
+    else {
+      time = time - timeRange;
+    }
+    time = time < 0 ? time + 24 * 60 : time;
+    time = time >= 24 * 60 ? time - 24 * 60 : time;
+    var hour = Math.floor(time / 60);
+    var minute = time % 60;
+    return `${TimeFormatter.padZero(hour)}:${TimeFormatter.padZero(minute)}`;
+  }
 }