Leon 1 rok pred
rodič
commit
87cd6c8ef6

+ 20 - 7
src/_health/components/add_label.tsx

@@ -10,7 +10,7 @@ import Taro from "@tarojs/taro";
 import { useSelector } from "react-redux";
 import { getThemeColor } from "@/features/health/hooks/health_hooks";
 
-export default function AddLabel(props: { labels: any, defaultValue?: string }) {
+export default function AddLabel(props: { labels: any, defaultValue?: string, disMiss?: any }) {
     const [showTimePicker, setShowTimePicker] = useState(false)
     const health = useSelector((state: any) => state.health);
     const [value, setValue] = useState(props.defaultValue ?? '')
@@ -36,7 +36,7 @@ export default function AddLabel(props: { labels: any, defaultValue?: string })
     }, [])
 
     function getData() {
-        
+
         getLabelsTime({}).then(res => {
             setTimeLabels((res as any).labels)
         })
@@ -62,11 +62,13 @@ export default function AddLabel(props: { labels: any, defaultValue?: string })
             schedules: [{
                 event: health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM',
                 title: value,
-                time: e, is_all_day: false
+                time: e, is_all_day: false,
+
             }]
         }).then(res => {
             global.refreshWindow()
             global.refreshSchedules()
+
             // if (process.env.TARO_ENV == 'weapp') {
             //     Taro.navigateBack()
             // }
@@ -79,12 +81,23 @@ export default function AddLabel(props: { labels: any, defaultValue?: string })
             schedules: [{
                 event: health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM',
                 title: value,
-                time: dayjs().format('HH:mm'), 
-                is_all_day: isFullday
+                time: dayjs().format('HH:mm'),
+                is_all_day: isFullday,
+                time_label: isFullday ? strTime : null
             }]
         }).then(res => {
-            global.refreshWindow()
-            global.refreshSchedules()
+            if (global.refreshWindow) {
+                global.refreshWindow()
+            }
+            if (global.refreshSchedules) {
+                global.refreshSchedules()
+            }
+
+
+            setShowTimePicker(false)
+            if (props.disMiss) {
+                props.disMiss()
+            }
             // if (process.env.TARO_ENV == 'weapp') {
             //     Taro.navigateBack()
             // }

+ 13 - 3
src/_health/pages/active_plan.tsx

@@ -7,6 +7,7 @@ import Modal from "@/components/layout/Modal.weapp";
 import AddLabel from "../components/add_label";
 import { getLabelsEvent, getSchedules } from "@/services/health";
 import { useSelector } from "react-redux";
+import Taro from "@tarojs/taro";
 
 let useRoute;
 let useNavigation;
@@ -35,16 +36,21 @@ export default function ActivePlan() {
     const [labels, setLabels] = useState<any>([])
     const [showModal, setShowModal] = useState(false)
     const health = useSelector((state: any) => state.health);
+    const [list,setList] = useState<any>([])
 
     useEffect(() => {
         getLabelsEvent({ window: health.mode }).then(res => {
             setLabels((res as any).labels)
         })
 
-        getSchedules({ window: health.mode }).then(res => {
+        getDatas()
+    }, [])
 
+    function getDatas(){
+        getSchedules({ window: health.mode }).then(res => {
+            setList((res as any).data)
         })
-    }, [])
+    }
 
     function tapEdit() {
         setShowModal(true)
@@ -65,7 +71,11 @@ export default function ActivePlan() {
                     setShowModal(false)
                 }}
                 confirm={() => { }}>
-                <AddLabel labels={labels} defaultValue={schedule.title}/>
+                <AddLabel labels={labels} defaultValue={schedule.title} disMiss={()=>{
+                    setShowModal(false)
+                    // getDatas()
+                    Taro.navigateBack()
+                }}/>
             </Modal>
         }
     </View>

+ 1 - 1
src/_health/pages/move.tsx

@@ -467,7 +467,7 @@ export default function Move() {
     return <View style={{ display: 'flex', flexDirection: 'column' }}>
         <Text className="move-title">Move Every Hour</Text>
         <Text onClick={() => {
-            jumpPage('./move_setting')
+            jumpPage('./move_setting_time')
         }}>Setting</Text>
         {
             currentContent()

+ 9 - 2
src/_health/pages/move_schedule.tsx

@@ -72,8 +72,15 @@ export default function MoveSchedule() {
                                 reminder: e.detail.value
                             }],
                         }).then(res => {
-                            global.refreshWindow()
-                            global.refreshSchedules()
+                            if (global.refreshWindow){
+                                global.refreshWindow()
+                            }
+                            if (global.refreshSchedules){
+                                global.refreshSchedules()
+                            }
+                            if (global.updateMove){
+                                global.updateMove()
+                            }
                         })
                     }} />
                     {/* {

+ 21 - 2
src/_health/pages/move_setting_reminder.tsx

@@ -2,7 +2,8 @@ import { View, Text, Switch } from "@tarojs/components";
 import './move_setting_reminder.scss'
 import Cell from "../base/cell";
 import { useEffect, useState } from "react";
-import { getMoveSchedules } from "@/services/health";
+import { createSchedule, getMoveSchedules } from "@/services/health";
+import { getThemeColor } from "@/features/health/hooks/health_hooks";
 
 export default function MoveSettingReminder() {
     const [selIndex, setSelIndex] = useState(-1)
@@ -30,7 +31,25 @@ export default function MoveSettingReminder() {
                             <Text>{item.reminder_time}</Text>
                             <View>
                                 <Text style={{ flex: 1 }}>check in for {item.time}-{item.end_time}</Text>
-                                <Switch checked={item.reminder} />
+                                <Switch checked={item.reminder} color={getThemeColor('ACTIVE')} onChange={e => {
+                        console.log(item)
+                        createSchedule({
+                            schedules: [{
+                                id: item.id,
+                                reminder: e.detail.value
+                            }],
+                        }).then(res => {
+                            if (global.refreshWindow){
+                                global.refreshWindow()
+                            }
+                            if (global.refreshSchedules){
+                                global.refreshSchedules()
+                            }
+                            if (global.updateMove){
+                                global.updateMove()
+                            }
+                        })
+                    }}/>
                             </View>
                         </View>
                     </Cell>

+ 48 - 9
src/_health/pages/move_setting_time.tsx

@@ -1,8 +1,9 @@
-import { View, Text } from "@tarojs/components";
+import { View, Text, Input } from "@tarojs/components";
 import './move_setting_time.scss'
 import Cell from "../base/cell";
 import { useEffect, useState } from "react";
-import { getMoveSchedules } from "@/services/health";
+import { createSchedule, getMoveSchedules } from "@/services/health";
+import { rpxToPx } from "@/utils/tools";
 
 export default function MoveSettingTime() {
     const [selIndex, setSelIndex] = useState(-1)
@@ -11,12 +12,16 @@ export default function MoveSettingTime() {
     const [detail, setDetail] = useState<any>(null)
 
     useEffect(() => {
+        getDatas()
+    }, [])
+
+    function getDatas() {
         getMoveSchedules().then(res => {
             setDetail(res)
             setHours((res as any).goal.hour)
             setTotal((res as any).goal.day)
         })
-    }, [])
+    }
 
     if (!detail) return <View />
 
@@ -27,13 +32,47 @@ export default function MoveSettingTime() {
             detail.schedules.map((item, index) => {
                 return <View key={index}>
                     <Cell className='demoCell' disable>
-                        <View style={{display:'flex',flexDirection:'column'}}>
+                        <View style={{ display: 'flex', flexDirection: 'column', paddingLeft: 20, paddingRight: 20, width: rpxToPx(750), boxSizing: 'border-box' }}>
                             <Text>{item.time}-{item.end_time}</Text>
-                            <View>
-                                <Text style={{flex:1}}>200<Text>Steps</Text></Text>
-                                <Text onClick={()=>{
-                                    setSelIndex(index)
-                                }}>更改目标</Text>
+                            <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
+                                {
+                                    selIndex == index ? <Input className='item_name' style={{ flex: 1 }}
+                                        value={item.goal}
+                                        autoFocus={true}
+                                        focus={true}
+                                        onBlur={() => {
+                                            setSelIndex(-1)
+                                            createSchedule({
+                                                schedules: [{
+                                                    id: item.id,
+                                                    goal: item.goal
+                                                }],
+                                            }).then(res => {
+                                                if (global.refreshWindow) {
+                                                    global.refreshWindow()
+                                                }
+                                                if (global.refreshSchedules) {
+                                                    global.refreshSchedules()
+                                                }
+                                                if (global.updateMove) {
+                                                    global.updateMove()
+                                                }
+                                                getDatas()
+                                            })
+                                        }}
+                                        onInput={(e) => {
+                                            // item.goal = e.detail.value
+                                            var obj = JSON.parse(JSON.stringify(detail))
+                                            obj.schedules[index].goal = e.detail.value
+                                            setDetail(obj)
+                                        }} /> : <Text style={{ flex: 1 }}>{item.goal}<Text>Steps</Text></Text>
+                                }
+                                {
+                                    selIndex != index && <Text onClick={() => {
+                                        setSelIndex(index)
+                                    }}>更改目标</Text>
+                                }
+
                             </View>
                         </View>
                     </Cell>

+ 8 - 5
src/_health/pages/schedules_edit.tsx

@@ -108,7 +108,7 @@ export default function SchedulesEdit() {
 
         createSchedule({
             schedules: array,
-            delete_ids:delIds
+            delete_ids: delIds
         }).then(res => {
             global.refreshWindow()
             global.refreshSchedules()
@@ -122,7 +122,7 @@ export default function SchedulesEdit() {
         var array = JSON.parse(JSON.stringify(list))
         var ids = JSON.parse(JSON.stringify(delIds))
         ids.push(array[index].list[i].id)
-        array[index].list.splice(i,1)
+        array[index].list.splice(i, 1)
 
         setList(array)
         setDelIds(ids)
@@ -210,9 +210,12 @@ export default function SchedulesEdit() {
 
                                             {/* <View style={{ flex: 1 }} /> */}
 
