leon před 1 rokem
rodič
revize
ee82bbf266

+ 5 - 1
src/_health/pages/add_moment.tsx

@@ -58,6 +58,10 @@ export default function AddMoment() {
 
     useEffect(() => {
         var obj = JSON.parse(router.params.moment)
+
+        obj.target.timestamp = new Date().getTime()
+        setMoment(obj)
+
         setDurationT(obj.target.duration??0)
         // var obj = JSON.parse(router.params.moment)
         // var start = dayjs(obj.target.timestamp).format('HH:mm')
@@ -304,7 +308,7 @@ export default function AddMoment() {
         {
             health.mode != 'FAST' && health.mode != 'SLEEP' &&
             <View className="addmoment_header">
-                <Text className="header_time" onClick={tapTime} style={{ color: getThemeColor(health.mode) }}>{dayjs(moment.target.timestamp).format('HH:mm')}</Text>
+                <Text className="header_time" onClick={tapTime} style={{ color: getThemeColor(health.mode) }}>{dayjs().format('HH:mm')}</Text>
                 {
                     (health.mode == 'EAT' || health.mode == 'ACTIVE') && <View className="header_line" />
                 }

+ 14 - 2
src/_health/pages/schedules_edit.scss

@@ -1,5 +1,11 @@
 @import "~taro-ui/dist/style/components/swipe-action.scss";
 
+.schedule_list_bg{
+    height: 100vh;
+    display: flex;
+    flex-direction: column;
+}
+
 .container {
     display: flex;
     flex-direction: column;
@@ -32,11 +38,11 @@
     bottom: 0;
 }
 
-.item_left{
+.item_left2{
     display: flex;
     flex-direction: row;
-    flex: 1;
     align-items: center;
+    flex: 1;
 }
 
 .item_index{
@@ -110,4 +116,10 @@
 
 .cell_hover{
     background-color: #E5E5E5;
+}
+
+.edit_icon{
+    padding: 22px;
+    width: 34px;
+    height: 34px;
 }

+ 125 - 42
src/_health/pages/schedules_edit.tsx

@@ -1,4 +1,4 @@
-import { View, Text, Image, Switch } from "@tarojs/components";
+import { View, Text, Image, Switch, Input, ScrollView } from "@tarojs/components";
 import './schedules_edit.scss'
 import { useEffect, useState } from "react";
 import { useSelector } from "react-redux";
@@ -9,6 +9,7 @@ import Modal from "@/components/layout/Modal.weapp";
 import TimePicker from "@/features/common/TimePicker";
 import { AtSwipeAction } from "taro-ui"
 import Taro from "@tarojs/taro";
+import showAlert from "@/components/basic/Alert";
 
 export default function SchedulesEdit() {
     const [list, setList] = useState<any>([])
@@ -17,6 +18,8 @@ export default function SchedulesEdit() {
     const health = useSelector((state: any) => state.health);
     const [showTimePicker, setShowTimePicker] = useState(false)
     const [selItem, setSelItem] = useState<any>(null)
+    const [editIndex, setEditIndex] = useState({ row: -1, index: -1 })
+    const [delIds, setDelIds] = useState<any>([])
 
     useEffect(() => {
         schedules()
@@ -97,14 +100,15 @@ export default function SchedulesEdit() {
                     time: item.time,
                     event: item.event,
                     title: item.title,
-                    reminder:item.reminder
+                    reminder: item.reminder
                 })
             })
 
         })
 
         createSchedule({
-            schedules: array
+            schedules: array,
+            delete_ids:delIds
         }).then(res => {
             global.refreshWindow()
             global.refreshSchedules()
@@ -113,46 +117,125 @@ export default function SchedulesEdit() {
             }
         })
     }
-    console.log(health.mode)
-    return <View>
-        {
-            list.map((item, index) => {
-                return <View key={index} style={{ display: 'flex', flexDirection: 'column', marginBottom: rpxToPx(36) }}>
-                    {
-                        item.list.map((obj, i) => {
-                            return <View className='schedule_item' key={i * 100}>
-
-                                <View className='item_left'>
-                                    <Text className='item_index'>{i + 1}</Text>
-
-
-                                    <Text className='item_name'>{obj.title}</Text>
-                                </View>
-                                <View style={{ flex: 1 }} />
-
-                                <View className='edit_item_time' onClick={() => changeTime(obj)} style={{ marginRight: rpxToPx(24) }}>{obj.time}</View>
-
-                                <Switch checked={obj.reminder}
-                                    color={getThemeColor(obj.window)}
-                                    onChange={e => {
-                                        if (process.env.TARO_ENV == 'weapp') {
-                                            e.stopPropagation()
-                                        }
-
-                                        obj.reminder = e.detail.value;
-                                        setList([...list])
-                                    }} />
-                                {
-                                    i < item.list.length - 1 && <View className='item_line' />
-                                }
-
-                            </View>
-                        })
-                    }
-                </View>
-            })
-        }
 
+    function delItem(index, i) {
+        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)
+
+        setList(array)
+        setDelIds(ids)
+    }
+    return <View className='schedule_list_bg'>
+        <ScrollView enableFlex style={{ height: Taro.getSystemInfoSync().screenHeight - 220 }} scrollY>
+            <View style={{ display: 'flex', flexDirection: 'column' }}>
+                {
+                    list.map((item, index) => {
+                        return <View key={index} style={{ display: 'flex', flexDirection: 'column', marginBottom: rpxToPx(36) }}>
+                            {
+                                item.list.map((obj, i) => {
+                                    return <AtSwipeAction key={i * 100}
+                                        isOpened={false}
+                                        autoClose
+                                        disabled={item.window != 'EAT' && item.window != 'ACTIVE'}
+                                        options={[
+                                            {
+                                                text: '删除',
+                                                style: {
+                                                    backgroundColor: '#FF4949'
+                                                }
+                                            }
+                                        ]}
+                                        onClick={() => {
+                                            showAlert({
+                                                title: '删除',
+                                                content: '确认删除此计划',
+                                                showCancel: true,
+                                                cancel: () => {
+                                                    console.log('cancel')
+                                                },
+                                                confirm: () => {
+                                                    delItem(index, i)
+                                                }
+                                            })
+                                        }}
+                                    >
+                                        <View className='schedule_item' style={{ width: rpxToPx(750), boxSizing: 'border-box' }}>
+
+                                            <View className='item_left2'>
+                                                <Text className='item_index'>{i + 1}</Text>
+
+                                                {
+                                                    editIndex.row == index && editIndex.index == i ?
+                                                        <Input className='item_name' style={{ flex: 1 }}
+                                                            value={selItem.title}
+                                                            autoFocus={true}
+                                                            focus={true}
+                                                            onBlur={() => {
+                                                                setEditIndex({
+                                                                    row: -1,
+                                                                    index: -1
+                                                                })
+                                                            }}
+                                                            onInput={(e) => {
+                                                                var temp = JSON.parse(JSON.stringify(selItem))
+                                                                temp.title = e.detail.value
+                                                                obj.title = e.detail.value
+                                                                setSelItem(temp)
+                                                                // selItem.title = e.detail.value
+                                                                // console.log(e.detail.value)
+                                                                // setSelItem(selItem)
+                                                            }} /> : <Text className='item_name'>{obj.title}</Text>
+                                                }
+
+                                                {
+                                                    (item.window == 'EAT' || item.window == 'ACTIVE') &&
+                                                    !(editIndex.row == index && editIndex.index == i) &&
+                                                    <Image src={require('@assets/_health/edit.png')}
+                                                        className="edit_icon"
+                                                        onClick={(e) => {
+                                                            if (process.env.TARO_ENV == 'weapp') {
+                                                                e.stopPropagation()
+                                                            }
+                                                            setSelItem(obj)
+                                                            setEditIndex({
+                                                                row: index,
+                                                                index: i
+                                                            })
+                                                        }}
+                                                    />
+                                                }
+                                            </View>
+
+                                            {/* <View style={{ flex: 1 }} /> */}
+
+                                            <View className='edit_item_time' onClick={() => changeTime(obj)} style={{ marginRight: rpxToPx(24) }}>{obj.time}</View>
+
+                                            <Switch checked={obj.reminder}
+                                                color={getThemeColor(obj.window)}
+                                                onChange={e => {
+                                                    if (process.env.TARO_ENV == 'weapp') {
+                                                        e.stopPropagation()
+                                                    }
+
+                                                    obj.reminder = e.detail.value;
+                                                    setList([...list])
+                                                }} />
+                                            {
+                                                i < item.list.length - 1 && <View className='item_line' />
+                                            }
+
+                                        </View>
+                                    </AtSwipeAction>
+                                })
+                            }
+                        </View>
+
+                    })
+                }
+            </View>
+        </ScrollView>
         <View className="edit_footer_btn" style={{ color: getThemeColor(health.mode), backgroundColor: getThemeColor(health.mode) + '33' }} onClick={tapDone}>完成</View>
         {
             showTimePicker && <Modal

+ 2 - 1
src/_health/pages/schedules_list.config.ts

@@ -4,5 +4,6 @@ export default definePageConfig({
       // 'demo':'../../components/demo'
     },
     "navigationBarTitleText":"",
-    "navigationBarBackgroundColor":"#f5f5f5"
+    "navigationBarBackgroundColor":"#f5f5f5",
+    "disableScroll":true
   })

+ 52 - 12
src/_health/pages/schedules_list.scss

@@ -1,5 +1,11 @@
 @import "~taro-ui/dist/style/components/swipe-action.scss";
 
+.schedule_list_bg {
+    height: 100vh;
+    display: flex;
+    flex-direction: column;
+}
+
 .container {
     display: flex;
     flex-direction: column;
@@ -18,11 +24,11 @@
     background-color: #fff;
 }
 
-.item_hover{
+.item_hover {
     background-color: #E5E5E5;
 }
 
-.item_line{
+.item_line {
     height: 2px;
     background-color: #B2B2B2;
     transform: scaleY(0.5);
@@ -32,14 +38,14 @@
     bottom: 0;
 }
 
-.item_left{
+.item_left {
     display: flex;
     flex-direction: row;
     flex: 1;
     align-items: center;
 }
 
-.item_index{
+.item_index {
     color: #B2B2B2;
     font-size: 26px;
     width: 36px;
@@ -51,17 +57,17 @@
 
 }
 
-.item_name{
+.item_name {
     color: #000;
     font-size: 34px;
 }
 
-.item_time{
+.item_time {
     color: #000;
     font-size: 34px;
 }
 
-.toolbar{
+.toolbar {
     display: flex;
     flex-direction: row;
     align-items: center;
@@ -71,7 +77,7 @@
     padding-right: 46px;
 }
 
-.item_add{
+.item_add {
     height: 128px;
     display: flex;
     flex-direction: row;
@@ -80,19 +86,19 @@
     padding-left: 40px;
 }
 
-.toolbar_btn{
+.toolbar_btn {
     color: #FF751A;
     font-size: 34px;
     margin-left: 26px;
 }
 
-.notification_icon{
+.notification_icon {
     width: 34px;
     height: 34px;
     margin-right: 12px;
 }
 
-.schedule_header_title{
+.schedule_header_title {
     margin-left: 40px;
     font-weight: bold;
     font-size: 50px;
@@ -101,6 +107,40 @@
     margin-top: 22px;
 }
 
-.cell_hover{
+.cell_hover {
     background-color: #E5E5E5;
+}
+
+.section_title {
+    margin-left: 40px;
+    margin-bottom: 22px;
+    color: #B2B2B2;
+    font-size: 24px;
+    font-weight: bold;
+}
+
+.schedule_set_tabbar {
+    height: 100px;
+    display: flex;
+    flex-direction: row;
+    background-color: #fff;
+}
+
+.schedule_tab_nor {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    flex: 1;
+    font-size: 28px;
+    color: #00000099;
+}
+
+.schedule_tab_sel {
+    color: #000;
+    flex: 1;
+    font-size: 30px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    border-bottom: solid 2px #000;
 }

+ 115 - 43
src/_health/pages/schedules_list.tsx

@@ -1,4 +1,4 @@
-import { View, Text, Image } from '@tarojs/components'
+import { View, Text, Image, ScrollView } from '@tarojs/components'
 import './schedules_list.scss'
 import './edit.scss'
 import { useEffect, useState } from 'react'
@@ -12,17 +12,51 @@ import showActionSheet from '@/components/basic/ActionSheet'
 import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
 import { IconAdd } from '@/components/basic/Icons'
 import { rpxToPx } from '@/utils/tools'
+import { useRouter } from '@tarojs/taro'
+import Taro from '@tarojs/taro'
 
-
+let useRoute;
+let useNavigation;
+let scenario = '';
+if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
+    useNavigation = require("@react-navigation/native").useNavigation
+}
 export default function SchedulesList() {
+    let navigation, showActionSheetWithOptions;
+
+    let router
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+
+    const selMode = router.params.mode;
     const [showModal, setShowModal] = useState(false)
     const [list, setList] = useState<any>([])
     const [labels, setLabels] = useState<any>([])
     const [showDel, setShowDel] = useState(false)
+    const [selTab, setSelTab] = useState(0)
     const health = useSelector((state: any) => state.health);
-    let navigation, showActionSheetWithOptions;
+
+
+
 
     useEffect(() => {
+        console.log(selMode)
+        if (!selMode || selMode == '') {
+            console.log('oppppp')
+            Taro.setNavigationBarColor({
+                frontColor: '#000000',
+                backgroundColor: '#ffffff'
+            })
+        }
         schedules()
     }, [])
 
@@ -32,7 +66,7 @@ export default function SchedulesList() {
 
     function schedules() {
         let windows = ''
-        switch (health.mode) {
+        switch (selMode) {
             case 'FAST':
                 windows = 'FAST,EAT';
                 break
@@ -45,6 +79,12 @@ export default function SchedulesList() {
             case 'ACTIVE':
                 windows = 'ACTIVE,SLEEP';
                 break
+            case 'DAY':
+                windows = 'DAY,NIGHT';
+                break
+            case 'NIGHT':
+                windows = 'NIGHT,DAY';
+                break
         }
         getSchedules({ window: windows }).then(res => {
             if ((res as any).data && (res as any).data.length > 0) {
@@ -146,7 +186,7 @@ export default function SchedulesList() {
     }
 
     function getTitle() {
-        switch (health.mode) {
+        switch (selMode) {
             case 'FAST':
                 return '断食和进食';
             case 'EAT':
@@ -155,55 +195,87 @@ export default function SchedulesList() {
                 return '睡眠和活动';
             case 'ACTIVE':
                 return '活动和睡眠';
+            case 'DAY':
+                return '白天和夜晚';
+            case 'NIGHT':
+                return '夜晚和白天';
         }
-        return ''
+        return '全部'
     }
 
-    return <View>
-        <View className='schedule_header_title'>{getTitle()}</View>
+    function sectionTitle(item) {
+        switch (item.window) {
+            case 'FAST':
+                return '断食'
+            case 'EAT':
+                return '进食'
+            case 'SLEEP':
+                return '睡眠'
+            case 'ACTIVE':
+                return '活动'
+            case 'DAY':
+                return '日间'
+            case 'NIGHT':
+                return '夜间'
+        }
+    }
+
+    return <View className='schedule_list_bg'>
         {
-            list.map((item, index) => {
-                return <View key={index} style={{ display: 'flex', flexDirection: 'column', marginBottom: rpxToPx(36) }}>
-                    {
-                        item.list.map((obj, i) => {
-                            if (obj.add) {
-                                return <View key={i * 100} className='item_add'
-                                    hoverClass='cell_hover'
-                                    hoverStayTime={50}
-                                    onClick={add}>
-                                    <IconAdd color={getThemeColor(item.window)} width={rpxToPx(34)} />
-                                    <View className='toolbar_btn' style={{ color: getThemeColor(item.window) }} >添加</View>
-                                    <View style={{ flex: 1 }} />
-                                    {/* <View className='toolbar_btn' style={{ color: getThemeColor(health.mode) }} onClick={() => setShowDel(!showDel)}>移除</View> */}
-                                </View>
-                            }
+            selMode == '' && <View className='schedule_set_tabbar'>
+                <View onClick={()=>setSelTab(0)} className={selTab==0?'schedule_tab_sel':'schedule_tab_nor'}>按场景</View>
+                <View onClick={()=>setSelTab(1)} className={selTab==1?'schedule_tab_sel':'schedule_tab_nor'}>按时间</View>
+            </View>
+        }
+        <ScrollView enableFlex style={{ height: Taro.getSystemInfoSync().screenHeight - 220 - (selMode == '' ? rpxToPx(100) : 0) }} scrollY>
+            <View style={{ display: 'flex', flexDirection: 'column' }}>
+                <View className='schedule_header_title'>{getTitle()}</View>
+                {
+                    list.map((item, index) => {
+                        return <View key={index} style={{ display: 'flex', flexDirection: 'column', marginBottom: rpxToPx(36) }}>
+                            <Text className='section_title'>{sectionTitle(item)}</Text>
+                            {
+                                item.list.map((obj, i) => {
+                                    if (obj.add) {
+                                        return <View key={i * 100} className='item_add'
+                                            hoverClass='cell_hover'
+                                            hoverStayTime={50}
+                                            onClick={add}>
+                                            <IconAdd color={getThemeColor(item.window)} width={rpxToPx(34)} />
+                                            <View className='toolbar_btn' style={{ color: getThemeColor(item.window) }} >添加</View>
+                                            <View style={{ flex: 1 }} />
+                                            {/* <View className='toolbar_btn' style={{ color: getThemeColor(health.mode) }} onClick={() => setShowDel(!showDel)}>移除</View> */}
+                                        </View>
+                                    }
 
-                            return <View className='schedule_item' key={i * 100} hoverClass='cell_hover' hoverStayTime={50} onClick={() => {
+                                    return <View className='schedule_item' key={i * 100} hoverClass='cell_hover' hoverStayTime={50} onClick={() => {
 
-                            }}>
+                                    }}>
 
-                                <View className='item_left'>
-                                    <Text className='item_index'>{i + 1}</Text>
+                                        <View className='item_left'>
+                                            <Text className='item_index'>{i + 1}</Text>
 
 
-                                    <Text className='item_name'>{obj.title}</Text>
-                                </View>
-                                <View style={{ flex: 1 }} />
-                                {
-                                    !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
-                                }
+                                            <Text className='item_name'>{obj.title}</Text>
+                                        </View>
+                                        <View style={{ flex: 1 }} />
+                                        {
+                                            !obj.reminder && <Image src={require('@assets/images/notification_off.png')} className='notification_icon' />
+                                        }
 
-                                <Text className='item_time'>{obj.time}</Text>
-                                {
-                                    i < item.list.length - 1 && <View className='item_line' />
-                                }
+                                        <Text className='item_time'>{obj.time}</Text>
+                                        {
+                                            i < item.list.length - 1 && <View className='item_line' />
+                                        }
 
-                            </View>
-                        })
-                    }
-                </View>
-            })
-        }
+                                    </View>
+                                })
+                            }
+                        </View>
+                    })
+                }
+            </View>
+        </ScrollView>
 
         <View className="edit_footer_btn" style={{ color: getThemeColor(health.mode), backgroundColor: getThemeColor(health.mode) + '33' }} onClick={tapEdit}>批量编辑</View>
 

binární
src/assets/_health/edit.png


+ 5 - 5
src/features/health/MainConsole.tsx

@@ -409,7 +409,7 @@ export default function MainConsole(props: { type: WindowType }) {
                     switch (health.mode) {
                         case 'DAY':
                         case 'NIGHT':
-                            jumpPage('/_health/pages/schedules_list')
+                            jumpPage('/_health/pages/schedules_list?mode='+health.mode)
                             break;
                         case 'FAST':
                         case 'SLEEP':
@@ -420,7 +420,7 @@ export default function MainConsole(props: { type: WindowType }) {
                                     setDurationPicker(true)
                                 }
                                 else {
-                                    jumpPage('/_health/pages/schedules_list')
+                                    jumpPage('/_health/pages/schedules_list?mode='+health.mode)
                                 }
                             }
                             break;
@@ -437,14 +437,14 @@ export default function MainConsole(props: { type: WindowType }) {
                 {
                     switch (health.mode) {
                         case 'EAT':
-                            jumpPage('/_health/pages/schedules_list')
+                            jumpPage('/_health/pages/schedules_list?mode='+health.mode)
                             break;
                         case 'FAST':
                         case 'SLEEP':
                             const obj = getScenario(health.windows, health.mode)
                             if (obj.window_id) {
                                 //del record
-                                jumpPage('/_health/pages/schedules_list')
+                                jumpPage('/_health/pages/schedules_list?mode='+health.mode)
                                 console.log('zzzzzzzzz')
                             }
                             else {
@@ -452,7 +452,7 @@ export default function MainConsole(props: { type: WindowType }) {
                             }
                             break;
                         case 'ACTIVE':
-                            jumpPage('/_health/pages/schedules_list')
+                            jumpPage('/_health/pages/schedules_list?mode='+health.mode)
                             break;
                     }
                 }

+ 3 - 1
src/pages/account/Profile.tsx

@@ -296,7 +296,9 @@ export default function Page() {
                 <Image src={require('@assets/_health/cell_arrow.png')} className="profile_cell_arrow" />
             </View>
 
-            <View className="profile_cell profile_cell_space" onClick={goSetting}>
+            <View className="profile_cell profile_cell_space" onClick={()=>{
+                jumpPage("/_health/pages/schedules_list?mode=")
+            }}>
                 <Image src={require('@assets/_health/sit.png')} className="profile_cell_icon" />
                 <Text style={{ flex: 1 }}>Schedule</Text>
                 <Image src={require('@assets/_health/cell_arrow.png')} className="profile_cell_arrow" />