|
|
@@ -1,4 +1,4 @@
|
|
|
-import { View, Text } from "@tarojs/components";
|
|
|
+import { View, Text, Image } from "@tarojs/components";
|
|
|
import trackTimeService, { machine } from "@/store/trackTimeMachine"
|
|
|
import { useEffect, useState } from "react";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
@@ -9,19 +9,22 @@ import Modal from "@/components/layout/Modal";
|
|
|
import Rings, { BgRing, CurrentDot, RealRing, RingCommon } from './Rings';
|
|
|
import { getBgRing, getCommon, getDot, getReal, getTarget } from "../hooks/RingData";
|
|
|
import Timeline from "@/components/view/Timeline";
|
|
|
+import RecordItem from "@/features/common/RecordItem";
|
|
|
+import Box from "@/components/layout/Box";
|
|
|
+import './Schedule.scss'
|
|
|
+import { ModalType } from "@/utils/types";
|
|
|
+import Header from "@/components/layout/Header";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
|
|
|
|
|
|
export default function Component(props: { type?: string, data?: any, delSuccess?: Function }) {
|
|
|
const [checkData, setCheckData] = useState(null)
|
|
|
-
|
|
|
+ const { t } = useTranslation()
|
|
|
const [key, setKey] = useState('');
|
|
|
const [value, setValue] = useState('');
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
const [isLatest, setIsLatest] = useState(props.type == 'latest');
|
|
|
-
|
|
|
- const [timerId, setTimerId] = useState(null)
|
|
|
- const [counter, setCounter] = useState(0)
|
|
|
-
|
|
|
+ const [showDetailModal, setShowDetailModal] = useState(false)
|
|
|
const canvasId = props.type == 'latest' ? 'latest' : props.type == 'record' ? props.data.id : 'current'
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -372,21 +375,14 @@ export default function Component(props: { type?: string, data?: any, delSuccess
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
+ var id = props.type == 'record' ? props.data.id : (checkData as any).latest_record.id
|
|
|
+ delRecord(id
|
|
|
+ ).then(res => {
|
|
|
+ Taro.showToast({
|
|
|
+ title: '删除成功'
|
|
|
+ })
|
|
|
+ props.delSuccess && props.delSuccess(props.data)
|
|
|
+ // Taro.navigateBack()
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -556,68 +552,144 @@ export default function Component(props: { type?: string, data?: any, delSuccess
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
- return <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center', position: 'relative' }} onClick={all}>
|
|
|
- {
|
|
|
- (props.type == 'latest' || props.type == 'record') &&
|
|
|
- <View style={{ position: 'relative', zIndex: 1 }}>
|
|
|
+ function rings() {
|
|
|
+ return <View style={{ position: 'relative', zIndex: 1 }}>
|
|
|
+ {
|
|
|
+ bigRing()
|
|
|
+ }
|
|
|
+ <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
|
|
|
{
|
|
|
- bigRing()
|
|
|
+ smallRing()
|
|
|
}
|
|
|
- <View style={{ display: 'flex', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }}>
|
|
|
- {
|
|
|
- smallRing()
|
|
|
- }
|
|
|
- </View>
|
|
|
</View>
|
|
|
- }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
|
|
|
- {
|
|
|
- props.type == 'latest' ? <Text style={{ color: 'red' }}>Latest</Text> :
|
|
|
- <Text>{value == 'WAIT_FOR_START' ? 'Schedule' : 'Log in Progress'}</Text>
|
|
|
- }
|
|
|
- {
|
|
|
- scheduleItems(props.type == 'record' ? props.data : checkData)
|
|
|
- }
|
|
|
+ function schedules() {
|
|
|
+ return scheduleItems(props.type == 'record' ? props.data : checkData)
|
|
|
+ }
|
|
|
|
|
|
- {
|
|
|
- (props.type != 'record' && value == 'WAIT_FOR_START') && <Text onClick={editSchedule}>调整日程</Text>
|
|
|
+ function detail() {
|
|
|
+ return <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center', position: 'relative' }} onClick={all}>
|
|
|
+ {
|
|
|
+ (props.type == 'latest' || props.type == 'record') && rings()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ schedules()
|
|
|
+ }
|
|
|
+ {/* {
|
|
|
+ (props.type != 'record' && value == 'WAIT_FOR_START') && <Text onClick={editSchedule}>调整日程</Text>
|
|
|
+ } */}
|
|
|
+ {
|
|
|
+ ((props.type == 'record' && props.data.scenario == 'FAST_SLEEP') || (props.type == 'latest' && key == 'FAST_SLEEP')) && <Text onClick={showLatest}>Durations by 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' && isOpen && props.type != 'record' && checkData && <Modal children={layoutContent()} dismiss={() => setIsOpen(false)} confirm={() => { }} />
|
|
|
+ }
|
|
|
+ {
|
|
|
+ key == 'FAST_SLEEP' && isOpen && props.type == 'record' && props.data.scenario == 'FAST_SLEEP' && <Modal children={layoutContent()} dismiss={() => setIsOpen(false)} confirm={() => { }} />
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ props.type == 'record' && <Text style={{ position: 'absolute', right: 20, top: 20 }} onClick={more}>More</Text>
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ </View >
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDuration(obj) {
|
|
|
+ if (!obj) {
|
|
|
+ debugger
|
|
|
}
|
|
|
- {
|
|
|
- ((props.type == 'record' && props.data.scenario == 'FAST_SLEEP') || (props.type == 'latest' && key == 'FAST_SLEEP')) && <Text onClick={showLatest}>Durations by stage</Text>
|
|
|
+ if (obj.status == 'NOT_STARTED' || obj.status == 'NOT_COMPLETED') {
|
|
|
+ return ''
|
|
|
}
|
|
|
- {
|
|
|
- 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>)
|
|
|
+ var start = obj.real_start_time
|
|
|
+ var end = obj.real_end_time
|
|
|
+ if (!end) {
|
|
|
+ end = (new Date()).getTime()
|
|
|
}
|
|
|
- {
|
|
|
- key == 'FAST_SLEEP' && isOpen && props.type != 'record' && checkData && <Modal children={layoutContent()} dismiss={() => setIsOpen(false)} confirm={() => { }} />
|
|
|
+ return TimeFormatter.calculateTimeDifference(start, end)
|
|
|
+ }
|
|
|
+
|
|
|
+ function showDetail(record) {
|
|
|
+ setShowDetailModal(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ function recordDetail() {
|
|
|
+ var record = getRecord()
|
|
|
+ var fastDuration = ''
|
|
|
+ var sleepDuration = ''
|
|
|
+ if (record.scenario == 'FAST_SLEEP') {
|
|
|
+ fastDuration = getDuration(record.fast)
|
|
|
+ sleepDuration = getDuration(record.sleep)
|
|
|
}
|
|
|
- {
|
|
|
- key == 'FAST_SLEEP' && isOpen && props.type == 'record' && props.data.scenario == 'FAST_SLEEP' && <Modal children={layoutContent()} dismiss={() => setIsOpen(false)} confirm={() => { }} />
|
|
|
+ else if (record.scenario == 'FAST') {
|
|
|
+ fastDuration = getDuration(record.fast)
|
|
|
}
|
|
|
-
|
|
|
- {/* {
|
|
|
- key == 'FAST_SLEEP' && <AtFloatLayout
|
|
|
- isOpened={isOpen}
|
|
|
- onClose={() => {
|
|
|
- // stopTimer()
|
|
|
- setIsOpen(false)
|
|
|
- }}
|
|
|
- title="这是个标题">
|
|
|
+ else {
|
|
|
+ sleepDuration = getDuration(record.sleep)
|
|
|
+ }
|
|
|
+ return <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
+ {
|
|
|
+ rings()
|
|
|
+ }
|
|
|
+ <View className="duration_bg">
|
|
|
+ {
|
|
|
+ fastDuration.length > 0 && <Text className="duration_title">断食</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ fastDuration.length > 0 && <Text className="duration_value" style={{ color: '#AAFF00' }}>{fastDuration}</Text>
|
|
|
+ }
|
|
|
{
|
|
|
- props.type != 'record'&&checkData && layoutContent()
|
|
|
+ sleepDuration.length > 0 && <Text className="duration_title">睡眠</Text>
|
|
|
}
|
|
|
{
|
|
|
- props.type == 'record' && props.data.scenario=='FAST_SLEEP' && layoutContent()
|
|
|
+ sleepDuration.length > 0 && <Text className="duration_value" style={{ color: '#00FFFF' }}>{sleepDuration}</Text>
|
|
|
}
|
|
|
+ </View>
|
|
|
+ <Image className="arrow1" src={require('@/assets/images/arrow.png')} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
|
|
|
+ function header() {
|
|
|
+ if (props.type == 'latest') {
|
|
|
+ return <Header title="最近记录" action={() => {
|
|
|
+ Taro.navigateTo({
|
|
|
+ url: '/pages/common/RecordsHistory?type=time&title=time'
|
|
|
+ })
|
|
|
+ }} />
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ }
|
|
|
|
|
|
- </AtFloatLayout>
|
|
|
- } */}
|
|
|
+ if (props.type == 'record' || props.type == 'latest') {
|
|
|
+ var record = getRecord()
|
|
|
+ if (!record) return <View />
|
|
|
+ return <Box header={header()}>
|
|
|
+ <RecordItem canDel={record.status == 'COMPLETED'} delete={del}
|
|
|
+ onClick={() => { showDetail(record) }}
|
|
|
+ >{recordDetail()}
|
|
|
+ </RecordItem>
|
|
|
+ {
|
|
|
+ showDetailModal && <Modal children={schedules()}
|
|
|
+ modalType={ModalType.center}
|
|
|
+ dismiss={() => setShowDetailModal(false)}
|
|
|
+ confirm={() => { }} />
|
|
|
+ }
|
|
|
+ </Box>
|
|
|
+ // return <RecordItem canDel={record.status == 'COMPLETED'} delete={del}>{detail()}</RecordItem>
|
|
|
+ }
|
|
|
|
|
|
+ return <Box title={t('page.clock.schedule.title')}>
|
|
|
{
|
|
|
- props.type == 'record' && <Text style={{ position: 'absolute', right: 20, top: 20 }} onClick={more}>More</Text>
|
|
|
+ detail()
|
|
|
}
|
|
|
- <Text style={{ opacity: 0 }}>{counter}</Text>
|
|
|
+ </Box>
|
|
|
+
|
|
|
|
|
|
- </View >
|
|
|
}
|