|
|
@@ -1,8 +1,8 @@
|
|
|
import { WindowType } from "@/utils/types";
|
|
|
-import { View, Text } from "@tarojs/components";
|
|
|
+import { View, Text, Image } from "@tarojs/components";
|
|
|
import dayjs from "dayjs";
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
-import { useSelector } from "react-redux";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
import './MainConsole.scss'
|
|
|
import { jumpPage } from "../trackTimeDuration/hooks/Common";
|
|
|
import Modal from "@/components/layout/Modal.weapp";
|
|
|
@@ -11,6 +11,9 @@ import ConsolePicker from "../trackTimeDuration/components/ConsolePicker";
|
|
|
import { clockTimes, updateSchedule, updateTarget } from "@/services/health";
|
|
|
import TimePicker from "../common/TimePicker";
|
|
|
import showActionSheet from "@/components/basic/ActionSheet";
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
+import { setMode } from "@/store/health";
|
|
|
+import { getCountownTime, getDuration, getScenario, getWindowStatus } from "./hooks/health_hooks";
|
|
|
|
|
|
let useNavigation;
|
|
|
let min = 0
|
|
|
@@ -30,6 +33,7 @@ export default function MainConsole(props: { type: WindowType }) {
|
|
|
const [btnDisable, setBtnDisable] = useState(false)
|
|
|
const [selItem, setSelItem] = useState<any>(null)
|
|
|
const limitPickerRef = useRef(null)
|
|
|
+ const dispatch = useDispatch()
|
|
|
|
|
|
let navigation, showActionSheetWithOptions;
|
|
|
if (useNavigation) {
|
|
|
@@ -46,7 +50,7 @@ export default function MainConsole(props: { type: WindowType }) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (item.action == 'NA' || item.action == 'POST_MOMENT' ||'SLEEP_WAKE_UP' == item.action) {
|
|
|
+ if (item.action == 'NA' || item.action == 'POST_MOMENT' || 'SLEEP_WAKE_UP' == item.action) {
|
|
|
return;
|
|
|
}
|
|
|
if (!user.isLogin) {
|
|
|
@@ -102,16 +106,45 @@ export default function MainConsole(props: { type: WindowType }) {
|
|
|
return '记录'
|
|
|
}
|
|
|
|
|
|
- function timelineItem(item: any, index: number) {
|
|
|
+ function itemTitle(item: any) {
|
|
|
+ if (health.mode == 'DAY' || health.mode == 'NIGHT') {
|
|
|
+ return item.title
|
|
|
+ }
|
|
|
+ return dayjs(item.target.timestamp).format('HH:mm')
|
|
|
+ }
|
|
|
+
|
|
|
+ function itemValue(item: any) {
|
|
|
+ let themeColor: any = getThemeColor()
|
|
|
+ const scenario = getScenario(health.windows,health.mode)
|
|
|
+ if (item.action == 'END' && !scenario.real) {
|
|
|
+ themeColor = '#B2B2B2'
|
|
|
+ }
|
|
|
+ if (health.mode == 'DAY' || health.mode == 'NIGHT') {
|
|
|
+ return <Text className="timeline_time">{dayjs(item.target.timestamp).format('HH:mm')}</Text>
|
|
|
+ }
|
|
|
+ if (item.action && item.action != 'NA')
|
|
|
+ return <View className="timeline_operate" style={{ color: themeColor, backgroundColor: themeColor + '1A' }} onClick={() => record(item)}>{operateTitle(item)}</View>
|
|
|
+ return <View />
|
|
|
+ }
|
|
|
+
|
|
|
+ function timelineItem(item: any, index: number, count: number) {
|
|
|
return <View key={index} className="timeline_item" >
|
|
|
<View className="timeline_left">
|
|
|
- <Text className="timeline_title">{item.title}</Text>
|
|
|
- <Text className="timeline_time" onClick={() => edit(item)}>{dayjs(item.target.timestamp).format('HH:mm')}</Text>
|
|
|
+ {
|
|
|
+ health.mode != 'DAY' && health.mode != 'NIGHT' && <Text className="timeline_title">{item.title}</Text>
|
|
|
+ }
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
+ <Text className="timeline_time" onClick={() => edit(item)}>{itemTitle(item)}</Text>
|
|
|
+ </View>
|
|
|
+
|
|
|
</View>
|
|
|
{
|
|
|
- item.action && item.action != 'NA' && <View className="timeline_operate" onClick={() => record(item)}>{operateTitle(item)}</View>
|
|
|
+ itemValue(item)
|
|
|
}
|
|
|
-
|
|
|
+ {/* {
|
|
|
+ item.action && item.action != 'NA' &&
|
|
|
+ } */}
|
|
|
+ <View className="border_footer_line" style={{ left: count - 1 == index ? -rpxToPx(64) : 0 }} />
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
@@ -157,7 +190,7 @@ export default function MainConsole(props: { type: WindowType }) {
|
|
|
function confirmPickerTime(strTime) {
|
|
|
if (selItem.event == 'FAST_END') {
|
|
|
const obj = health.windows.fast_eat.fast.timeline[0]
|
|
|
- if (obj.action=='POST_MOMENT' || obj.action == 'NA') {
|
|
|
+ if (obj.action == 'POST_MOMENT' || obj.action == 'NA') {
|
|
|
const format = dayjs(obj.target.timestamp).format(`YYYY-MM-DDT${strTime}:ss`)
|
|
|
var t = new Date(format).getTime()
|
|
|
if (t <= obj.target.timestamp) {
|
|
|
@@ -172,7 +205,7 @@ export default function MainConsole(props: { type: WindowType }) {
|
|
|
}
|
|
|
else if (selItem.event == 'SLEEP_WAKE_UP') {
|
|
|
const obj = health.windows.sleep_active.sleep.timeline[0]
|
|
|
- if (obj.action=='POST_MOMENT' || obj.action == 'NA') {
|
|
|
+ if (obj.action == 'POST_MOMENT' || obj.action == 'NA') {
|
|
|
const format = dayjs(obj.target.timestamp).format(`YYYY-MM-DDT${strTime}:ss`)
|
|
|
var t = new Date(format).getTime()
|
|
|
if (t <= obj.target.timestamp) {
|
|
|
@@ -293,67 +326,116 @@ export default function MainConsole(props: { type: WindowType }) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ function getThemeColor() {
|
|
|
+ switch (health.mode) {
|
|
|
+ case 'DAY':
|
|
|
+ return MainColorType.day;
|
|
|
+ case 'NIGHT':
|
|
|
+ return MainColorType.night;
|
|
|
+ case 'FAST':
|
|
|
+ return MainColorType.fast;
|
|
|
+ case 'EAT':
|
|
|
+ return MainColorType.eat;
|
|
|
+ case 'SLEEP':
|
|
|
+ return MainColorType.sleep;
|
|
|
+ case 'ACTIVE':
|
|
|
+ return MainColorType.active;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function detail() {
|
|
|
const { day, night } = health.windows.night_day
|
|
|
const { fast, eat } = health.windows.fast_eat
|
|
|
const { sleep, active } = health.windows.sleep_active
|
|
|
+ let list: any = []
|
|
|
switch (health.mode) {
|
|
|
case 'DAY':
|
|
|
- return <View>
|
|
|
- {
|
|
|
- day.timeline.map((item, index) => {
|
|
|
- return timelineItem(item, index)
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ list = day.timeline
|
|
|
+ break;
|
|
|
case 'NIGHT':
|
|
|
- return <View>
|
|
|
- {
|
|
|
- night.timeline.map((item, index) => {
|
|
|
- return timelineItem(item, index)
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ list = night.timeline
|
|
|
+ break;
|
|
|
case 'FAST':
|
|
|
- return <View>
|
|
|
- {
|
|
|
- fast.timeline.map((item, index) => {
|
|
|
- return timelineItem(item, index)
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ list = fast.timeline
|
|
|
+ break;
|
|
|
case 'EAT':
|
|
|
- return <View>
|
|
|
- {
|
|
|
- eat.timeline.map((item, index) => {
|
|
|
- return timelineItem(item, index)
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ list = eat.timeline
|
|
|
+ break;
|
|
|
case 'SLEEP':
|
|
|
- return <View>
|
|
|
- {
|
|
|
- sleep.timeline.map((item, index) => {
|
|
|
- return timelineItem(item, index)
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ list = sleep.timeline
|
|
|
+ break;
|
|
|
case 'ACTIVE':
|
|
|
- return <View>
|
|
|
- {
|
|
|
- active.timeline && active.timeline.map((item, index) => {
|
|
|
- return timelineItem(item, index)
|
|
|
- })
|
|
|
- }
|
|
|
- </View>
|
|
|
+ list = active.timeline
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
- return <View />
|
|
|
+ return <View>
|
|
|
+ {
|
|
|
+ list.map((item, index) => {
|
|
|
+ return timelineItem(item, index, list.length)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
}
|
|
|
- return <View>
|
|
|
- {
|
|
|
- detail()
|
|
|
+
|
|
|
+ function switchText() {
|
|
|
+ switch (health.mode) {
|
|
|
+ case 'FAST':
|
|
|
+ return 'Switch to Eat'
|
|
|
+ case 'EAT':
|
|
|
+ return 'Switch to Fast'
|
|
|
+ case 'DAY':
|
|
|
+ return 'Switch to Night'
|
|
|
+ case 'NIGHT':
|
|
|
+ return 'Switch to Daylight'
|
|
|
+ case 'SLEEP':
|
|
|
+ return 'Switch to Activity'
|
|
|
+ case 'ACTIVE':
|
|
|
+ return 'Switch to Sleep'
|
|
|
+
|
|
|
}
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+
|
|
|
+ function tapSwitchBtn() {
|
|
|
+ switch (health.mode) {
|
|
|
+ case 'FAST':
|
|
|
+ dispatch(setMode('EAT'));
|
|
|
+ break
|
|
|
+ case 'EAT':
|
|
|
+ dispatch(setMode('FAST'));
|
|
|
+ break
|
|
|
+ case 'DAY':
|
|
|
+ dispatch(setMode('NIGHT'));
|
|
|
+ break
|
|
|
+ case 'NIGHT':
|
|
|
+ dispatch(setMode('DAY'));
|
|
|
+ break
|
|
|
+ case 'SLEEP':
|
|
|
+ dispatch(setMode('ACTIVE'));
|
|
|
+ break
|
|
|
+ case 'ACTIVE':
|
|
|
+ dispatch(setMode('SLEEP'));
|
|
|
+ break
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return <View className="main-console-bg">
|
|
|
+ <Image className="main_arrow" src={require('@assets/images/center_arrow.png')} />
|
|
|
+ <View className="main_summary">
|
|
|
+ <View className="main_summary_status" style={{ color: getThemeColor() }}>{getWindowStatus(health.windows, health.mode)}</View>
|
|
|
+ <Text className="main_summary_time">{getCountownTime(health.windows, health.mode)}</Text>
|
|
|
+ <Text className="main_summary_duration">Total {getDuration(health.windows, health.mode)}</Text>
|
|
|
+ <View className="border_footer_line" />
|
|
|
+ </View>
|
|
|
+ <View style={{ backgroundColor: '#fff', width: rpxToPx(750) }}>
|
|
|
+ {
|
|
|
+ detail()
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ <View className="main_footer">
|
|
|
+ <Text className="main_footer_text" onClick={tapSwitchBtn}>{switchText()}</Text>
|
|
|
+ </View>
|
|
|
{
|
|
|
(health.mode == 'EAT' || health.mode == 'ACTIVE') && <Text style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }} onClick={more}>更多</Text>
|
|
|
}
|