Leon 2 lat temu
rodzic
commit
9aa17431c2

BIN
src/assets/images/notice_switch_select.png


BIN
src/assets/images/notice_switch_unselect.png


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

@@ -20,7 +20,7 @@ const Component = forwardRef((props: {
         if (props.showBtns) {
             return;
         }
-        props.onChange(e.detail.value)
+        // props.onChange(e.detail.value)
     }
 
     function alphaToHex(alpha) {

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

@@ -3,6 +3,7 @@ import { Picker, Text, PickerView, PickerViewColumn, View } from "@tarojs/compon
 import { useEffect, useState } from "react";
 
 export default function Component(props: { time: string, content: string, change: Function, isPickerView?: boolean }) {
+    debugger
     var [hour, minute] = props.time.split(':').map(x => parseInt(x))
     const m = Math.round(minute / 5) * 5;
     const v = [hour, m / 5];

+ 41 - 0
src/features/common/TimePicker.tsx

@@ -0,0 +1,41 @@
+import PickerViews from "@/components/input/PickerViews";
+import {  PickerView, PickerViewColumn, View } from "@tarojs/components";
+
+import { useEffect, useState } from "react";
+
+export default function Component(props: { time: string, confirm: Function,cancel:Function }) {
+    var [hour, minute] = props.time.split(':').map(x => parseInt(x))
+    const m = Math.round(minute / 5) * 5;
+    const v = [hour, m / 5];
+
+    const [dt, setDt] = useState(v)
+
+    useEffect(() => {
+        var [hour, minute] = props.time.split(':').map(x => parseInt(x))
+        const m = Math.round(minute / 5) * 5;
+        const v = [hour, m / 5];
+        setDt(v)
+    }, [props.time])
+
+
+    const hours: number[] = [];
+
+
+    for (let i = 0; i <= 23; i++) {
+        hours.push(i);
+    }
+
+    const minutes: number[] = [];
+    for (let i = 0; i <= 11; i++) {
+        minutes.push(i * 5);
+    }
+
+    function onPickerChange(e) {
+        var strHour = hours[e[0]] < 10 ? '0' + hours[e[0]] : hours[e[0]]
+        var strMinute = minutes[e[1]] < 10 ? '0' + minutes[e[1]] : minutes[e[1]]
+        console.log(strHour + ':' + strMinute)
+        props.confirm(strHour + ':' + strMinute)
+    }
+
+    return <PickerViews value={dt} onChange={onPickerChange} items={[hours,minutes]} onCancel={()=>{props.cancel()}}/>
+}

+ 31 - 4
src/features/trackTimeDuration/components/SetSchedule.tsx

@@ -15,6 +15,7 @@ import { durationDatas, durationIndex, durationTime, pickerDurations } from "../
 import { TimeFormatter } from "@/utils/time_format";
 import Modal from "@/components/layout/Modal";
 import Dial from './Dial';
+import TimePicker from "@/features/common/TimePicker";
 
 export default function Component() {
   const isFastFirst = true;
@@ -25,6 +26,7 @@ export default function Component() {
   const common = useSelector((state: any) => state.common);
 
   const [isOpen, setIsOpen] = useState(false)
+  const [isTimeOpen,setIsTimeOpen] = useState(false)
 
   const pickerRef = useRef<any>(null);
   // const [count,setCount] = useState(0)
@@ -57,6 +59,7 @@ export default function Component() {
 
   const [hours, setHours] = useState(durationTime(scheduleObj.start_time, scheduleObj.end_time)[0])
   const [minutes, setMinutes] = useState(durationTime(scheduleObj.start_time, scheduleObj.end_time)[1])
+  const [chooseStart,setChooseStart] = useState(true)
 
   useReady(() => {
     if (global.schedule_fast && scenario.step == 'fast') {
@@ -167,6 +170,7 @@ export default function Component() {
   }
 
   function onStartTimeChange(e: string) {
+    setIsTimeOpen(false)
     setBeginChange(true)
     setStartTime(e)
 
@@ -179,6 +183,7 @@ export default function Component() {
   }
 
   function onEndTimeChange(e: string) {
+    setIsTimeOpen(false)
     setBeginChange(false)
     setEndTime(e)
 
@@ -263,17 +268,34 @@ export default function Component() {
   function layoutContent() {
     return <PickerViews ref={pickerRef} onChange={durationChange} items={durationDatas(common)} value={pickerValue} height={200} showBtns={true} onCancel={() => { setIsOpen(false) }} />
   }
+  
+
+  function timeContent(){
+    console.log(chooseStart)
+    return <TimePicker time={chooseStart?startTime:endTime} confirm={chooseStart?onStartTimeChange:onEndTimeChange} cancel={()=>{setIsTimeOpen(false)}}/>
+      // return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
+      //     <PickerViews  onChange={durationChange} items={durationDatas(common)} value={isFast ? fastPickerValue : sleepPickerValue} showBtns={true} onCancel={() => { setIsOpenDurationPicker(false) }} />
+      // </View>
+  }
 
   return <View >
     {/* <Text>场景名称{scenario.name}</Text> */}
 
     <View className="box">
       <View className="header">
-        <View className="item">
-          <TimePickers time={startTime} content={scenario.step == 'fast' ? 'Fast starts\n' + startTime : 'Sleep starts\n' + startTime} change={onStartTimeChange} />
+        <View className="item" onClick={()=>{
+          setChooseStart(true)
+          setIsTimeOpen(true)
+        }}>
+          <Text>{scenario.step == 'fast' ? 'Fast starts\n' + startTime : 'Sleep starts\n' + startTime}</Text>
+          {/* <TimePickers time={startTime} content={scenario.step == 'fast' ? 'Fast starts\n' + startTime : 'Sleep starts\n' + startTime} change={onStartTimeChange} /> */}
         </View>
-        <View className="item">
-          <TimePickers time={endTime} content={scenario.step == 'fast' ? 'Fast ends\n' + endTime : 'Sleep ends\n' + endTime} change={onEndTimeChange} />
+        <View className="item" onClick={()=>{
+          setChooseStart(false)
+          setIsTimeOpen(true)
+        }}>
+          <Text>{scenario.step == 'fast' ? 'Fast ends\n' + endTime : 'Sleep ends\n' + endTime}</Text>
+          {/* <TimePickers time={endTime} content={scenario.step == 'fast' ? 'Fast ends\n' + endTime : 'Sleep ends\n' + endTime} change={onEndTimeChange} /> */}
         </View>
 
 
@@ -293,6 +315,11 @@ export default function Component() {
         durationChange(pickerRef.current.getConfirmData())
       }}/>
     }
+    {
+      isTimeOpen && <Modal children={timeContent()} dismiss={() => setIsTimeOpen(false)} confirm={()=>{
+        setIsTimeOpen(false)
+      }}/>
+    }
 
 
     {/* <AtFloatLayout