|
@@ -1,14 +1,12 @@
|
|
|
-import { recordCheck } from "@/services/trackTimeDuration";
|
|
|
|
|
|
|
+
|
|
|
import { View, Text, PickerView } from "@tarojs/components";
|
|
import { View, Text, PickerView } from "@tarojs/components";
|
|
|
-import trackTimeService, { machine } from "@/store/trackTimeMachine"
|
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
-import TimePickers from '@/components/input/TimePickers'
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
import { useSelector } from "react-redux";
|
|
|
import Taro from "@tarojs/taro";
|
|
import Taro from "@tarojs/taro";
|
|
|
import LimitPickers from '@/components/input/LimitPickers';
|
|
import LimitPickers from '@/components/input/LimitPickers';
|
|
|
import { endFast, endSleep, startFast, startSleep } from "../actions/TrackTimeActions";
|
|
import { endFast, endSleep, startFast, startSleep } from "../actions/TrackTimeActions";
|
|
|
-import { durationDatas, durationIndex, getTitle, pickerDurations } from "../hooks/Console";
|
|
|
|
|
|
|
+import { durationDatas, durationIndex, getColor, getTitle, textAlpha, textNextStepAlpha } from "../hooks/Console";
|
|
|
import PickerViews from "@/components/input/PickerViews";
|
|
import PickerViews from "@/components/input/PickerViews";
|
|
|
import Modal from "@/components/layout/Modal";
|
|
import Modal from "@/components/layout/Modal";
|
|
|
import Stepper from "@/components/input/Stepper";
|
|
import Stepper from "@/components/input/Stepper";
|
|
@@ -16,142 +14,91 @@ import { EndFastBtn, EndSleepBtn, StartFastBtn, StartSleepBtn } from "@/features
|
|
|
import Box from "@/components/layout/Box";
|
|
import Box from "@/components/layout/Box";
|
|
|
import './Console.scss'
|
|
import './Console.scss'
|
|
|
|
|
|
|
|
-export default function Component() {
|
|
|
|
|
|
|
+export default function Component(props: { isNextStep?: boolean }) {
|
|
|
const scenario = useSelector((state: any) => state.scenario);
|
|
const scenario = useSelector((state: any) => state.scenario);
|
|
|
- const [key, setKey] = useState('');
|
|
|
|
|
- const [value, setValue] = useState('');
|
|
|
|
|
|
|
+ const time = useSelector((state: any) => state.time);
|
|
|
const user = useSelector((state: any) => state.user);
|
|
const user = useSelector((state: any) => state.user);
|
|
|
const common = useSelector((state: any) => state.common);
|
|
const common = useSelector((state: any) => state.common);
|
|
|
const [isFast, setIsFast] = useState(true);
|
|
const [isFast, setIsFast] = useState(true);
|
|
|
- const [fastValues, setFastValues] = useState<number[]>([0, 0]);
|
|
|
|
|
- const [sleepValues, setSleepValues] = useState<number[]>([0, 0]);
|
|
|
|
|
const [fastDuration, setFastDuration] = useState<number>(0);
|
|
const [fastDuration, setFastDuration] = useState<number>(0);
|
|
|
const [sleepDuration, setSleepDuration] = useState<number>(0);
|
|
const [sleepDuration, setSleepDuration] = useState<number>(0);
|
|
|
- const [fastStr, setFastStr] = useState('00:00');
|
|
|
|
|
- const [sleepStr, setSleepStr] = useState('00:00');
|
|
|
|
|
- const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
- const [showModal, setShowModal] = useState(false);
|
|
|
|
|
|
|
+
|
|
|
const [fastPickerValue, setFastPickerValue] = useState([0, 0])
|
|
const [fastPickerValue, setFastPickerValue] = useState([0, 0])
|
|
|
const [sleepPickerValue, setSleepPickerValue] = useState([0, 0])
|
|
const [sleepPickerValue, setSleepPickerValue] = useState([0, 0])
|
|
|
- const [isOpenDurationPicker, setIsOpenDurationPicker] = useState(false)
|
|
|
|
|
const limitPickerRef = useRef(null)
|
|
const limitPickerRef = useRef(null)
|
|
|
const durationPickerRef = useRef(null)
|
|
const durationPickerRef = useRef(null)
|
|
|
|
|
|
|
|
- // const [pickerValue, setPickerValue] = useState([0,0])
|
|
|
|
|
-
|
|
|
|
|
- // const pickerDurations = pickerDurations();
|
|
|
|
|
-
|
|
|
|
|
- // console.log(pickerDurations())
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- getStateDetail();
|
|
|
|
|
- }, [machine.context.checkData]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
getStateDetail();
|
|
getStateDetail();
|
|
|
- }, [machine.context.currentStatus])
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- trackTimeService.onTransition(state => {
|
|
|
|
|
- if ((state.value as any).FAST_SLEEP) {
|
|
|
|
|
- setKey('FAST_SLEEP');
|
|
|
|
|
- setValue((state.value as any).FAST_SLEEP);
|
|
|
|
|
- }
|
|
|
|
|
- if ((state.value as any).FAST) {
|
|
|
|
|
- setKey('FAST');
|
|
|
|
|
- setValue((state.value as any).FAST);
|
|
|
|
|
- }
|
|
|
|
|
- if ((state.value as any).SLEEP) {
|
|
|
|
|
- setKey('SLEEP');
|
|
|
|
|
- setValue((state.value as any).SLEEP);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }, []);
|
|
|
|
|
|
|
+ }, [time.fast, time.sleep, time.status, time.scenario]);
|
|
|
|
|
|
|
|
function getStateDetail() {
|
|
function getStateDetail() {
|
|
|
- var state = trackTimeService.getSnapshot().value
|
|
|
|
|
- if ((state as any).FAST_SLEEP) {
|
|
|
|
|
- setKey('FAST_SLEEP');
|
|
|
|
|
- setValue((state as any).FAST_SLEEP);
|
|
|
|
|
- if ((state as any).FAST_SLEEP == 'WAIT_FOR_START' || (state as any).FAST_SLEEP == 'ONGOING3') {
|
|
|
|
|
- setIsFast(true);
|
|
|
|
|
- }
|
|
|
|
|
- else if ((state as any).FAST_SLEEP == 'ONGOING1') {
|
|
|
|
|
- setIsFast(false);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (time.fast) {
|
|
|
|
|
+ var fastCount = time.fast.target_end_time - time.fast.target_start_time
|
|
|
|
|
+ setFastDuration(fastCount)
|
|
|
|
|
+ setFastPickerValue(durationIndex(time.fast.target_start_time, time.fast.target_end_time, common))
|
|
|
}
|
|
}
|
|
|
- if ((state as any).FAST) {
|
|
|
|
|
- setKey('FAST');
|
|
|
|
|
- setValue((state as any).FAST);
|
|
|
|
|
- setIsFast(true);
|
|
|
|
|
- }
|
|
|
|
|
- if ((state as any).SLEEP) {
|
|
|
|
|
- setKey('SLEEP');
|
|
|
|
|
- setValue((state as any).SLEEP);
|
|
|
|
|
- setIsFast(false);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (time.sleep) {
|
|
|
|
|
+ var sleepCount = time.sleep.target_end_time - time.sleep.target_start_time
|
|
|
|
|
+ setSleepDuration(sleepCount)
|
|
|
|
|
+ setSleepPickerValue(durationIndex(time.sleep.target_start_time, time.sleep.target_end_time, common))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var checkData = machine.context.checkData;
|
|
|
|
|
- if (checkData) {
|
|
|
|
|
- var current_record = (checkData as any).current_record;
|
|
|
|
|
- if (current_record.fast) {
|
|
|
|
|
- var fastTime = TimeFormatter.formateHourMinute(current_record.fast.target_start_time,
|
|
|
|
|
- current_record.fast.target_end_time);
|
|
|
|
|
- setFastValues(fastTime.split(':').map(x => parseInt(x)));
|
|
|
|
|
- setFastStr(fastTime);
|
|
|
|
|
- var fastCount = current_record.fast.target_end_time - current_record.fast.target_start_time
|
|
|
|
|
- setFastDuration(fastCount)
|
|
|
|
|
- setFastPickerValue(durationIndex(current_record.fast.target_start_time, current_record.fast.target_end_time, common))
|
|
|
|
|
- // setFastPickerValue([fastCount / 60000 / 5 - 12])
|
|
|
|
|
|
|
+ if (time.scenario == 'FAST') {
|
|
|
|
|
+ setIsFast(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (time.scenario == 'SLEEP') {
|
|
|
|
|
+ setIsFast(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ if (time.status == 'WAIT_FOR_START' || time.status == 'ONGOING3') {
|
|
|
|
|
+ setIsFast(true)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (current_record.sleep) {
|
|
|
|
|
- var sleepTime = TimeFormatter.formateHourMinute(current_record.sleep.target_start_time,
|
|
|
|
|
- current_record.sleep.target_end_time);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- setSleepValues(sleepTime.split(':').map(x => parseInt(x)));
|
|
|
|
|
-
|
|
|
|
|
- setSleepStr(sleepTime);
|
|
|
|
|
-
|
|
|
|
|
- var sleepCount = current_record.sleep.target_end_time - current_record.sleep.target_start_time
|
|
|
|
|
-
|
|
|
|
|
- setSleepDuration(sleepCount)
|
|
|
|
|
- setSleepPickerValue(durationIndex(current_record.sleep.target_start_time, current_record.sleep.target_end_time, common))
|
|
|
|
|
- // setSleepPickerValue([sleepCount / 60000 / 5 - 12])
|
|
|
|
|
|
|
+ else {
|
|
|
|
|
+ setIsFast(false)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
function showPicker() {
|
|
function showPicker() {
|
|
|
- setShowModal(true)
|
|
|
|
|
- setIsOpen(true)
|
|
|
|
|
global.set_time = new Date().getTime()
|
|
global.set_time = new Date().getTime()
|
|
|
- console.log(global.set_time)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ global.testInfotimer = setInterval(() => {
|
|
|
|
|
+ var node = (<Modal testInfo={testLayout()} children={layoutContent()} dismiss={() => {
|
|
|
|
|
+ global.showClockModal(false, null);
|
|
|
|
|
+ hidePicker()
|
|
|
|
|
+ }} confirm={() => {
|
|
|
|
|
+ hidePicker()
|
|
|
|
|
+ var picker = limitPickerRef.current;
|
|
|
|
|
+ pickerConfirm((picker as any).getConfirmData());
|
|
|
|
|
+ global.showClockModal(false, null);
|
|
|
|
|
+ }} />);
|
|
|
|
|
+ global.showClockModal(true, node);
|
|
|
|
|
+
|
|
|
|
|
+ }, 1000)
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function hidePicker() {
|
|
function hidePicker() {
|
|
|
- setIsOpen(false)
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- setShowModal(false)
|
|
|
|
|
- }, 1000)
|
|
|
|
|
|
|
+ global.showClockModal(false, null);
|
|
|
|
|
+ if (global.testInfotimer) {
|
|
|
|
|
+ clearInterval(global.testInfotimer)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testLayout() {
|
|
function testLayout() {
|
|
|
if (!user.test_user) {
|
|
if (!user.test_user) {
|
|
|
return <View />
|
|
return <View />
|
|
|
}
|
|
}
|
|
|
- var current_record = machine.context.checkData ? (machine.context.checkData as any).current_record : null;
|
|
|
|
|
- if (current_record == null) {
|
|
|
|
|
- return <View />
|
|
|
|
|
- }
|
|
|
|
|
var isStart = false;
|
|
var isStart = false;
|
|
|
- if (value == 'WAIT_FOR_START' || value == 'ONGOING1') {
|
|
|
|
|
|
|
+ if (time.status == 'WAIT_FOR_START' || time.status == 'ONGOING1') {
|
|
|
isStart = true
|
|
isStart = true
|
|
|
}
|
|
}
|
|
|
var isFast = false;
|
|
var isFast = false;
|
|
|
- switch (value) {
|
|
|
|
|
|
|
+ switch (time.status) {
|
|
|
case 'WAIT_FOR_START':
|
|
case 'WAIT_FOR_START':
|
|
|
case 'ONGOING':
|
|
case 'ONGOING':
|
|
|
{
|
|
{
|
|
@@ -173,7 +120,10 @@ export default function Component() {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (props.isNextStep){
|
|
|
|
|
+ isFast = true
|
|
|
|
|
+ isStart = false
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return <View style={{ color: '#fff', paddingTop: 30, paddingLeft: 30, display: 'flex', flexDirection: 'column' }}>
|
|
return <View style={{ color: '#fff', paddingTop: 30, paddingLeft: 30, display: 'flex', flexDirection: 'column' }}>
|
|
|
<Text>check scenario:{isFast ? 'fast' : 'sleep'}</Text>
|
|
<Text>check scenario:{isFast ? 'fast' : 'sleep'}</Text>
|
|
@@ -186,8 +136,8 @@ export default function Component() {
|
|
|
<Text style={{ marginTop: 30 }}>now:{TimeFormatter.formatTimestamp(new Date().getTime())}</Text>
|
|
<Text style={{ marginTop: 30 }}>now:{TimeFormatter.formatTimestamp(new Date().getTime())}</Text>
|
|
|
<Text>elapsed:{TimeFormatter.calculateTimeDifference(global.picker_time, new Date().getTime())}</Text>
|
|
<Text>elapsed:{TimeFormatter.calculateTimeDifference(global.picker_time, new Date().getTime())}</Text>
|
|
|
|
|
|
|
|
- <Text style={{ marginTop: 30 }}>real start:{isStart ? '-' : TimeFormatter.formatTimestamp(isFast ? current_record.fast.real_start_time : current_record.sleep.real_start_time)}</Text>
|
|
|
|
|
- <Text>real duration:{isStart ? '-' : TimeFormatter.calculateTimeDifference(isFast ? current_record.fast.real_start_time : current_record.sleep.real_start_time, new Date().getTime())}</Text>
|
|
|
|
|
|
|
+ <Text style={{ marginTop: 30 }}>real start:{isStart ? '-' : TimeFormatter.formatTimestamp(isFast ? time.fast.real_start_time : time.sleep.real_start_time)}</Text>
|
|
|
|
|
+ <Text>real duration:{isStart ? '-' : TimeFormatter.calculateTimeDifference(isFast ? time.fast.real_start_time : time.sleep.real_start_time, new Date().getTime())}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -195,25 +145,23 @@ export default function Component() {
|
|
|
function layoutContent() {
|
|
function layoutContent() {
|
|
|
var limit = global.set_time - 7 * 3600 * 1000 * 24;
|
|
var limit = global.set_time - 7 * 3600 * 1000 * 24;
|
|
|
global.limit = limit
|
|
global.limit = limit
|
|
|
- var current_record = machine.context.checkData ? (machine.context.checkData as any).current_record : null;
|
|
|
|
|
- if (current_record && current_record.last_real_check_time) {
|
|
|
|
|
- limit = current_record.last_real_check_time
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (time.last_real_check_time) {
|
|
|
|
|
+ limit = time.last_real_check_time
|
|
|
global.limit = limit
|
|
global.limit = limit
|
|
|
//当set_time秒数<=latest_record_time秒数时,最小限制时间戳需+1分钟
|
|
//当set_time秒数<=latest_record_time秒数时,最小限制时间戳需+1分钟
|
|
|
- if (new Date(global.set_time).getSeconds() <= new Date(current_record.last_real_check_time).getSeconds()) {
|
|
|
|
|
|
|
+ if (new Date(global.set_time).getSeconds() <= new Date(time.last_real_check_time).getSeconds()) {
|
|
|
limit = limit + 60 * 1000
|
|
limit = limit + 60 * 1000
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var color = isFast ? '#aaff00' : '#00ffff'
|
|
|
|
|
- if (value == 'ONGOING2') {
|
|
|
|
|
- color = '#00ffff'
|
|
|
|
|
|
|
+ var title = getTitle(time)
|
|
|
|
|
+ var color = getColor(time)
|
|
|
|
|
+ if (props.isNextStep){
|
|
|
|
|
+ title = '结束断食'
|
|
|
|
|
+ color = '#AAFF00'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var checkData = machine.context.checkData;
|
|
|
|
|
- var current = (checkData as any).current_record
|
|
|
|
|
- var title = getTitle(current)
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
return <LimitPickers ref={limitPickerRef} limit={limit} limitDay={8}
|
|
return <LimitPickers ref={limitPickerRef} limit={limit} limitDay={8}
|
|
|
themeColor={color}
|
|
themeColor={color}
|
|
@@ -232,9 +180,13 @@ export default function Component() {
|
|
|
|
|
|
|
|
t = date.getTime();
|
|
t = date.getTime();
|
|
|
|
|
|
|
|
|
|
+ if (props.isNextStep){
|
|
|
|
|
+ endFast(t)
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (isFast) {
|
|
if (isFast) {
|
|
|
- if (value == 'WAIT_FOR_START') {
|
|
|
|
|
- // const duration = fastValues[0] * 3600 * 1000 + fastValues[1] * 60 * 1000
|
|
|
|
|
|
|
+ if (time.status == 'WAIT_FOR_START') {
|
|
|
startFast(t, fastDuration);
|
|
startFast(t, fastDuration);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -242,8 +194,7 @@ export default function Component() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- if (value == 'WAIT_FOR_START' || value == 'ONGOING1') {
|
|
|
|
|
- // const duration = sleepValues[0] * 3600 * 1000 + sleepValues[1] * 60 * 1000
|
|
|
|
|
|
|
+ if (time.status == 'WAIT_FOR_START' || time.status == 'ONGOING1') {
|
|
|
startSleep(t, sleepDuration);
|
|
startSleep(t, sleepDuration);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -252,76 +203,91 @@ export default function Component() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function targetView() {
|
|
|
|
|
+ if (props.isNextStep && (time.status == 'ONGOING1' || time.status == 'ONGOING2')) {
|
|
|
|
|
+ var opacity = textNextStepAlpha(time)
|
|
|
|
|
+ if (opacity == 1) {
|
|
|
|
|
+ return <View className="target_view" style={{ backgroundColor: '#FA51511A' }}>
|
|
|
|
|
+ <Text className="target_text" style={{ color: '#FA5151' }}>超出目标结束</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+ return <View className="target_view" style={{ backgroundColor: '#AAFF001A', opacity: opacity }}>
|
|
|
|
|
+ <Text className="target_text" style={{ color: '#AAFF00' }}>距离目标结束</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (time.status == 'ONGOING' || time.status == 'ONGOING2' || time.status == 'ONGOING3') {
|
|
|
|
|
+ var opacity = textAlpha(time)
|
|
|
|
|
+ if (opacity == 1) {
|
|
|
|
|
+ return <View className="target_view" style={{ backgroundColor: '#FA51511A' }}>
|
|
|
|
|
+ <Text className="target_text" style={{ color: '#FA5151' }}>超出目标结束</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+ return <View className="target_view" style={{ backgroundColor: isFast ? '#AAFF001A' : '#00FFFF1A', opacity: opacity }}>
|
|
|
|
|
+ <Text className="target_text" style={{ color: isFast ? '#AAFF00' : '#00FFFF' }}>距离目标结束</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+ return <View />
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function mixedBtns() {
|
|
function mixedBtns() {
|
|
|
- var checkData = machine.context.checkData;
|
|
|
|
|
- var current = (checkData as any).current_record
|
|
|
|
|
- return <View style={{ display: 'flex', marginTop: 22 }}>
|
|
|
|
|
|
|
+ return <View className="btn_bg">
|
|
|
{
|
|
{
|
|
|
- (value == 'WAIT_FOR_START' || value == 'DONE') &&
|
|
|
|
|
|
|
+ (time.status == 'WAIT_FOR_START' || time.status == 'DONE') &&
|
|
|
<StartFastBtn onClick={showPicker} />
|
|
<StartFastBtn onClick={showPicker} />
|
|
|
- // <Text style={{ color: '#AAFF00' }} onClick={showPicker}>Start Fast</Text>
|
|
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- (value == 'ONGOING' || value == 'ONGOING3') &&
|
|
|
|
|
- <EndFastBtn onClick={showPicker} lowLight={current.fast.target_end_time > new Date().getTime()} />
|
|
|
|
|
|
|
+ (time.status == 'ONGOING' || time.status == 'ONGOING3') &&
|
|
|
|
|
+ <EndFastBtn onClick={showPicker} lowLight={time.fast.target_end_time > new Date().getTime()} />
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- value == 'ONGOING1' && <StartSleepBtn onClick={showPicker} />
|
|
|
|
|
|
|
+ time.status == 'ONGOING1' && <StartSleepBtn onClick={showPicker} />
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- value == 'ONGOING2' && <EndSleepBtn onClick={showPicker} lowLight={current.sleep.target_end_time > new Date().getTime()} />
|
|
|
|
|
|
|
+ time.status == 'ONGOING2' && <EndSleepBtn onClick={showPicker} lowLight={time.sleep.target_end_time > new Date().getTime()} />
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function textAlpha() {
|
|
|
|
|
- var checkData = machine.context.checkData;
|
|
|
|
|
- var current = (checkData as any).current_record
|
|
|
|
|
- if (value == 'WAIT_FOR_START' || value == 'DONE') {
|
|
|
|
|
- return 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function nextStepBtns() {
|
|
|
|
|
+ return <View className="btn_bg">
|
|
|
|
|
+ {
|
|
|
|
|
+ (time.status == 'WAIT_FOR_START') &&
|
|
|
|
|
+ <StartSleepBtn onClick={showPicker} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ time.status == 'ONGOING1' && <EndFastBtn onClick={showPicker} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ time.status == 'ONGOING2' && <EndFastBtn onClick={showPicker} lowLight={time.fast.target_end_time > new Date().getTime()} />
|
|
|
|
|
|
|
|
- if (value == 'ONGOING' || value == 'ONGOING3') {
|
|
|
|
|
- if (current.scenario == 'SLEEP') {
|
|
|
|
|
- return current.sleep.target_end_time > new Date().getTime() ? 0.4 : 1
|
|
|
|
|
}
|
|
}
|
|
|
- return current.fast.target_end_time > new Date().getTime() ? 0.4 : 1
|
|
|
|
|
- }
|
|
|
|
|
- if (value == 'ONGOING1')
|
|
|
|
|
- return 1//current.sleep.target_start_time > new Date().getTime()?0.4:1
|
|
|
|
|
- if (value == 'ONGOING2')
|
|
|
|
|
- return current.sleep.target_end_time > new Date().getTime() ? 0.4 : 1
|
|
|
|
|
- return 1
|
|
|
|
|
|
|
+ </View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
function fastBtns() {
|
|
function fastBtns() {
|
|
|
- return <View style={{ display: 'flex', marginTop: 22 }}>
|
|
|
|
|
|
|
+ return <View className="btn_bg">
|
|
|
{
|
|
{
|
|
|
- value == 'ONGOING' ? <EndFastBtn onClick={showPicker} lowLight={textAlpha() != 1} /> : <StartFastBtn onClick={showPicker} />
|
|
|
|
|
|
|
+ time.status == 'ONGOING' ? <EndFastBtn onClick={showPicker} lowLight={textAlpha(time) != 1} /> : <StartFastBtn onClick={showPicker} />
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function sleepBtns() {
|
|
function sleepBtns() {
|
|
|
- return <View style={{ display: 'flex', marginTop: 22 }}>
|
|
|
|
|
|
|
+ return <View className="btn_bg">
|
|
|
{
|
|
{
|
|
|
- value == 'ONGOING' ? <EndSleepBtn onClick={showPicker} lowLight={textAlpha() != 1} /> : <StartSleepBtn onClick={showPicker} />
|
|
|
|
|
|
|
+ time.status == 'ONGOING' ? <EndSleepBtn onClick={showPicker} lowLight={textAlpha(time) != 1} /> : <StartSleepBtn onClick={showPicker} />
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const handlePickerChange = (e: string) => {
|
|
|
|
|
- var [hour, minute] = e.split(':').map(x => parseInt(x))
|
|
|
|
|
- isFast ? setFastValues([hour, minute]) : setSleepValues([hour, minute]);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
function durationChange(e) {
|
|
function durationChange(e) {
|
|
|
var count = (e[0] + common.duration.min) * 60 + e[1] * common.duration.step
|
|
var count = (e[0] + common.duration.min) * 60 + e[1] * common.duration.step
|
|
|
isFast ? setFastDuration(count * 60000) : setSleepDuration(count * 60000);
|
|
isFast ? setFastDuration(count * 60000) : setSleepDuration(count * 60000);
|
|
|
isFast ? setFastPickerValue(e) : setSleepPickerValue(e)
|
|
isFast ? setFastPickerValue(e) : setSleepPickerValue(e)
|
|
|
-
|
|
|
|
|
- setIsOpenDurationPicker(false)
|
|
|
|
|
|
|
+ global.showClockModal2(false, null)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function login() {
|
|
function login() {
|
|
@@ -331,43 +297,28 @@ export default function Component() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function durationFormate() {
|
|
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 + '分钟' : ''}`
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var t = isFast ? fastDuration / 60000 : sleepDuration / 60000
|
|
|
|
|
+ if (props.isNextStep) t = sleepDuration / 60000
|
|
|
|
|
+ var hour = Math.floor(t / 60)
|
|
|
|
|
+ var minute = Math.floor(t % 60)
|
|
|
|
|
+ return `${hour > 0 ? hour + '小时' : ''}${minute > 0 ? minute + '分钟' : ''}`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function showDurationPicker() {
|
|
function showDurationPicker() {
|
|
|
- setIsOpenDurationPicker(true)
|
|
|
|
|
|
|
+ var node = <Modal children={durationPickerContent()} dismiss={() => global.showClockModal2(false, null)} confirm={() => {
|
|
|
|
|
+ var picker = durationPickerRef.current;
|
|
|
|
|
+ durationChange((picker as any).getConfirmData());
|
|
|
|
|
+ global.showClockModal2(false, null);
|
|
|
|
|
+ }} />
|
|
|
|
|
+ global.showClockModal2(true, node);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!user.isLogin) {
|
|
|
|
|
- return <View style={{ display: 'flex', flexDirection: 'column', width: '100%', alignItems: 'center' }}>
|
|
|
|
|
- <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>
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
function durationPickerContent() {
|
|
function durationPickerContent() {
|
|
|
- var color = isFast ? '#aaff00' : '#00ffff'
|
|
|
|
|
- if (value == 'ONGOING2') {
|
|
|
|
|
- color = '#00ffff'
|
|
|
|
|
- }
|
|
|
|
|
- var checkData = machine.context.checkData;
|
|
|
|
|
- var current = (checkData as any).current_record
|
|
|
|
|
- var title = getTitle(current)
|
|
|
|
|
|
|
+ var color = getColor(time)
|
|
|
|
|
+ var title = getTitle(time)
|
|
|
return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
|
<PickerViews ref={durationPickerRef}
|
|
<PickerViews ref={durationPickerRef}
|
|
|
onChange={durationChange}
|
|
onChange={durationChange}
|
|
@@ -375,7 +326,7 @@ export default function Component() {
|
|
|
value={isFast ? fastPickerValue : sleepPickerValue}
|
|
value={isFast ? fastPickerValue : sleepPickerValue}
|
|
|
themeColor={color}
|
|
themeColor={color}
|
|
|
title={title}
|
|
title={title}
|
|
|
- showBtns={true} onCancel={() => { setIsOpenDurationPicker(false) }} />
|
|
|
|
|
|
|
+ showBtns={true} onCancel={() => { global.showClockModal2(false, null); }} />
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -447,64 +398,92 @@ export default function Component() {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var textColor = '#AAFF00'
|
|
|
|
|
- if (!isFast) {
|
|
|
|
|
- textColor = '#00FFFF'
|
|
|
|
|
|
|
+ var textColor = getColor(time)
|
|
|
|
|
+ if (time.status != 'ONGOING1' && time.status != 'WAIT_FOR_START') {
|
|
|
|
|
+ if (textAlpha(time) == 1) {
|
|
|
|
|
+ textColor = '#FA5151';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (!user.isLogin) {
|
|
|
|
|
+ return <View style={{ display: 'flex', flexDirection: 'column', width: '100%', alignItems: 'center' }}>
|
|
|
|
|
+ <Text>16:00</Text>
|
|
|
|
|
+ <Text style={{ color: '#AAFF00' }} onClick={login}>Start Fast</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (props.isNextStep) {
|
|
|
|
|
+ return <Box >
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', flexShrink: 0 }}>
|
|
|
|
|
+ {
|
|
|
|
|
+ (time.status == 'WAIT_FOR_START') && <Stepper child={
|
|
|
|
|
+ <Text className="stepper_text" style={{ color: '#00FFFF', opacity: textAlpha(time) }} onClick={showDurationPicker}>{durationFormate()}</Text>
|
|
|
|
|
+ } minus={minus} plus={plus} disableMinus={disableMinus()} disablePlus={disablePlus()} />
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ time.status == 'ONGOING1' && <View>
|
|
|
|
|
+ <Text className="counter_text" style={{ color: '#AAFF00', opacity: textAlpha(time) }}>{TimeFormatter.countdown(time.fast.target_end_time)}</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ time.status == 'ONGOING2' && <View>
|
|
|
|
|
+ <Text className="counter_text" style={{ color: '#AAFF00', opacity: textAlpha(time) }}>{TimeFormatter.countdown(time.fast.target_end_time)}</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ }
|
|
|
|
|
+ {
|
|
|
|
|
+ targetView()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ <View>
|
|
|
|
|
+ {
|
|
|
|
|
+ nextStepBtns()
|
|
|
|
|
+ }
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </Box>
|
|
|
|
|
+ }
|
|
|
return (
|
|
return (
|
|
|
<Box >
|
|
<Box >
|
|
|
- <View style={{ display:'flex',flexDirection: 'column',alignItems: 'center', flexShrink: 0 }}>
|
|
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', flexShrink: 0 }}>
|
|
|
{
|
|
{
|
|
|
- value == 'ONGOING' && <View>
|
|
|
|
|
- <Text className="counter_text" style={{ color: textColor, opacity: textAlpha() }}>{(machine.context.checkData as any).current_record.scenario == 'FAST' ?
|
|
|
|
|
- TimeFormatter.countdown((machine.context.checkData as any).current_record.fast.target_end_time) :
|
|
|
|
|
- TimeFormatter.countdown((machine.context.checkData as any).current_record.sleep.target_end_time)}</Text>
|
|
|
|
|
|
|
+ time.status == 'ONGOING' && <View>
|
|
|
|
|
+ <Text className="counter_text" style={{ color: textColor, opacity: textAlpha(time) }}>{time.scenario == 'FAST' ?
|
|
|
|
|
+ TimeFormatter.countdown(time.fast.target_end_time) :
|
|
|
|
|
+ TimeFormatter.countdown(time.sleep.target_end_time)}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- (value == 'ONGOING1' || value == 'WAIT_FOR_START') && <Stepper child={
|
|
|
|
|
- <Text className="stepper_text" style={{ color: textColor, opacity: textAlpha() }} onClick={showDurationPicker}>{durationFormate()}</Text>
|
|
|
|
|
|
|
+ (time.status == 'ONGOING1' || time.status == 'WAIT_FOR_START') && <Stepper child={
|
|
|
|
|
+ <Text className="stepper_text" style={{ color: textColor, opacity: textAlpha(time) }} onClick={showDurationPicker}>{durationFormate()}</Text>
|
|
|
} minus={minus} plus={plus} disableMinus={disableMinus()} disablePlus={disablePlus()} />
|
|
} minus={minus} plus={plus} disableMinus={disableMinus()} disablePlus={disablePlus()} />
|
|
|
- // <Text style={{marginBottom:10}} onClick={showDurationPicker}>时长:{durationFormate()}</Text>
|
|
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- machine.context.checkData && value == 'ONGOING2' && <View>
|
|
|
|
|
- <Text className="counter_text" style={{ color: '#00ffff', opacity: textAlpha() }}>{TimeFormatter.countdown((machine.context.checkData as any).current_record.sleep.target_end_time)}</Text>
|
|
|
|
|
|
|
+ time.status == 'ONGOING2' && <View>
|
|
|
|
|
+ <Text className="counter_text" style={{ color: textColor, opacity: textAlpha(time) }}>{TimeFormatter.countdown(time.sleep.target_end_time)}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
- machine.context.checkData && value == 'ONGOING3' && <View>
|
|
|
|
|
- <Text className="counter_text" style={{ color: textColor, opacity: textAlpha() }}>{TimeFormatter.countdown((machine.context.checkData as any).current_record.fast.target_end_time)}</Text>
|
|
|
|
|
|
|
+ time.status == 'ONGOING3' && <View>
|
|
|
|
|
+ <Text className="counter_text" style={{ color: textColor, opacity: textAlpha(time) }}>{TimeFormatter.countdown(time.fast.target_end_time)}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
+ {
|
|
|
|
|
+ targetView()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
<View>
|
|
<View>
|
|
|
{
|
|
{
|
|
|
- key === 'FAST_SLEEP' && mixedBtns()
|
|
|
|
|
|
|
+ time.scenario === 'FAST_SLEEP' && mixedBtns()
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- key === 'FAST' && fastBtns()
|
|
|
|
|
|
|
+ time.scenario === 'FAST' && fastBtns()
|
|
|
}
|
|
}
|
|
|
{
|
|
{
|
|
|
- key === 'SLEEP' && sleepBtns()
|
|
|
|
|
|
|
+ time.scenario === 'SLEEP' && sleepBtns()
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
|
- {
|
|
|
|
|
- showModal && isOpen && <Modal testInfo={testLayout()} children={layoutContent()} dismiss={() => setIsOpen(false)} confirm={() => {
|
|
|
|
|
- var picker = limitPickerRef.current;
|
|
|
|
|
- pickerConfirm((picker as any).getConfirmData());
|
|
|
|
|
- setIsOpen(false);
|
|
|
|
|
- }} />
|
|
|
|
|
- }
|
|
|
|
|
- {
|
|
|
|
|
- isOpenDurationPicker && <Modal children={durationPickerContent()} dismiss={() => setIsOpenDurationPicker(false)} confirm={() => {
|
|
|
|
|
- var picker = durationPickerRef.current;
|
|
|
|
|
- durationChange((picker as any).getConfirmData());
|
|
|
|
|
- setIsOpenDurationPicker(false);
|
|
|
|
|
- }} />
|
|
|
|
|
- }
|
|
|
|
|
</View>
|
|
</View>
|
|
|
</Box>
|
|
</Box>
|
|
|
)
|
|
)
|