|
|
@@ -7,13 +7,14 @@ import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/tr
|
|
|
import dayjs from "dayjs";
|
|
|
import moment from 'moment-timezone'
|
|
|
import { MainColorType } from "@/context/themes/color";
|
|
|
-import { fastWindow } from "@/services/trackTimeDuration";
|
|
|
+import { fastWindow, setSchedule, updateRecord } from "@/services/trackTimeDuration";
|
|
|
import { useSelector } from "react-redux";
|
|
|
import { jumpPage } from "../hooks/Common";
|
|
|
import ConsolePicker from "./ConsolePicker";
|
|
|
import { endFast, startFast } from "../actions/TrackTimeActions";
|
|
|
import formatMilliseconds from "@/utils/format_time";
|
|
|
-
|
|
|
+import TimePicker from "@/features/common/TimePicker";
|
|
|
+import showAlert from "@/components/basic/Alert";
|
|
|
let useNavigation;
|
|
|
|
|
|
let Linking, PushNotification;
|
|
|
@@ -46,7 +47,8 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
const [startTime, setStartTime] = useState<any>(null)
|
|
|
const [endTime, setEndTime] = useState<any>(null)
|
|
|
const [status, setStatus] = useState<any>('upcoming')
|
|
|
-
|
|
|
+ const [showPicker, setShowPicker] = useState(false)
|
|
|
+ const [isStart, setIsStart] = useState(true)
|
|
|
const [loaded, setLoaded] = useState(false)
|
|
|
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
@@ -85,6 +87,10 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
}
|
|
|
}, [props.count])
|
|
|
|
|
|
+ global.refreshFastEat = () => {
|
|
|
+ refresh()
|
|
|
+ }
|
|
|
+
|
|
|
function refresh() {
|
|
|
fastWindow().then(res => {
|
|
|
const { eat_win, fast_win } = res
|
|
|
@@ -367,15 +373,17 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
}
|
|
|
|
|
|
function tapFastStart() {
|
|
|
-
|
|
|
+ setIsStart(true)
|
|
|
+ setShowPicker(true)
|
|
|
}
|
|
|
|
|
|
function tapFastEnd() {
|
|
|
-
|
|
|
+ setIsStart(false)
|
|
|
+ setShowPicker(true)
|
|
|
}
|
|
|
|
|
|
function tapStartLog() {
|
|
|
- if (status == 'upcoming'){
|
|
|
+ if (status == 'upcoming') {
|
|
|
return;
|
|
|
}
|
|
|
if (!user.isLogin) {
|
|
|
@@ -416,6 +424,19 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
</Modal>
|
|
|
}
|
|
|
|
|
|
+ function timeContent() {
|
|
|
+ return <Modal
|
|
|
+ testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ setShowPicker(false)
|
|
|
+ }}
|
|
|
+ confirm={() => { }}>
|
|
|
+ {
|
|
|
+ pickerContent()
|
|
|
+ }
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+
|
|
|
function timePickerContent() {
|
|
|
var title = operateType == 'endFast' ? '结束断食' : '开始断食'
|
|
|
var color = MainColorType.fast
|
|
|
@@ -450,6 +471,70 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
+ function pickerContent() {
|
|
|
+ const timestamp = isStart ? fastData.fast.target_start_time : fastData.fast.target_end_time
|
|
|
+ const strTime = dayjs(timestamp).format('HH:mm')
|
|
|
+ return <TimePicker time={strTime}
|
|
|
+ color={MainColorType.fast}
|
|
|
+ title={isStart ? '开始断食' : '结束断食'}
|
|
|
+ confirm={(e) => {
|
|
|
+ confirmPickerTime(e)
|
|
|
+ }}
|
|
|
+ cancel={() => {
|
|
|
+ setShowPicker(false)
|
|
|
+ }} />
|
|
|
+ }
|
|
|
+
|
|
|
+ function confirmPickerTime(strTime) {
|
|
|
+ if (status != 'process') {
|
|
|
+ setSchedule({
|
|
|
+ code: isStart ? 'FAST_START' : 'FAST_END',
|
|
|
+ time: strTime
|
|
|
+ }).then(res => {
|
|
|
+ refresh()
|
|
|
+ setShowPicker(false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var startTime = dayjs(fastData.fast.target_start_time).format('HH:mm:ss')
|
|
|
+ var endTime = strTime + ':00'
|
|
|
+ console.log(startTime, endTime)
|
|
|
+ if (startTime == endTime) {
|
|
|
+ showAlert({
|
|
|
+ title: '',
|
|
|
+ content: '开始时间不能与结束时间相同'
|
|
|
+ })
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateRecord({
|
|
|
+ fast: {
|
|
|
+ target_duration: getIntervalSeconds(startTime, endTime) * 1000
|
|
|
+ }
|
|
|
+ }, fastData.id).then(res => {
|
|
|
+ refresh()
|
|
|
+ setShowPicker(false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function getIntervalSeconds(time1, time2) {
|
|
|
+ // 将时间字符串转换为 Date 对象
|
|
|
+ const date1 = new Date(`2000-01-01T${time1}Z`);
|
|
|
+ const date2 = new Date(`2000-01-01T${time2}Z`);
|
|
|
+
|
|
|
+ // 计算两个 Date 对象之间的时间差
|
|
|
+ let intervalMs = date2.getTime() - date1.getTime();
|
|
|
+
|
|
|
+ // 如果 time2 比 time1 小, 说明跨天了, 需要加上一天的毫秒数
|
|
|
+ if (date2 < date1) {
|
|
|
+ intervalMs += 24 * 60 * 60 * 1000;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回间隔秒数
|
|
|
+ return Math.floor(intervalMs / 1000);
|
|
|
+ }
|
|
|
+
|
|
|
function pickerConfirm(t1: number, event: any) {
|
|
|
if (btnDisable) {
|
|
|
return
|
|
|
@@ -484,6 +569,13 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function goAddEat(index) {
|
|
|
+ if (status == 'process') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ jumpPage('/pages/clock/AddEat?meal=' + JSON.stringify(eatData.meals[index]))
|
|
|
+ }
|
|
|
+
|
|
|
if (!loaded) {
|
|
|
return <View />
|
|
|
}
|
|
|
@@ -505,7 +597,7 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
<Text className="date1">{global.language == 'en' ? formatTime('dddd, MMM D') : formatTime('MMMD日 dddd')}</Text>
|
|
|
</View>
|
|
|
</View>
|
|
|
- <View>{isFastMode?formatMilliseconds(fastData.fast.target_duration):formatMilliseconds(eatData.target_end_time-eatData.target_start_time)}</View>
|
|
|
+ <View>{isFastMode ? formatMilliseconds(fastData.fast.target_duration) : formatMilliseconds(eatData.target_end_time - eatData.target_start_time)}</View>
|
|
|
{
|
|
|
isFastMode && <View>
|
|
|
<View className="log_row">
|
|
|
@@ -521,8 +613,8 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- status == 'process' ? <View className="schedule_time">{dayjs(fastData.fast.target_start_time).format('HH:mm')}</View> :
|
|
|
- <View onClick={tapStartLog} className={status == 'new' ? "fast_log_btn" : "fast_log_btn fast_log_btn_disable"}>Log{status == 'new' && <View className="badge" />}</View>
|
|
|
+ status == 'process' ? <View className="schedule_time">{dayjs(fastData.fast.target_start_time).format('HH:mm')}</View> :
|
|
|
+ <View onClick={tapStartLog} className={status == 'new' ? "fast_log_btn" : "fast_log_btn fast_log_btn_disable"}>Log{status == 'new' && <View className="badge" />}</View>
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -533,13 +625,33 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
Fast ends:
|
|
|
</Text>
|
|
|
<Text className="schedule_time">
|
|
|
- {status == 'process' ?dayjs(fastData.fast.target_end_time).format('HH:mm'):endScheduleTime}
|
|
|
+ {status == 'process' ? dayjs(fastData.fast.target_end_time).format('HH:mm') : endScheduleTime}
|
|
|
</Text>
|
|
|
</View>
|
|
|
<View onClick={tapEndLog} className={status == 'process' ? "fast_log_btn" : "fast_log_btn fast_log_btn_disable"}>Log</View>
|
|
|
</View>
|
|
|
</View>
|
|
|
}
|
|
|
+ {
|
|
|
+ !isFastMode && <View>
|
|
|
+ {
|
|
|
+ eatData.meals.map((item, index) => {
|
|
|
+ return <View className="log_row" key={index}>
|
|
|
+ <View className="schedule">
|
|
|
+ <Text className="schedule_name">{item.name}</Text>
|
|
|
+ <Text className="schedule_time">
|
|
|
+ {item.schedule_start_time}
|
|
|
+ </Text>
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ item.real_start_time ? <View className="fast_log_btn fast_log_btn_disable">已上传</View> : <View onClick={() => goAddEat(index)} className={status == 'process' ? "fast_log_btn fast_log_btn_disable" : "fast_log_btn fast_log_eat_btn"}>Add</View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
@@ -552,5 +664,8 @@ export default function MainFastEatCard(props: { count: any }) {
|
|
|
{
|
|
|
showTimePicker && modalContent()
|
|
|
}
|
|
|
+ {
|
|
|
+ showPicker && timeContent()
|
|
|
+ }
|
|
|
</View>
|
|
|
}
|