-                                            <View className='edit_item_time' onClick={() => changeTime(obj)} style={{ marginRight: rpxToPx(24) }}>{obj.time}</View>
+                                            {
+                                                !obj.is_all_day && <View className='edit_item_time' onClick={() => changeTime(obj)} style={{ marginRight: rpxToPx(24) }}>{obj.time}</View>
+                                            }
+
 
-                                            <Switch checked={obj.reminder}
+                                            {!obj.is_all_day &&<Switch checked={obj.reminder}
                                                 color={getThemeColor(obj.window)}
                                                 onChange={e => {
                                                     if (process.env.TARO_ENV == 'weapp') {
@@ -221,7 +224,7 @@ export default function SchedulesEdit() {
 
                                                     obj.reminder = e.detail.value;
                                                     setList([...list])
-                                                }} />
+                                                }} />}
                                             {
                                                 i < item.list.length - 1 && <View className='item_line' />
                                             }

+ 3 - 3
src/_health/pages/schedules_list.tsx

@@ -260,10 +260,10 @@ export default function SchedulesList() {
                                         </View>
                                         <View style={{ flex: 1 }} />
                                         {
-                                            !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
+                                            !obj.is_all_day&&!obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
                                         }
 
-                                        <Text className='item_time'>{obj.time}</Text>
+                                        <Text className='item_time'>{obj.time_label?obj.time_label:obj.time}</Text>
                                         {
                                             i < item.list.length - 1 && <View className='item_line' />
                                         }
@@ -285,7 +285,7 @@ export default function SchedulesList() {
                     setShowModal(false)
                 }}
                 confirm={() => { }}>
-                <AddLabel labels={labels} />
+                <AddLabel labels={labels} disMiss={()=>setShowModal(false)}/>
             </Modal>
         }
     </View>

+ 4 - 1
src/features/health/MainConsole.tsx

@@ -144,6 +144,9 @@ export default function MainConsole(props: { type: WindowType }) {
         if (item.real) {
             return dayjs(item.real.timestamp).format('HH:mm')
         }
+        if (!item.target||!item.target.timestamp){
+            return item.time_label
+        }
         return dayjs(item.target.timestamp).format('HH:mm')
     }
 
@@ -557,7 +560,7 @@ export default function MainConsole(props: { type: WindowType }) {
                         alignItems: 'center',
                         justifyContent: 'center',
                     }}>
-                        <Text>Title</Text>
+                        <Text>{list[0].title}</Text>
                         <Text>Subtitle</Text>
                         <View onClick={()=>{
                             jumpPage('/_health/pages/active_plan?schedule='+JSON.stringify(list.length>0?list[0]:'{}'))