|
|
@@ -5,9 +5,10 @@ import Taro from "@tarojs/taro";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
import { AtFloatLayout } from 'taro-ui';
|
|
|
import "taro-ui/dist/style/components/float-layout.scss";
|
|
|
+import { delRecord } from "@/services/trackTimeDuration";
|
|
|
|
|
|
|
|
|
-export default function Component(props: { type?: string }) {
|
|
|
+export default function Component(props: { type?: string, data?: any, delSuccess?: Function }) {
|
|
|
const [checkData, setCheckData] = useState(null)
|
|
|
|
|
|
const [key, setKey] = useState('');
|
|
|
@@ -34,34 +35,34 @@ export default function Component(props: { type?: string }) {
|
|
|
});
|
|
|
}, []);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- return () => {
|
|
|
- // 在组件卸载时清除定时器
|
|
|
- if (timerId) {
|
|
|
- clearInterval(timerId);
|
|
|
- }
|
|
|
- };
|
|
|
- }, [timerId]);
|
|
|
-
|
|
|
- const startTimer = () => {
|
|
|
- // 避免重复启动定时器
|
|
|
- if (timerId) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const id = setInterval(() => {
|
|
|
- setCounter((prevCounter) => prevCounter + 1);
|
|
|
- }, 1000);
|
|
|
-
|
|
|
- setTimerId(id as any);
|
|
|
- };
|
|
|
-
|
|
|
- const stopTimer = () => {
|
|
|
- if (timerId) {
|
|
|
- clearInterval(timerId);
|
|
|
- setTimerId(null);
|
|
|
- }
|
|
|
- };
|
|
|
+ // useEffect(() => {
|
|
|
+ // return () => {
|
|
|
+ // // 在组件卸载时清除定时器
|
|
|
+ // if (timerId) {
|
|
|
+ // clearInterval(timerId);
|
|
|
+ // }
|
|
|
+ // };
|
|
|
+ // }, [timerId]);
|
|
|
+
|
|
|
+ // const startTimer = () => {
|
|
|
+ // // 避免重复启动定时器
|
|
|
+ // if (timerId) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // const id = setInterval(() => {
|
|
|
+ // setCounter((prevCounter) => prevCounter + 1);
|
|
|
+ // }, 1000);
|
|
|
+
|
|
|
+ // setTimerId(id as any);
|
|
|
+ // };
|
|
|
+
|
|
|
+ // const stopTimer = () => {
|
|
|
+ // if (timerId) {
|
|
|
+ // clearInterval(timerId);
|
|
|
+ // setTimerId(null);
|
|
|
+ // }
|
|
|
+ // };
|
|
|
|
|
|
function getStateDetail() {
|
|
|
if (props.type == 'latest') {
|
|
|
@@ -94,16 +95,17 @@ export default function Component(props: { type?: string }) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- function showStage() {
|
|
|
- startTimer();
|
|
|
+ function showStage(e) {
|
|
|
setIsLatest(false);
|
|
|
setIsOpen(true)
|
|
|
+ e.stopPropagation()
|
|
|
}
|
|
|
|
|
|
- function showLatest() {
|
|
|
- startTimer();
|
|
|
+ function showLatest(e) {
|
|
|
+ // startTimer();
|
|
|
setIsLatest(true)
|
|
|
setIsOpen(true)
|
|
|
+ e.stopPropagation()
|
|
|
}
|
|
|
|
|
|
function getTime(t1: number, t2: number) {
|
|
|
@@ -143,6 +145,9 @@ export default function Component(props: { type?: string }) {
|
|
|
function layoutContent() {
|
|
|
//当前断食阶段
|
|
|
var obj = isLatest ? (checkData as any).latest_record : (checkData as any).current_record
|
|
|
+ if (props.type == 'record') {
|
|
|
+ obj = props.data
|
|
|
+ }
|
|
|
return <View style={{ flexDirection: 'column', display: 'flex', color: '#000' }}>
|
|
|
{
|
|
|
obj.status == 'WAIT_FOR_START' ? <Text>断食阶段目标</Text> :
|
|
|
@@ -179,21 +184,21 @@ export default function Component(props: { type?: string }) {
|
|
|
}
|
|
|
|
|
|
//🚫❌⭕️✅
|
|
|
- function statusString(isFast: boolean, isStart: boolean) {
|
|
|
- if (props.type == 'latest') {
|
|
|
+ function statusString(isFast: boolean, isStart: boolean, data: any) {
|
|
|
+ if (props.type == 'latest' || props.type == 'record') {
|
|
|
if (isFast) {
|
|
|
- if ((checkData as any).latest_record.fast.status == 'COMPLETED') {
|
|
|
+ if (data.fast.status == 'COMPLETED') {
|
|
|
return '✅'
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- if ((checkData as any).latest_record.sleep.status == 'COMPLETED') {
|
|
|
+ if (data.sleep.status == 'COMPLETED') {
|
|
|
return '✅'
|
|
|
}
|
|
|
- else if ((checkData as any).latest_record.sleep.status == 'NOT_STARTED') {
|
|
|
+ else if (data.sleep.status == 'NOT_STARTED') {
|
|
|
return '🚫'
|
|
|
}
|
|
|
- else if ((checkData as any).latest_record.sleep.status == 'NOT_COMPLETED') {
|
|
|
+ else if (data.sleep.status == 'NOT_COMPLETED') {
|
|
|
return isStart ? '✅' : '🚫'
|
|
|
}
|
|
|
}
|
|
|
@@ -201,6 +206,14 @@ export default function Component(props: { type?: string }) {
|
|
|
if (value == 'WAIT_FOR_START') {
|
|
|
return '⭕️'
|
|
|
}
|
|
|
+ else if (value == 'ONGOING') {
|
|
|
+ if (isFast && isStart) {
|
|
|
+ return '✅'
|
|
|
+ }
|
|
|
+ else if (!isFast && isStart) {
|
|
|
+ return '✅'
|
|
|
+ }
|
|
|
+ }
|
|
|
else if (value == 'ONGOING1') {
|
|
|
if (isFast && isStart) {
|
|
|
return '✅'
|
|
|
@@ -221,20 +234,67 @@ export default function Component(props: { type?: string }) {
|
|
|
}
|
|
|
|
|
|
return '⭕️'
|
|
|
+ // if (props.type == 'latest') {
|
|
|
+ // if (isFast) {
|
|
|
+ // if ((checkData as any).latest_record.fast.status == 'COMPLETED') {
|
|
|
+ // return '✅'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // if ((checkData as any).latest_record.sleep.status == 'COMPLETED') {
|
|
|
+ // return '✅'
|
|
|
+ // }
|
|
|
+ // else if ((checkData as any).latest_record.sleep.status == 'NOT_STARTED') {
|
|
|
+ // return '🚫'
|
|
|
+ // }
|
|
|
+ // else if ((checkData as any).latest_record.sleep.status == 'NOT_COMPLETED') {
|
|
|
+ // return isStart ? '✅' : '🚫'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if (value == 'WAIT_FOR_START') {
|
|
|
+ // return '⭕️'
|
|
|
+ // }
|
|
|
+ // else if (value == 'ONGOING1'||value == 'ONGOING') {
|
|
|
+ // if (isFast && isStart) {
|
|
|
+ // return '✅'
|
|
|
+ // }
|
|
|
+ // else if (!isFast && isStart) {
|
|
|
+ // return '✅'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else if (value == 'ONGOING2') {
|
|
|
+ // if (isStart) {
|
|
|
+ // return '✅'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // else if (value == 'ONGOING3') {
|
|
|
+ // if (isFast && !isStart) {
|
|
|
+ // return '⭕️'
|
|
|
+ // }
|
|
|
+ // else {
|
|
|
+ // return '✅'
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return '⭕️'
|
|
|
}
|
|
|
|
|
|
- function scheduleItems() {
|
|
|
- if (!checkData) {
|
|
|
+ function scheduleItems(data) {
|
|
|
+ if (!data) {
|
|
|
return <View></View>
|
|
|
}
|
|
|
- var obj = props.type == 'latest' ? (checkData as any).latest_record : (checkData as any).current_record;
|
|
|
+ var obj = props.type == 'latest' ? (data as any).latest_record : (data as any).current_record;
|
|
|
+ if (props.type == 'record') {
|
|
|
+ obj = data//(data as any).latest_record
|
|
|
+ }
|
|
|
return <View>
|
|
|
{
|
|
|
obj && <View style={{ flexDirection: 'column', display: 'flex' }}>
|
|
|
- {obj.fast && <Text>{statusString(true, true)}开始断食:{formateTime(obj.fast, false)}</Text>}
|
|
|
- {obj.sleep && <Text>{statusString(false, true)}开始睡眠:{formateTime(obj.sleep, false)}</Text>}
|
|
|
- {obj.sleep && <Text>{statusString(false, false)}结束睡眠:{formateTime(obj.sleep, true)}</Text>}
|
|
|
- {obj.fast && <Text>{statusString(true, false)}结束断食:{formateTime(obj.fast, true)}</Text>}
|
|
|
+ {obj.fast && <Text>{statusString(true, true, obj)}开始断食:{formateTime(obj.fast, false)}</Text>}
|
|
|
+ {obj.sleep && <Text>{statusString(false, true, obj)}开始睡眠:{formateTime(obj.sleep, false)}</Text>}
|
|
|
+ {obj.sleep && <Text>{statusString(false, false, obj)}结束睡眠:{formateTime(obj.sleep, true)}</Text>}
|
|
|
+ {obj.fast && <Text>{statusString(true, false, obj)}结束断食:{formateTime(obj.fast, true)}</Text>}
|
|
|
</View>
|
|
|
}
|
|
|
</View>
|
|
|
@@ -261,40 +321,94 @@ export default function Component(props: { type?: string }) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- return <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center' }}>
|
|
|
+ function more(e) {
|
|
|
+ Taro.showActionSheet({
|
|
|
+ itemList: ['删除', '分享']
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ console.log(res.tapIndex)
|
|
|
+ switch (res.tapIndex) {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ del()
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err.errMsg)
|
|
|
+ })
|
|
|
+ e.stopPropagation()
|
|
|
+ }
|
|
|
+
|
|
|
+ function del() {
|
|
|
+ Taro.showModal({
|
|
|
+ title: '删除记录',
|
|
|
+ content: '确定删除该记录吗?',
|
|
|
+ success: res => {
|
|
|
+ if (res.confirm) {
|
|
|
+ delRecord(props.data.id
|
|
|
+ ).then(res => {
|
|
|
+ Taro.showToast({
|
|
|
+ title: '删除成功'
|
|
|
+ })
|
|
|
+ props.delSuccess && props.delSuccess(props.data)
|
|
|
+ // Taro.navigateBack()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function all() {
|
|
|
+ if (props.type == 'latest') {
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: '/pages/RecordsHistory'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center', position: 'relative' }} onClick={all}>
|
|
|
{
|
|
|
props.type == 'latest' ? <Text style={{ color: 'red' }}>Latest</Text> :
|
|
|
<Text>{value == 'WAIT_FOR_START' ? 'Schedule' : 'Log in Progress'}</Text>
|
|
|
}
|
|
|
{
|
|
|
- scheduleItems()
|
|
|
+ scheduleItems(props.type == 'record' ? props.data : checkData)
|
|
|
}
|
|
|
|
|
|
{
|
|
|
- value == 'WAIT_FOR_START' && <Text onClick={editSchedule}>调整日程</Text>
|
|
|
+ (props.type != 'record' && value == 'WAIT_FOR_START') && <Text onClick={editSchedule}>调整日程</Text>
|
|
|
}
|
|
|
{
|
|
|
- props.type == 'latest' && key == 'FAST_SLEEP' && <Text onClick={showLatest}>Durations by stage</Text>
|
|
|
+ ((props.type == 'record' && props.data.scenario == 'FAST_SLEEP') || (props.type == 'latest' && key == 'FAST_SLEEP')) && <Text onClick={showLatest}>Durations by stage</Text>
|
|
|
}
|
|
|
{
|
|
|
- props.type != 'latest' && key == 'FAST_SLEEP' && (value == 'WAIT_FOR_START' ? <Text onClick={showStage}>Duration goals by stage</Text> : <Text onClick={showStage}>Current stage</Text>)
|
|
|
+ props.type != 'record' && props.type != 'latest' && key == 'FAST_SLEEP' && (value == 'WAIT_FOR_START' ? <Text onClick={showStage}>Duration goals by stage</Text> : <Text onClick={showStage}>Current stage</Text>)
|
|
|
}
|
|
|
|
|
|
{
|
|
|
key == 'FAST_SLEEP' && <AtFloatLayout
|
|
|
isOpened={isOpen}
|
|
|
onClose={() => {
|
|
|
- stopTimer()
|
|
|
+ // stopTimer()
|
|
|
setIsOpen(false)
|
|
|
}}
|
|
|
title="这是个标题">
|
|
|
{
|
|
|
- checkData && layoutContent()
|
|
|
+ props.type != 'record'&&checkData && layoutContent()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ props.type == 'record' && props.data.scenario=='FAST_SLEEP' && layoutContent()
|
|
|
}
|
|
|
|
|
|
|
|
|
</AtFloatLayout>
|
|
|
}
|
|
|
+
|
|
|
+ {
|
|
|
+ props.type == 'record' && <Text style={{ position: 'absolute', right: 20, top: 20 }} onClick={more}>More</Text>
|
|
|
+ }
|
|
|
<Text style={{ opacity: 0 }}>{counter}</Text>
|
|
|
|
|
|
</View >
|