Leon 1 éve
szülő
commit
acd81fe916

+ 107 - 0
src/features/health/calendar.scss

@@ -0,0 +1,107 @@
+.calendar_main{
+    width: 750px;
+}
+
+.calendar_header{
+    width: 750px;
+    height: 56px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    color: #808080;
+    font-size: 34px;
+}
+
+.calendar_body{
+    margin-top: 38px;
+    display: flex;
+    flex-direction: column;
+}
+
+.calendar_weekly{
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+}
+
+.week_item{
+    flex:1;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    font-size: 26px;
+    color:#B2B2B2;
+}
+
+.calendar_main{
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+    flex-wrap: wrap;
+    width: 750px;
+}
+
+.left_calendar_item{
+    height: 74px;
+    margin-bottom: 16px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-shrink: 0;
+    background-color: #26B7FF1A;
+    border-top-left-radius: 37px;
+    border-bottom-left-radius: 37px;
+}
+
+.right_calendar_item{
+    height: 74px;
+    margin-bottom: 16px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-shrink: 0;
+    background-color: #26B7FF1A;
+    border-top-right-radius: 37px;
+    border-bottom-right-radius: 37px;
+}
+
+.full_calendar_item{
+    height: 74px;
+    margin-bottom: 16px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-shrink: 0;
+    background-color: #26B7FF1A;
+    border-radius: 37px;
+}
+
+.calendar_item{
+    height: 74px;
+    margin-bottom: 16px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex-shrink: 0;
+    
+}
+
+.left_day{
+    color:#26B7FF;
+    font-size: 34px;
+}
+
+.right_day{
+    color:#26B7FF;
+    font-size: 34px;
+}
+
+.full_day{
+    color:#26B7FF;
+    font-size: 34px;
+}
+
+.normal_day{
+    color:#808080;
+    font-size: 34px;
+}

+ 109 - 0
src/features/health/calendar.tsx

@@ -0,0 +1,109 @@
+import { View, Text } from "@tarojs/components";
+import './calendar.scss'
+import dayjs from "dayjs";
+import { useEffect, useState } from "react";
+import { rpxToPx } from "@/utils/tools";
+
+export default function Calendar(props: { year: number, month: number }) {
+    const weeks = ['日', '一', '二', '三', '四', '五', '六']
+    const indexBeginWeek = 0;
+    const [spaces, setSpaces] = useState<any>([])
+    const [days, setDays] = useState<any>([])
+
+    useEffect(() => {
+        loadData()
+    }, [])
+
+    function loadData() {
+        const firstDay = new Date(props.year, props.month - 1, 1);
+        const firstDayOfWeek = firstDay.getDay();
+        const spaceCount = firstDayOfWeek > indexBeginWeek ? firstDayOfWeek - indexBeginWeek : firstDayOfWeek - indexBeginWeek + 7
+        setSpaces(new Array(spaceCount).fill(''))
+
+
+        // 创建一个 Date 对象来获取该月的最后一天
+        const lastDay = new Date(props.year, props.month, 0); // 0 表示上一个月的最后一天
+        const totalDays = lastDay.getDate();
+        var list: any = []
+        for (var i = 1; i <= totalDays; i++) {
+            var obj: any = {
+                day: i
+            }
+            if (i == 1 || i == 10 || i == 15) {
+                obj.begin = true
+            }
+            if (i == 2 || i == 11 || i == 16) {
+                obj.right = true
+            }
+
+            if (i == 22) {
+                obj.full = true
+            }
+
+            list.push(obj)
+        }
+        setDays(list)
+    }
+
+    function itemClass(item) {
+        if (item.begin) {
+            return 'left_calendar_item'
+        }
+        if (item.center) {
+            return 'center_calendar_item'
+        }
+        if (item.right) {
+            return 'right_calendar_item'
+        }
+        if (item.full) {
+            return 'full_calendar_item'
+        }
+        return 'calendar_item'
+    }
+
+    function itemTextClass(item) {
+        if (item.begin) {
+            return 'left_day'
+        }
+        if (item.center) {
+            return 'center_day'
+        }
+        if (item.right) {
+            return 'right_day'
+        }
+        if (item.full) {
+            return 'full_day'
+        }
+        return 'normal_day'
+    }
+
+    return <View className="calendar_main">
+        <View className="calendar_header">{dayjs().format('YYYY年M月')}</View>
+        <View className="calendar_body">
+            <View className="calendar_weekly">
+                {
+                    weeks.map((item, index) => {
+                        return <View className="week_item" key={index}>{item}</View>
+                    })
+                }
+            </View>
+            <View className="calendar_main">
+                {
+                    spaces.map((item, i) => {
+                        return <View className="calendar_item" style={{ width: rpxToPx(750) / 7 }} key={i * 10} />
+                    })
+                }
+                {
+                    days.map((item, index) => {
+                        return <View className={itemClass(item)} style={{ width: rpxToPx(750) / 7 }} key={index}>
+                            <Text className={itemTextClass(item)}>{item.day}</Text>
+                        </View>
+                    })
+                }
+            </View>
+        </View>
+        <View className="calendar_footer">
+
+        </View>
+    </View>
+}

+ 2 - 0
src/features/trackTimeDuration/components/MainDayNightCard.tsx

@@ -10,6 +10,7 @@ import momentT from 'moment';
 // import moment from 'moment-timezone'
 import { MainColorType } from "@/context/themes/color";
 import { useSelector } from "react-redux";
+import Calendar from "@/features/health/calendar";
 
 export default function MainDayNightCard(props: { count: number }) {
     const [isDay, setIsDay] = useState(true)
@@ -132,6 +133,7 @@ export default function MainDayNightCard(props: { count: number }) {
     }
 
     return <View style={{ width: rpxToPx(750), display: 'flex', flexShrink: 0, flexDirection: 'column', alignItems: 'center' }}>
+        <Calendar year={2024} month={8}/>
         <View>Page Day Night</View>
         <View style={{ position: 'relative' }}>
             {

+ 3 - 2
src/pages/clock/ClockNew.tsx

@@ -47,11 +47,12 @@ export default function ClockNew() {
             style={{ width: rpxToPx(750), display: 'flex', flexDirection: 'row', overflow: 'hidden' }}
             enhanced>
             <View style={{ display: 'flex', flexShrink: 0, width: rpxToPx(750) }}>
-                <MainFastEatCard count={count} />
+                <MainDayNightCard count={count} />
             </View>
             <View style={{ display: 'flex', flexShrink: 0, width: rpxToPx(750) }}>
-                <MainDayNightCard count={count} />
+                <MainFastEatCard count={count} />
             </View>
+
             <View style={{ display: 'flex', flexShrink: 0, width: rpxToPx(750) }}>
                 <MainSleepActiveCard count={count} />
             </View>