|
|
@@ -1,19 +1,177 @@
|
|
|
-import { View } from "@tarojs/components";
|
|
|
+import { View, Text } from "@tarojs/components";
|
|
|
import './MainCard.scss'
|
|
|
import { useState } from "react";
|
|
|
import Modal from "@/components/layout/Modal.weapp";
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
+import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
|
|
|
+import dayjs from "dayjs";
|
|
|
+import moment from 'moment-timezone'
|
|
|
+import { MainColorType } from "@/context/themes/color";
|
|
|
|
|
|
-export default function MainFastEatCard(props:{count:any}) {
|
|
|
+export default function MainFastEatCard(props: { count: any }) {
|
|
|
const [isFast, setIsFast] = useState(true)
|
|
|
- const [showModal,setShowModal] = useState(false)
|
|
|
- return <View>
|
|
|
-
|
|
|
- <View style={{height:200,backgroundColor:'blue',width:rpxToPx(750)}}/>
|
|
|
- <View onClick={()=>{setShowModal(true)}}>Fast Eat Night{props.count}</View>
|
|
|
+ const [isFastMode, setIsFastMode] = useState(true)
|
|
|
+
|
|
|
+ const [showModal, setShowModal] = useState(false)
|
|
|
+
|
|
|
+ const startScheduleTime = '22:00'
|
|
|
+ const endScheduleTime = '10:00'
|
|
|
+ const startTime = '17:15'
|
|
|
+ const endTime = '18:00'
|
|
|
+
|
|
|
+ const common: RingCommon = {
|
|
|
+ useCase: 'ChooseScenario',
|
|
|
+ radius: 115,
|
|
|
+ lineWidth: 26,
|
|
|
+ isFast: true,
|
|
|
+ status: 'WAIT_FOR_START'
|
|
|
+ }
|
|
|
+
|
|
|
+ const bgRing: BgRing = {
|
|
|
+ color: '#EAE9E9'
|
|
|
+ }
|
|
|
+
|
|
|
+ function targetRing() {
|
|
|
+
|
|
|
+ var starts: any = startScheduleTime.split(':')
|
|
|
+ var ends: any = endScheduleTime.split(':')
|
|
|
+ const startSeconds: any = parseInt(starts[0] + '') * 60 + parseInt(starts[1] + '')
|
|
|
+ const endSeconds: any = parseInt(ends[0] + '') * 60 + parseInt(ends[1] + '')
|
|
|
+ const color = isFastMode ? '#9AE2FE' : '#FE810C66'
|
|
|
+ const startArc = isFastMode ? startSeconds / 1440 * 2 * Math.PI - Math.PI / 2 : endSeconds / 1440 * 2 * Math.PI - Math.PI / 2
|
|
|
+
|
|
|
+ const fastCount = endSeconds - startSeconds > 0 ? endSeconds - startSeconds : endSeconds - startSeconds + 1440
|
|
|
+ const eatCount = 1440 - fastCount
|
|
|
+
|
|
|
+ const durationArc = isFastMode ? fastCount / 1440 * 2 * Math.PI : eatCount / 1440 * 2 * Math.PI
|
|
|
+
|
|
|
+ return {
|
|
|
+ color,
|
|
|
+ startArc,
|
|
|
+ durationArc
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function realRing() {
|
|
|
+ if (isFastMode) {
|
|
|
+ if (isFast) {
|
|
|
+ var starts: any = startTime ? startTime.split(':') : startScheduleTime.split(':')
|
|
|
+ const startSeconds = parseInt(starts[0] + '') * 60 + parseInt(starts[1] + '')
|
|
|
+
|
|
|
+ const color = MainColorType.fast
|
|
|
+ const startArc = startSeconds / 1440 * 2 * Math.PI - Math.PI / 2
|
|
|
+ var endSeconds = new Date().getHours() * 60 + new Date().getMinutes()
|
|
|
+ if (endTime) {
|
|
|
+ var ends: any = endTime.split(':')
|
|
|
+ endSeconds = parseInt(ends[0] + '') * 60 + parseInt(ends[1] + '')
|
|
|
+ }
|
|
|
+ const fastCount = endSeconds - startSeconds > 0 ? endSeconds - startSeconds : endSeconds - startSeconds + 1440
|
|
|
+ const durationArc = fastCount / 1440 * 2 * Math.PI
|
|
|
+
|
|
|
+ return {
|
|
|
+ color,
|
|
|
+ startArc,
|
|
|
+ durationArc
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (isCurrentTimeInRange(endScheduleTime,startScheduleTime)){
|
|
|
+ var starts: any = endScheduleTime.split(':')
|
|
|
+ const startSeconds = parseInt(starts[0] + '') * 60 + parseInt(starts[1] + '')
|
|
|
+
|
|
|
+ const color = MainColorType.eat
|
|
|
+ const startArc = startSeconds / 1440 * 2 * Math.PI - Math.PI / 2
|
|
|
+ var endSeconds = new Date().getHours() * 60 + new Date().getMinutes()
|
|
|
+
|
|
|
+ const fastCount = endSeconds - startSeconds > 0 ? endSeconds - startSeconds : endSeconds - startSeconds + 1440
|
|
|
+ const durationArc = fastCount / 1440 * 2 * Math.PI
|
|
|
+
|
|
|
+ return {
|
|
|
+ color,
|
|
|
+ startArc,
|
|
|
+ durationArc
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function isCurrentTimeInRange(start, end) {
|
|
|
+ // 获取当前时间
|
|
|
+ const now = new Date();
|
|
|
+ const currentTime = now.getHours() * 60 + now.getMinutes(); // 当前时间转换为分钟
|
|
|
+
|
|
|
+ // 将时间点转换为分钟
|
|
|
+ const [startHour, startMinute] = start.split(':').map(Number);
|
|
|
+ const [endHour, endMinute] = end.split(':').map(Number);
|
|
|
+ const startTime = startHour * 60 + startMinute; // 开始时间转换为分钟
|
|
|
+ const endTime = endHour * 60 + endMinute; // 结束时间转换为分钟
|
|
|
+
|
|
|
+ // 处理跨日的情况
|
|
|
+ if (endTime < startTime) {
|
|
|
+ return currentTime >= startTime || currentTime <= endTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断当前时间是否在范围内
|
|
|
+ return currentTime >= startTime && currentTime <= endTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ function ring() {
|
|
|
+ var offset = 0
|
|
|
+
|
|
|
+ var hour = new Date().getHours()
|
|
|
+ var minute = new Date().getMinutes()
|
|
|
+
|
|
|
+ if (hour != new Date().getHours() || minute != new Date().getMinutes()) {
|
|
|
+ offset = hour * 60 + minute - new Date().getHours() * 60 - new Date().getMinutes()
|
|
|
+ }
|
|
|
+
|
|
|
+ const currentDot: CurrentDot = {
|
|
|
+ color: isFastMode ? MainColorType.fast : MainColorType.eat,
|
|
|
+ lineWidth: 10,
|
|
|
+ borderColor: '#fff',
|
|
|
+ offset: offset,
|
|
|
+ whiteIcon: true
|
|
|
+ }
|
|
|
+
|
|
|
+ return <Rings common={common} bgRing={bgRing} targetRing={targetRing()} realRing={realRing()} currentDot={currentDot} canvasId={'smal11l'} />
|
|
|
+ }
|
|
|
+
|
|
|
+ function formatTime(format: string, timestamp?: number) {
|
|
|
+ // var moment = require('moment-timezone');
|
|
|
+ // if (current) {
|
|
|
+ // if (timestamp) {
|
|
|
+ // return moment(timestamp).tz(current.time.timezone.id).format(format)
|
|
|
+ // }
|
|
|
+ // return moment().tz(current.time.timezone.id).format(format)
|
|
|
+ // }
|
|
|
+
|
|
|
+ return dayjs().format(format)
|
|
|
+ }
|
|
|
+
|
|
|
+ function switchMode() {
|
|
|
+ setIsFastMode(!isFastMode)
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View style={{ alignItems: 'center', display: 'flex', flexDirection: 'column' }}>
|
|
|
+
|
|
|
+ <View style={{ width: rpxToPx(750), }} />
|
|
|
+ <View onClick={() => { setShowModal(true) }}>Fast Eat Night{props.count}</View>
|
|
|
+ <View style={{ height: 40 }} />
|
|
|
+ <View style={{ position: 'relative', }}>
|
|
|
+ {
|
|
|
+ ring()
|
|
|
+ }
|
|
|
+ <View className="ring_center">
|
|
|
+ <Text className="time1">{formatTime('HH:mm:ss')}</Text>
|
|
|
+ <Text className="date1">{global.language == 'en' ? formatTime('dddd, MMM D') : formatTime('MMMD日 dddd')}</Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <Text onClick={switchMode}>Switch</Text>
|
|
|
{
|
|
|
- showModal && <Modal dismiss={()=>setShowModal(false)}>
|
|
|
- <View style={{width:100,height:100,backgroundColor:'red'}}>{props.count}</View>
|
|
|
+ showModal && <Modal dismiss={() => setShowModal(false)}>
|
|
|
+ <View style={{ width: 100, height: 100, backgroundColor: 'red' }}>{props.count}</View>
|
|
|
</Modal>
|
|
|
}
|
|
|
</View>
|