|
|
@@ -1,7 +1,7 @@
|
|
|
-import { View, Text, Image } from "@tarojs/components";
|
|
|
+import { View, Text, Image, ScrollView } from "@tarojs/components";
|
|
|
import Tabbar from "@/components/navigation/TabBar";
|
|
|
import IndexItem from '@/features/trackTimeDuration/components/IndexItem';
|
|
|
-
|
|
|
+import Rings from "@/features/trackTimeDuration/components/Rings";
|
|
|
import './Index.scss'
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
import { useReady } from "@tarojs/taro";
|
|
|
@@ -14,6 +14,8 @@ import { setScenario } from "@/store/scenario";
|
|
|
import { useEffect, useState } from "react";
|
|
|
import { IconPlus, IconRadioCheck, IconRadioCross } from "@/components/basic/Icons";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
+import { getBgRing, getCommon, getDot, getSchedule } from "@/features/trackTimeDuration/hooks/RingData";
|
|
|
+import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
|
|
|
|
|
|
export default function Page() {
|
|
|
const dispatch = useDispatch();
|
|
|
@@ -50,7 +52,7 @@ export default function Page() {
|
|
|
|
|
|
useEffect(() => {
|
|
|
// if (user.isLogin) {
|
|
|
- getCheckData()
|
|
|
+ getCheckData()
|
|
|
// }
|
|
|
}, [user.isLogin, time.status])
|
|
|
|
|
|
@@ -69,24 +71,118 @@ export default function Page() {
|
|
|
})
|
|
|
|
|
|
function getCheckData() {
|
|
|
- getClocks().then(res => {
|
|
|
- // setErrorPage(false)
|
|
|
- // setData(res as any)
|
|
|
- // dispatch(updateScenario((res as any).current_record))
|
|
|
- // dispatch(setConfigs((res as any).time_input_schema));
|
|
|
- // dispatch(setScenario((res as any).scenario));
|
|
|
-
|
|
|
- if ((res as any).theme_color) {
|
|
|
- global.fastColor = (res as any).theme_color.fast
|
|
|
- global.sleepColor = (res as any).theme_color.sleep
|
|
|
- }
|
|
|
- })
|
|
|
+ // getClocks().then(res => {
|
|
|
+ // // setErrorPage(false)
|
|
|
+ // // setData(res as any)
|
|
|
+ // // dispatch(updateScenario((res as any).current_record))
|
|
|
+ // // dispatch(setConfigs((res as any).time_input_schema));
|
|
|
+ // // dispatch(setScenario((res as any).scenario));
|
|
|
+
|
|
|
+ // if ((res as any).theme_color) {
|
|
|
+ // global.fastColor = (res as any).theme_color.fast
|
|
|
+ // global.sleepColor = (res as any).theme_color.sleep
|
|
|
+ // }
|
|
|
+ // })
|
|
|
|
|
|
clockHome().then(res => {
|
|
|
setHomeData(res as any)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ const startArc = (time: number) => {
|
|
|
+ var date = new Date(time);
|
|
|
+ var hour = date.getHours();
|
|
|
+ var minute = date.getMinutes();
|
|
|
+ var second = date.getSeconds();
|
|
|
+ return (hour * 3600 + minute * 60 + second) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ const durationArc = (start_time: number, end_time: number) => {
|
|
|
+ var duration = (end_time - start_time) / 1000;
|
|
|
+ return duration / (24 * 3600) * 2 * Math.PI;
|
|
|
+ }
|
|
|
+
|
|
|
+ function bigRing() {
|
|
|
+ var currentRecord = (homeData as any).fast_sleep.current_record
|
|
|
+
|
|
|
+ var common = getCommon(null, true)
|
|
|
+ common.radius = 42;
|
|
|
+ common.lineWidth = 9;
|
|
|
+ var bgRing = getBgRing()
|
|
|
+ var realRing1 = getSchedule(currentRecord, true, true)
|
|
|
+ realRing1.color = ColorType.fast + '66'
|
|
|
+
|
|
|
+ var list: any = []
|
|
|
+ if (multiData[0].checked) {
|
|
|
+
|
|
|
+ const realRingBig: RealRing = {
|
|
|
+ color: global.fastColor ? global.fastColor : ColorType.fast,
|
|
|
+ startArc: startArc(currentRecord.fast.target_start_time),
|
|
|
+ durationArc: durationArc(currentRecord.fast.target_start_time, currentRecord.sleep.target_start_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ list.push(realRingBig)
|
|
|
+ }
|
|
|
+ if (multiData[1].checked) {
|
|
|
+ const realRingBig: RealRing = {
|
|
|
+ color: global.fastColor ? global.fastColor : ColorType.fast,
|
|
|
+ startArc: startArc(currentRecord.sleep.target_start_time),
|
|
|
+ durationArc: durationArc(currentRecord.sleep.target_start_time, currentRecord.sleep.target_end_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ list.push(realRingBig)
|
|
|
+ }
|
|
|
+ if (multiData[2].checked) {
|
|
|
+ const realRingBig: RealRing = {
|
|
|
+ color: global.fastColor ? global.fastColor : ColorType.fast,
|
|
|
+ startArc: startArc(currentRecord.sleep.target_end_time),
|
|
|
+ durationArc: durationArc(currentRecord.sleep.target_end_time, currentRecord.fast.target_end_time)
|
|
|
+ }
|
|
|
+
|
|
|
+ list.push(realRingBig)
|
|
|
+ }
|
|
|
+
|
|
|
+ var points: any = []
|
|
|
+ for (var i = 0; i < 12; i++) {
|
|
|
+ var dot: CurrentDot = {
|
|
|
+ color: 'red',
|
|
|
+ lineWidth: 8,
|
|
|
+ borderColor: 'black',
|
|
|
+ timestamp: new Date().getTime() + i * 3600 * 1000 * 2
|
|
|
+ }
|
|
|
+ points.push(dot)
|
|
|
+ }
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing1} stageList={list} dotList={points} canvasId={'testA'} />
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function smallRing() {
|
|
|
+ var common = getCommon(null, true)
|
|
|
+ common.radius = 28;
|
|
|
+ common.lineWidth = 9;
|
|
|
+ var bgRing = getBgRing()
|
|
|
+ var realRing1 = getSchedule((homeData as any).fast_sleep.current_record, false, false)
|
|
|
+ return <Rings common={common} bgRing={bgRing} realRing={realRing1} canvasId={'testB'} />
|
|
|
+ }
|
|
|
+
|
|
|
+ function rings() {
|
|
|
+ return <View style={{ display: 'flex', flexDirection: 'row', marginLeft: 100, marginBottom: 30 }}>
|
|
|
+ <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' }}>
|
|
|
+ {
|
|
|
+ smallRing()
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
async function getStorage(key: string) {
|
|
|
try {
|
|
|
const res = await Taro.getStorage({ key });
|
|
|
@@ -102,57 +198,71 @@ export default function Page() {
|
|
|
}
|
|
|
|
|
|
var timestamp = new Date().getTime()
|
|
|
- return <View className="index_container">
|
|
|
- <Text className="count">{count}</Text>
|
|
|
- <IndexItem type="FAST" data={(homeData as any).fast} time={timestamp} />
|
|
|
- <IndexItem type='SLEEP' data={(homeData as any).sleep} time={timestamp} />
|
|
|
- <Text className="discovery">探索</Text>
|
|
|
- <IndexItem type="FAST_SLEEP" data={(homeData as any).fast_sleep} time={timestamp} />
|
|
|
- <Tabbar index={0} />
|
|
|
-
|
|
|
- <View>
|
|
|
- <Text>Single Sel</Text>
|
|
|
- <View className={selIndex == 0 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(0)}>
|
|
|
- <Text className={selIndex == 0 ? "single_check_text_sel" : "single_check_text_nor"}>睡前断食</Text>
|
|
|
- {
|
|
|
- selIndex == 0 ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
|
|
|
- <IconPlus color={ColorType.fast} />
|
|
|
- }
|
|
|
+
|
|
|
+ function render() {
|
|
|
+ return <View className="index_container">
|
|
|
+ <Text className="count">{count}</Text>
|
|
|
+ <IndexItem type="FAST" data={(homeData as any).fast} time={timestamp} />
|
|
|
+ <IndexItem type='SLEEP' data={(homeData as any).sleep} time={timestamp} />
|
|
|
+ <Text className="discovery">探索</Text>
|
|
|
+ <IndexItem type="FAST_SLEEP" data={(homeData as any).fast_sleep} time={timestamp} />
|
|
|
+
|
|
|
+
|
|
|
+ <View>
|
|
|
+ <Text>Single Sel</Text>
|
|
|
+
|
|
|
+ <View className={selIndex == 0 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(0)}>
|
|
|
+ <Text className={selIndex == 0 ? "single_check_text_sel" : "single_check_text_nor"}>睡前断食</Text>
|
|
|
+ {
|
|
|
+ selIndex == 0 && <Image src={require('@assets/images/check_black.png')} className="single_checked" />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ <View className={selIndex == 1 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(1)}>
|
|
|
+ <Text className={selIndex == 1 ? "single_check_text_sel" : "single_check_text_nor"}>睡眠中断食</Text>
|
|
|
+ {
|
|
|
+ selIndex == 1 && <Image src={require('@assets/images/check_black.png')} className="single_checked" />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ <View className={selIndex == 2 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(2)}>
|
|
|
+ <Text className={selIndex == 2 ? "single_check_text_sel" : "single_check_text_nor"}>起床后断食</Text>
|
|
|
+ {
|
|
|
+ selIndex == 2 && <Image src={require('@assets/images/check_black.png')} className="single_checked" />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
</View>
|
|
|
- <View className={selIndex == 1 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(1)}>
|
|
|
- <Text className={selIndex == 1 ? "single_check_text_sel" : "single_check_text_nor"}>睡眠中断食</Text>
|
|
|
+
|
|
|
+ <View style={{ marginTop: 50 }}>
|
|
|
+ <Text>Multi Sel</Text>
|
|
|
{
|
|
|
- selIndex == 1 ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
|
|
|
- <IconPlus color={ColorType.fast} />
|
|
|
+ rings()
|
|
|
}
|
|
|
- </View>
|
|
|
- <View className={selIndex == 2 ? "single_check_sel" : "single_check_nor"} onClick={() => setSelIndex(2)}>
|
|
|
- <Text className={selIndex == 2 ? "single_check_text_sel" : "single_check_text_nor"}>起床后断食</Text>
|
|
|
{
|
|
|
- selIndex == 2 ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
|
|
|
- <IconPlus color={ColorType.fast} />
|
|
|
+ multiData.map((item) => {
|
|
|
+ return <View className={item.checked ? "single_check_sel" : "single_check_nor"} onClick={() => {
|
|
|
+ item.checked = !item.checked
|
|
|
+ setMultiData(JSON.parse(JSON.stringify(multiData)))
|
|
|
+ }}>
|
|
|
+ <Text className={item.checked ? "single_check_text_sel" : "single_check_text_nor"}>{item.title}</Text>
|
|
|
+ {
|
|
|
+ item.checked ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
|
|
|
+ <IconPlus color={ColorType.fast} />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ })
|
|
|
}
|
|
|
</View>
|
|
|
+
|
|
|
+ <View style={{ height: 100 }} />
|
|
|
+ <Tabbar index={0} />
|
|
|
</View>
|
|
|
+ }
|
|
|
|
|
|
- <View style={{ marginTop: 50 }}>
|
|
|
- <Text>Multi Sel</Text>
|
|
|
+ if (process.env.TARO_ENV=='rn'){
|
|
|
+ return <ScrollView>
|
|
|
{
|
|
|
- multiData.map((item) => {
|
|
|
- return <View className={item.checked ? "single_check_sel" : "single_check_nor"} onClick={() => {
|
|
|
- item.checked = !item.checked
|
|
|
- setMultiData(JSON.parse(JSON.stringify(multiData)))
|
|
|
- }}>
|
|
|
- <Text className={item.checked ? "single_check_text_sel" : "single_check_text_nor"}>{item.title}</Text>
|
|
|
- {
|
|
|
- item.checked ? <Image src={require('@assets/images/check_black.png')} className="single_checked" /> :
|
|
|
- <IconPlus color={ColorType.fast} />
|
|
|
- }
|
|
|
- </View>
|
|
|
- })
|
|
|
+ render()
|
|
|
}
|
|
|
- </View>
|
|
|
-
|
|
|
- <View style={{ height: 100 }} />
|
|
|
- </View>
|
|
|
+ </ScrollView>
|
|
|
+ }
|
|
|
+ return render()
|
|
|
}
|