import { View, Swiper, SwiperItem, Text } from "@tarojs/components"; import './MainCard.scss'; import MainDayNightCard from "./MainDayNightCard"; import MainFastEatCard from "./MainFastEatCard"; import MainSleepActiveCard from "./MainSleepActiveCard"; import { useState } from "react"; import { WindowType } from "@/utils/types"; import { useDispatch, useSelector } from "react-redux"; import { setTab } from "@/store/health"; import { MainColorType } from "@/context/themes/color"; import { rpxToPx } from "@/utils/tools"; import dayjs from "dayjs"; let scrollPage = 0; export default function MainSwiper(props: { count: number, pageChanged: Function, typeChanged: Function }) { const [current, setCurrent] = useState(0) const [type, setType] = useState(WindowType.day) const health = useSelector((state: any) => state.health); const [scale0, setScale0] = useState(1.0) const [scale1, setScale1] = useState(0.8) const [scale2, setScale2] = useState(0.8) const dispatch = useDispatch() function pageChanged(e) { const page = e.detail.current console.log(page) setCurrent(page) props.pageChanged(page) var strType = WindowType.day if (page == 0) { strType = WindowType.day } else if (page == 1) { strType = WindowType.fast } else { strType = WindowType.sleep } props.typeChanged(strType) dispatch(setTab(page % 3)) } function typeChanged(e) { setType(e) props.typeChanged(e) } function onTransition(e) { let x = e.detail.dx let scale0 = 0 let scale1 = 0 let scale2 = 0 const pageWidth = 143 if (x >= -pageWidth && x <= pageWidth) { switch (scrollPage) { case 0: case 3: { scale0 = 1 - Math.abs(x) / pageWidth * 0.2 scale1 = x > 0 ? 1 - (pageWidth - x) / pageWidth * 0.2 : 0.8 scale2 = x < 0 ? 1 - (pageWidth + x) / pageWidth * 0.2 : 0.8 } break; case 1: case 4: { scale0 = x < 0 ? 1 - (pageWidth + x) / pageWidth * 0.2 : 0.8 scale1 = 1 - Math.abs(x) / pageWidth * 0.2 scale2 = x > 0 ? 1 - (pageWidth - x) / pageWidth * 0.2 : 0.8 } break; case 2: case 5: { scale0 = x > 0 ? 1 - (pageWidth - x) / pageWidth * 0.2 : 0.8 scale1 = x < 0 ? 1 - (pageWidth + x) / pageWidth * 0.2 : 0.8 scale2 = 1 - Math.abs(x) / pageWidth * 0.2 } break; } } else if (x >= -pageWidth*2 && x <= pageWidth*2) { switch (scrollPage) { case 0: case 3: { scale1 = 1 - (Math.abs(x)-pageWidth) / pageWidth * 0.2 scale2 = x > 0 ? 1 - (pageWidth - x+pageWidth) / pageWidth * 0.2 : 0.8 scale0 = x < 0 ? 1 - (pageWidth + x+pageWidth) / pageWidth * 0.2 : 0.8 } break; case 1: case 4: { scale1 = x < 0 ? 1 - (pageWidth + x+pageWidth) / pageWidth * 0.2 : 0.8 scale2 = 1 - (Math.abs(x)-pageWidth) / pageWidth * 0.2 scale0 = x > 0 ? 1 - (pageWidth - x+pageWidth) / pageWidth * 0.2 : 0.8 } break; case 2: case 5: { scale1 = x > 0 ? 1 - (pageWidth - x+pageWidth) / pageWidth * 0.2 : 0.8 scale2 = x < 0 ? 1 - (pageWidth + x+pageWidth) / pageWidth * 0.2 : 0.8 scale0 = 1 - (Math.abs(x)-pageWidth) / pageWidth * 0.2 } break; } } else if (x >= -pageWidth*3 && x <= pageWidth*3) { switch (scrollPage) { case 0: case 3: { scale2 = 1 - (Math.abs(x)-pageWidth*2) / pageWidth * 0.2 scale0 = x > 0 ? 1 - (pageWidth - x+pageWidth*2) / pageWidth * 0.2 : 0.8 scale1 = x < 0 ? 1 - (pageWidth + x+pageWidth*2) / pageWidth * 0.2 : 0.8 } break; case 1: case 4: { scale2 = x < 0 ? 1 - (pageWidth + x+pageWidth*2) / pageWidth * 0.2 : 0.8 scale0 = 1 - (Math.abs(x)-pageWidth*2) / pageWidth * 0.2 scale1 = x > 0 ? 1 - (pageWidth - x+pageWidth*2) / pageWidth * 0.2 : 0.8 } break; case 2: case 5: { scale2 = x > 0 ? 1 - (pageWidth - x+pageWidth*2) / pageWidth * 0.2 : 0.8 scale0 = x < 0 ? 1 - (pageWidth + x+pageWidth*2) / pageWidth * 0.2 : 0.8 scale1 = 1 - (Math.abs(x)-pageWidth*2) / pageWidth * 0.2 } break; } } setScale0(scale0) setScale1(scale1) setScale2(scale2) } function onTransitionend(){ scrollPage = current } return Today {global.language == 'en' ? dayjs().format('dddd, MMM D') : dayjs().format('MMMDæ—¥, dddd')} {/* tapScroll(0)}> tapScroll(1)}> tapScroll(2)}> */} { setCurrent(0) }} /> { setCurrent(1) }} /> { setCurrent(2) }} /> { setCurrent(3) }} /> { setCurrent(4) }} /> { setCurrent(5) }} /> {/* setCurrent(0)}> setCurrent(1)}> setCurrent(2)}> */} }