leon 1 år sedan
förälder
incheckning
5784ffc462

+ 0 - 0
src/_eat/components/add_label.scss → src/_health/components/add_label.scss


+ 1 - 1
src/_eat/components/add_label.tsx → src/_health/components/add_label.tsx

@@ -44,7 +44,7 @@ export default function AddLabel(props: { labels: any }) {
             
             event:'EAT_CUSTOM',
             title:value,
-            time:e,is_all_day:true
+            time:e,is_all_day:false
         }).then(res=>{
             global.refreshWindow()
             if (process.env.TARO_ENV=='weapp'){

+ 0 - 0
src/pages/clock/AddMoment.scss → src/_health/pages/add_moment.scss


+ 1 - 1
src/pages/clock/AddMoment.tsx → src/_health/pages/add_moment.tsx

@@ -1,7 +1,7 @@
 import { View, Text, Textarea, Image, Input } from "@tarojs/components";
 import Taro, { useRouter } from "@tarojs/taro";
 import { useTranslation } from "react-i18next";
-import './AddMoment.scss'
+import './add_moment.scss'
 import { useEffect, useState } from "react";
 import { saveFoodCache } from "@/features/food/hooks/ExtraData";
 import { baseUrl } from "@/services/http/api";

+ 0 - 0
src/_eat/pages/meal_list.scss → src/_health/pages/edit_schedule.scss


+ 0 - 0
src/_eat/pages/meal_list.ts.config → src/_health/pages/edit_schedule.ts.config


+ 9 - 4
src/_eat/pages/meal_list.tsx → src/_health/pages/edit_schedule.tsx

@@ -1,24 +1,26 @@
 import { View, Text } from '@tarojs/components'
-import './meal_list.scss'
+import './edit_schedule.scss'
 import { useEffect, useState } from 'react'
 import Modal from '@/components/layout/Modal.weapp'
 import AddLabel from '../components/add_label'
 import { delSchedule, getLabels, getSchedules } from '@/services/health'
 import { AtSwipeAction } from "taro-ui"
+import { useSelector } from 'react-redux'
 
 
-export default function MealList() {
+export default function EditSchedule() {
     const [showModal, setShowModal] = useState(false)
     const [list, setList] = useState<any>([])
     const [labels, setLabels] = useState<any>([])
     const [showDel, setShowDel] = useState(false)
+    const health = useSelector((state: any) => state.health);
 
     useEffect(() => {
         schedules()
     }, [])
 
     function schedules() {
-        getSchedules({ window: 'EAT',is_all_day:true }).then(res => {
+        getSchedules({ window: health.mode,is_all_day:false }).then(res => {
             console.log('sss',res)
             if ((res as any).data && (res as any).data.length > 0) {
                 setList((res as any).data)
@@ -61,7 +63,10 @@ export default function MealList() {
                         }
         
                         <View className='item_left'>
-                            <Text className='item_index'>第{index + 1}餐</Text>
+                            {
+                                health.mode == 'EAT' && <Text className='item_index'>第{index + 1}餐</Text>
+                            }
+                            
                             <Text className='item_name'>{item.title}</Text>
                         </View>
                         <Text className='item_time'>{item.time}</Text>

+ 0 - 0
src/_health/pages/setting_reminder.scss


+ 0 - 0
src/_health/pages/setting_reminder.ts.config


+ 6 - 0
src/_health/pages/setting_reminder.tsx

@@ -0,0 +1,6 @@
+import { View } from '@tarojs/components'
+import './edit_schedule.scss'
+
+export default function SettingReminder(){
+    return <View></View>
+}

+ 5 - 3
src/app.config.ts

@@ -6,7 +6,7 @@ const appConfig = defineAppConfig({
     'pages/clock/Clock',
     // 'pages/clock/Suggest',
     // 'pages/clock/SetGoal',
-    'pages/clock/AddMoment',
+    
     // 'pages/demo',
     // 'pages/food/Food',
     'pages/account/Login',
@@ -43,9 +43,11 @@ const appConfig = defineAppConfig({
   // ],
   subPackages: [
     {
-      root: '_eat',
+      root: '_health',
       pages: [
-        'pages/meal_list'
+        'pages/add_moment',
+        'pages/edit_schedule',
+        'pages/setting_reminder'
       ]
     }
   ],

+ 17 - 0
src/features/health/History.scss

@@ -13,6 +13,7 @@
 }
 
 .history_ring {
+    display: flex;
     position: relative;
     width: 76px;
     height: 76px;
@@ -81,4 +82,20 @@
     height: 157px;
     margin-right: 2px;
     margin-bottom: 2px;
+}
+
+.recent {
+    background-color: #fff;
+    position: relative;
+    height: 108px;
+    padding-left: 52px;
+    padding-right: 40px;
+    display: flex;
+    align-items: center;
+}
+
+.recent_text{
+    font-weight: bold;
+    color: #000;
+    font-size: 26px;
 }

+ 20 - 4
src/features/health/HistoryItem.tsx

@@ -62,6 +62,19 @@ export default function HistoryItem(props: { data: any, index: number }) {
         return <Rings common={common} bgRing={bgRing} realRing={realRing} canvasId={'history_' + props.index} />
     }
 
+    function mediaCount(){
+        let count = 0;
+        props.data.events.map((item) => {
+            if (item.moment){
+                item.moment.media.map((obj, j) => {
+                    count++;
+                })
+            }
+            
+        })
+        return count;
+    }
+
     return <View className="history_item">
         <View className="history_ring">
             {
@@ -85,12 +98,15 @@ export default function HistoryItem(props: { data: any, index: number }) {
                     })
                 }
             </Text>
-            <View className="media" style={{ marginTop: 9 }}>
+            <View className="media" style={{ marginTop: mediaCount()>0?9:-10 }}>
                 {
                     props.data.events.map((item) => {
-                        return item.moment.media.map((obj, j) => {
-                            return <Image className="media_item" mode="aspectFill" onClick={() => preview(obj)} src={obj.url} key={j * 10} />
-                        })
+                        if (item.moment){
+                            return item.moment.media.map((obj, j) => {
+                                return <Image className="media_item" mode="aspectFill" onClick={() => preview(obj)} src={obj.url} key={j * 10} />
+                            })
+                        }
+                        
                     })
                 }
             </View>

+ 136 - 42
src/features/health/MainConsole.tsx

@@ -8,12 +8,12 @@ import { jumpPage } from "../trackTimeDuration/hooks/Common";
 import Modal from "@/components/layout/Modal.weapp";
 import { MainColorType } from "@/context/themes/color";
 import ConsolePicker from "../trackTimeDuration/components/ConsolePicker";
-import { clockTimes, updateSchedule, updateTarget } from "@/services/health";
+import { clockTimes, makeDone, updateSchedule, updateTarget } from "@/services/health";
 import TimePicker from "../common/TimePicker";
 import showActionSheet from "@/components/basic/ActionSheet";
 import { rpxToPx } from "@/utils/tools";
 import { setMode } from "@/store/health";
-import { getCountownTime, getDuration, getScenario, getWindowStatus } from "./hooks/health_hooks";
+import { getCountownTime, getDuration, getScenario, getThemeColor, getWindowStatus } from "./hooks/health_hooks";
 import { IconMore } from "@/components/basic/Icons";
 
 let useNavigation;
@@ -95,7 +95,7 @@ export default function MainConsole(props: { type: WindowType }) {
                 return;
 
         }
-        jumpPage('/pages/clock/AddMoment?moment=' + JSON.stringify(item))
+        jumpPage('/_health/pages/clock/add_moment?moment=' + JSON.stringify(item))
     }
 
     function operateTitle(item) {
@@ -118,7 +118,7 @@ export default function MainConsole(props: { type: WindowType }) {
     }
 
     function itemValue(item: any) {
-        let themeColor: any = getThemeColor()
+        let themeColor: any = getThemeColor(health.mode)
         const scenario = getScenario(health.windows, health.mode)
         if (item.action == 'END' && !scenario.real) {
             themeColor = '#B2B2B2'
@@ -181,11 +181,11 @@ export default function MainConsole(props: { type: WindowType }) {
         var title, color;
         switch (selItem.scenario) {
             case 'FAST':
-                title = operateType == 'endFast' ? '结束断食' : '开始断食'
+                title = selItem.event == 'FAST_END' ? '结束断食' : '开始断食'
                 color = MainColorType.fast
                 break;
             case 'SLEEP':
-                title = operateType == 'endFast' ? '结束睡眠' : '开始睡眠'
+                title = selItem.event == 'SLEEP_END' ? '结束睡眠' : '开始睡眠'
                 color = MainColorType.sleep
         }
 
@@ -233,7 +233,6 @@ export default function MainConsole(props: { type: WindowType }) {
                 return;
             }
         }
-        console.log('zzz')
 
         updateSchedule({
             time: strTime
@@ -262,16 +261,16 @@ export default function MainConsole(props: { type: WindowType }) {
         var title, color;
         switch (selItem.scenario) {
             case 'FAST':
-                title = operateType == 'endFast' ? '结束断食' : '开始断食'
+                title = selItem.event == 'FAST_END' ? '结束断食' : '开始断食'
                 color = MainColorType.fast
                 break;
             case 'SLEEP':
-                title = operateType == 'endFast' ? '结束睡眠' : '开始睡眠'
+                title = selItem.event == 'FAST_SLEEP' ? '结束睡眠' : '开始睡眠'
                 color = MainColorType.sleep
         }
 
         var endTimestamp = 0
-        if (operateType == 'endFast') {
+        if (selItem.envent == 'FAST_END') {
             endTimestamp = new Date().getTime()//fastData.target.end_time
         }
 
@@ -324,42 +323,138 @@ export default function MainConsole(props: { type: WindowType }) {
     }
 
     function more() {
+        var list: any = []
+        switch (health.mode) {
+            case 'DAY':
+            case 'NIGHT':
+                list = ['设置提醒']
+                break;
+            case 'FAST':
+            case 'SLEEP':
+                {
+                    const obj = getScenario(health.windows, health.mode)
+                    if (obj.window_id) {
+                        list.push('编辑本次时长')
+                        if (obj.timeline && obj.timeline[0].moment) {
+                            list.push('删除本次记录')
+                        }
+                    }
+                    else {
+                        list = ['编辑日程']
+                    }
+                }
+                break;
+            case 'EAT':
+                {
+                    list = [
+                        'Add Snack',
+                        '自定义餐次列表',
+                    ]
+
+                    if (getScenario(health.windows, health.mode).window_id) {
+                        list.push('Make done')
+                    }
+                }
+                break;
+            case 'ACTIVE':
+                {
+                    list = [
+                        '记录一次活动',
+                        '编辑日程',
+                    ]
+
+                    if (getScenario(health.windows, health.mode).window_id) {
+                        list.push('Make done')
+                    }
+                }
+                break;
+
+        }
+
+
+
         showActionSheet({
             showActionSheetWithOptions: showActionSheetWithOptions,
             title: 'Oprate Title',
-            itemList: [
-                'Add Snack',
-                '自定义餐次列表',
-            ],
+            itemList: list,
             success: (res) => {
-                switch (res) {
-                    case 0:
-                        break;
-                    case 1:
-                        jumpPage('/_eat/pages/meal_list')
-                        break;
-                }
+                tapActionSheet(res)
             }
         });
     }
 
-    function getThemeColor() {
-        switch (health.mode) {
-            case 'DAY':
-                return MainColorType.day;
-            case 'NIGHT':
-                return MainColorType.night;
-            case 'FAST':
-                return MainColorType.fast;
-            case 'EAT':
-                return MainColorType.eat;
-            case 'SLEEP':
-                return MainColorType.sleep;
-            case 'ACTIVE':
-                return MainColorType.active;
+    function tapActionSheet(index) {
+        switch (index) {
+            case 0:
+                {
+                    switch (health.mode) {
+                        case 'DAY':
+                        case 'NIGHT':
+                            jumpPage('/_health/pages/setting_reminder')
+                            break;
+                        case 'FAST':
+                        case 'SLEEP':
+                            {
+                                const obj = getScenario(health.windows, health.mode)
+                                if (obj.window_id) {
+                                    //编辑本次时长
+                                }
+                                else {
+                                    jumpPage('/_health/pages/edit_schedule')
+                                }
+                            }
+                            break;
+                        case 'EAT':
+                            //add snack
+                            break;
+                        case 'ACTIVE':
+                            //记录一次活动
+                            break;
+                    }
+                }
+                break;
+            case 1:
+                {
+                    switch (health.mode) {
+                        case 'EAT':
+                            jumpPage('/_health/pages/edit_schedule')
+                            break;
+                        case 'FAST':
+                        case 'SLEEP':
+                            const obj = getScenario(health.windows, health.mode)
+                            if (obj.window_id) {
+                                //del record
+                            }
+                            else {
+
+                            }
+                            break;
+                        case 'ACTIVE':
+                            jumpPage('/_health/pages/edit_schedule')
+                            break;
+                    }
+                }
+                break;
+            case 2:
+                {
+                    switch (health.mode) {
+                        case 'EAT':
+                        case 'ACTIVE':
+                            tapMakeDone()
+                            break;
+                    }
+                }
+                break;
         }
     }
 
+    function tapMakeDone() {
+        makeDone(getScenario(health.windows, health.mode).window_id).then(res => {
+            global.refreshWindow()
+            global.refreshHistory()
+        })
+    }
+
     function detail() {
         const { day, night } = health.windows.night_day
         const { fast, eat } = health.windows.fast_eat
@@ -453,8 +548,8 @@ export default function MainConsole(props: { type: WindowType }) {
     return <View className="main-console-bg">
         <Image className="main_arrow" src={require('@assets/images/center_arrow.png')} />
         <View className="main_summary">
-            <View className="main_summary_status" style={{ color: getThemeColor() }}>{windowStatus()}</View>
-            <Text className="main_summary_time">{getCountownTime(health.windows, health.mode)}</Text>
+            <View className="main_summary_status" style={{ color: getThemeColor(health.mode) }}>{windowStatus()}</View>
+            <Text className="main_summary_time" style={{color:getWindowStatus(health.windows, health.mode)==WindowStatusType.upcoming?'#B2B2B2':'#000'}}>{getCountownTime(health.windows, health.mode)}</Text>
             <Text className="main_summary_duration">Total {getDuration(health.windows, health.mode)}</Text>
             <View className="border_footer_line" />
         </View>
@@ -468,11 +563,10 @@ export default function MainConsole(props: { type: WindowType }) {
             {/* {
                 (health.mode == 'EAT' || health.mode == 'ACTIVE') && <Text style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }} onClick={more}>更多</Text>
             } */}
-            {
-                (health.mode == 'EAT' || health.mode == 'ACTIVE') && <View className="main_footer_more" onClick={more}>
-                    <IconMore color="#b2b2b2" width={17}/>
-                </View>
-            }
+            <View className="main_footer_more" onClick={more}>
+                <IconMore color="#b2b2b2" width={17} />
+            </View>
+
         </View>
 
         {

+ 3 - 2
src/features/health/MainFastEatCard.tsx

@@ -146,7 +146,6 @@ export default function MainFastEatCard(props: { count: any, typeChanged: Functi
         const eatCount = 1440 - fastCount
 
         const durationArc = isFastMode ? fastCount / 1440 * 2 * Math.PI : eatCount / 1440 * 2 * Math.PI
-
         return {
             color,
             startArc,
@@ -179,6 +178,8 @@ export default function MainFastEatCard(props: { count: any, typeChanged: Functi
             durationArc = ((fastData.target.end_time - fastData.target.start_time) / 1000) / (1440 * 60) * 2 * Math.PI
         }
 
+        
+
         return {
             color,
             startArc,
@@ -560,7 +561,7 @@ export default function MainFastEatCard(props: { count: any, typeChanged: Functi
                     case 0:
                         break;
                     case 1:
-                        jumpPage('/_eat/pages/meal_list')
+                        jumpPage('/_health/pages/edit_schedule')
                         break;
                 }
             }

+ 7 - 1
src/features/health/MainHistory.tsx

@@ -78,6 +78,12 @@ export default function MainHistory(props: { type: string }) {
             backgroundColor: 'blue',
             zIndex: 100
         }} /> */}
+        {
+            list.length>0 && <View className="recent">
+                <Text className="recent_text">Recent</Text>
+                <View className="border_footer_line"/>
+            </View>
+        }
         {
             list.map((item, index) => {
                 return <View key={index}>
@@ -98,7 +104,7 @@ export default function MainHistory(props: { type: string }) {
             })
         }
         {
-            (total == list.length) && <Text className="no_more">没有更多了</Text>
+            (health.mode !='DAY' && health.mode !='NIGHT')&&(total == list.length) && <Text className="no_more">没有更多了</Text>
         }
     </View>
 }

+ 19 - 2
src/features/health/calendar.tsx

@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
 import { rpxToPx } from "@/utils/tools";
 import { streaks } from "@/services/health";
 import { useSelector } from "react-redux";
+import { getThemeColor } from "./hooks/health_hooks";
 
 export default function Calendar(props: { year: number, month: number }) {
     const weeks = ['日', '一', '二', '三', '四', '五', '六']
@@ -79,6 +80,8 @@ export default function Calendar(props: { year: number, month: number }) {
                     }
                 }
             }
+            setDays([...list])
+            // console.log(list)
         }).catch(e=>{
 
         })
@@ -116,6 +119,20 @@ export default function Calendar(props: { year: number, month: number }) {
         return 'normal_day'
     }
 
+    function bgColor(item){
+        if (itemClass(item)=='calendar_item'){
+            return 'transparent'
+        }
+        return getThemeColor(health.mode)+'33'
+    }
+
+    function textColor(item){
+        if (itemTextClass(item)=='normal_day'){
+            return '#808080'
+        }
+        return getThemeColor(health.mode)
+    }
+
     return <View className="calendar_main">
         <View className="calendar_header">{dayjs().format('YYYY年M月')}</View>
         <View className="calendar_body">
@@ -134,8 +151,8 @@ export default function Calendar(props: { year: number, month: number }) {
                 }
                 {
                     days.map((item, index) => {
-                        return <View className={itemClass(item)} style={{ width: rpxToPx(750) / 7 }} key={index}>
-                            <Text className={itemTextClass(item)}>{item.day}</Text>
+                        return <View className={itemClass(item)} style={{ width: rpxToPx(750) / 7,backgroundColor:bgColor(item) }} key={index}>
+                            <Text className={itemTextClass(item)} style={{color:textColor(item)}}>{item.day}</Text>
                         </View>
                     })
                 }

+ 1 - 0
src/features/health/hooks/health_hooks.tsx

@@ -75,6 +75,7 @@ export function getCountownTime(windows: any, mode: any) {
         case WindowStatusType.process:
             return TimeFormatter.countdown(scenario.real.start_timestamp, now)
         case WindowStatusType.open:
+
             return TimeFormatter.countdown(scenario.target.start_timestamp, now)
         case WindowStatusType.upcoming:
             return TimeFormatter.countdown(now, scenario.target.start_timestamp)

+ 9 - 2
src/pages/clock/Clock.config.ts

@@ -1,5 +1,12 @@
 export default definePageConfig({
-    // "renderer":"skyline",
-    
+    // "lazyCodeLoading": "requiredComponents",
+    // "componentFramework": "glass-easel",
+    // "renderer": "skyline",
+    // "rendererOptions": {
+    //     "skyline": {
+    //         "disableABTest": true,
+    //         "defaultDisplayBlock": true
+    //     }
+    // },
     "navigationStyle":"custom"
 })

+ 11 - 0
src/services/health.tsx

@@ -138,4 +138,15 @@ export const clockTimes = (params) =>{
             // dispatch(loginSuccess(res));
         })
     })
+}
+
+export const makeDone = (id)=>{
+    return new Promise((resolve) => {
+        request({
+            url: API_HEALTH_WINDOWS+`/${id}/done`, method: 'POST', data: {}
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        })
+    })
 }