leon vor 1 Jahr
Ursprung
Commit
dcd0f1b80a

+ 1 - 1
config/env.ts

@@ -1,4 +1,4 @@
 
 export const APP_VERSION = '1.0.2'
 export const ANDROID_VERSION = '1.0.0'
-export const WX_VERSION = '1.5.1'
+export const WX_VERSION = '1.5.4'

+ 4 - 0
src/_health/pages/add_moment.scss

@@ -35,8 +35,10 @@
 .form{
     display: flex;
     flex-direction: row;
+    flex-wrap: wrap;
     margin-left: 96px;
     margin-bottom: 54px;
+    width: 80%;
 }
 
 .cover{
@@ -48,6 +50,8 @@
     justify-content: center;
     border-radius: 16px;
     overflow: hidden;
+    margin-right: 10px;
+    margin-bottom: 10px;
 }
 
 .input_title{

+ 109 - 14
src/_health/pages/add_moment.tsx

@@ -40,6 +40,7 @@ export default function AddMoment() {
     const [desc, setDesc] = useState('')
     const { t } = useTranslation()
     const [imgUrl, setImgUrl] = useState('')
+    const [pics, setPics] = useState<any>([])
     const [showPicker, setShowPicker] = useState(false)
     const [durationT, setDurationT] = useState(0)
     const dispatch = useDispatch()
@@ -128,7 +129,7 @@ export default function AddMoment() {
         var source: any = isCamera ? ['camera'] : ['album']
         console.log(source)
         Taro.chooseMedia({
-            count: 1,
+            count: 9-pics.length,
             sizeType: ['compressed'],
             mediaType: ['image'],
             sourceType: source,
@@ -166,14 +167,26 @@ export default function AddMoment() {
             }
         }
 
-
-        if (imgUrl.length > 0) {
-            params.media = [{
-                url: imgUrl,
-                type: imgUrl.indexOf('mp4') != -1 ? 'video' : 'image',
-                source: 'album'
-            }]
+        if (pics.length>0){
+            var picList:any = []
+            pics.map((item)=>{
+                picList.push({
+                    url:item,
+                    type:item.indexOf('mp4') != -1 ? 'video' : 'image',
+                    source: 'album'
+                })
+            })
+            params.media = picList
         }
+
+
+        // if (imgUrl.length > 0) {
+        //     params.media = [{
+        //         url: imgUrl,
+        //         type: imgUrl.indexOf('mp4') != -1 ? 'video' : 'image',
+        //         source: 'album'
+        //     }]
+        // }
         if (event_id && event_id != 'undefined') {
             params.event_id = event_id
         }
@@ -200,7 +213,7 @@ export default function AddMoment() {
         setPosting(true)
         createMoment(params).then(res => {
             // setTimeout(() => {
-                setPosting(false)
+            setPosting(false)
             // }, 1000)
 
             if (process.env.TARO_ENV == 'weapp') {
@@ -289,12 +302,67 @@ export default function AddMoment() {
     }
 
     async function chooseSuccess(res, isAlbum) {
+        const filePaths = res.tempFiles.map(file =>
+            process.env.TARO_ENV === 'rn' ? file.path : file.tempFilePath
+        )
+
+        try {
+            const uploadedUrls = await Promise.all(filePaths.map(path => uploadFile2(path, isAlbum ? 'album' : 'camera')))
+            setPics([...pics,...uploadedUrls])
+            Taro.hideLoading()
+        } catch (error) {
+            console.error('Error uploading files:', error)
+            Taro.hideLoading()
+        }
+    }
+
+    function uploadFile2(path: string, source: string): Promise<string> {
+        return new Promise((resolve, reject) => {
+            const dot = path.lastIndexOf('.')
+            const fileExt = dot > 0 ? path.substring(dot) : ''
+            Taro.request({
+                method: 'GET',
+                url: `${baseUrl}/api/thirdparty/aliyun/oss-form-upload`,
+                header: {
+                    'Authorization': 'bearer ' + global.token
+                },
+                data: {
+                    type: 'FOOD_JOURNAL',
+                    file_ext: fileExt
+                },
+                success: (rsp) => {
+                    if (rsp.statusCode !== 200) {
+                        reject(new Error(t('health.networkError')))
+                        return
+                    }
+                    Taro.uploadFile({
+                        url: rsp.data.upload_url,
+                        filePath: path,
+                        name: 'file',
+                        formData: rsp.data.fields,
+                        success: () => {
+
+                            resolve(rsp.data.view_url)
+                        },
+                        fail: (error) => {
+
+                            reject(error)
+                        }
+                    })
+                },
+                fail: reject
+            })
+        })
+    }
+
+    async function chooseSuccess2(res, isAlbum) {
         var params = {
             event: 'add_a_picture',
             value: isAlbum ? 'choose_from_album_confirm' : 'use_camera_confirm',
         }
 
         saveFoodCache('create', params)
+        debugger
 
         var savedFilePath = process.env.TARO_ENV == 'rn' ? res.tempFiles[0].path : res.tempFiles[0].tempFilePath
 
@@ -305,7 +373,7 @@ export default function AddMoment() {
 
     function uploadFile(path, source) {
         Taro.showLoading({
-            title: '加载中'
+            title: t('health.loading')
         })
         var dot = path.lastIndexOf('.')
         var fileExt = dot > 0 ? path.substring(dot) : ''
@@ -411,16 +479,28 @@ export default function AddMoment() {
     function tapPic() {
         showActionSheet({
             title: '',
-            itemList: [t('health.choose_photo'), t('health.camera'), t('health.delete')],
+            itemList: [t('health.choose_photo'), t('health.import_wechat'), t('health.camera'), t('health.delete')],
             success: function (res) {
                 switch (res) {
                     case 0:
                         addImage(false)
                         break;
                     case 1:
-                        addImage(true)
+                        Taro.chooseMessageFile({
+                            count:9-pics.length,
+                            type:'image',
+                            success: function (res) {
+                                chooseSuccess(res, true)
+                            },
+                            fail(res) {
+                                console.log(res)
+                            },
+                        })
                         break;
                     case 2:
+                        addImage(true)
+                        break;
+                    case 3:
                         setImgUrl('')
                         break;
                 }
@@ -507,8 +587,23 @@ export default function AddMoment() {
                 onInput={e => {
                     setDesc(e.detail.value)
                 }} />
-
             <View className="form">
+                {
+                    pics.map((item, index) => {
+                        return <Image src={item} mode="aspectFill" className="cover" key={index} onClick={()=>{
+                            Taro.previewImage({
+                                current:item,
+                                urls:pics
+                            })
+                        }}/>
+                    })
+                }
+                {
+                    pics.length < 9 && <View onClick={tapPic} className="cover" style={{backgroundColor:'red'}}>添加</View>
+                }
+            </View>
+
+            {/* <View className="form">
                 {
                     imgUrl.length > 0 && <View className="cover" ><NewButton type={NewButtonType.img} onClick={() => tapPic()}><Image src={imgUrl} mode="aspectFill" className="cover" /></NewButton></View>
                 }
@@ -523,7 +618,7 @@ export default function AddMoment() {
                     </View>
                 }
 
-            </View>
+            </View> */}
         </View>
 
 

+ 6 - 3
src/_health/pages/timeline_detail.tsx

@@ -291,7 +291,9 @@ export default function TimelineDetail() {
     function getDatas() {
         var showWindow = true
         console.log('获取接口数据')
+
         if (!window_id || op_page == 'HOME_EAT' || op_page == 'HOME_ACTIVE') showWindow = false
+        if (window_id == 'undefined') showWindow = false
         if (showWindow) {
             var params: any = {}
             if (router.params.isfastsleep == '1') {
@@ -582,7 +584,7 @@ export default function TimelineDetail() {
 
     function tapMore() {
         var list: any = []
-        if (window_id) {
+        if (window_id && window_id != 'undefined' && (op_page != 'HOME_EAT' && op_page != 'HOME_ACTIVE')) {
             if (detail.archived) {
                 list = [t('health.delete'), 'Mark Done']
             }
@@ -612,6 +614,7 @@ export default function TimelineDetail() {
             })
             return
         }
+        debugger
 
         if (health.mode != 'ACTIVE' && health.mode != 'EAT') {
             list = [t('health.delete')]
@@ -706,7 +709,7 @@ export default function TimelineDetail() {
     }
 
     function backHome() {
-        
+
         Taro.reLaunch({
             url: '/pages/clock/Clock'
         })
@@ -715,7 +718,7 @@ export default function TimelineDetail() {
     function postBtnColor() {
         if (detail.window)
             return getThemeColor(detail.window)
-        if (detail.events){
+        if (detail.events) {
             return getThemeColor(detail.events[0].window)
         }
     }

+ 3 - 2
src/app.tsx

@@ -9,6 +9,7 @@ import Taro from '@tarojs/taro'
 import { getInfoSuccess } from './store/user'
 import { uploadLocalPushInfo } from './features/trackTimeDuration/actions/TrackTimeActions'
 import { kIsAndroid } from './utils/tools'
+import { WX_VERSION } from './services/http/api'
 
 
 // import { StatusBar } from 'react-native'
@@ -34,7 +35,7 @@ if (process.env.TARO_ENV == 'rn') {
 
 const App: React.FC<PropsWithChildren> = ({ children }) => {
 
-
+  
   global.hideRingIcon = true
 
   Taro.setStorage({ key: 'showedDisqualifiedAlert', data: false })
@@ -228,7 +229,7 @@ const App: React.FC<PropsWithChildren> = ({ children }) => {
 
     </ActionSheetProvider>
   }
-
+  console.log('当前微信版本',WX_VERSION)
   return <Provider store={store}>
     {children}
   </Provider>

+ 32 - 31
src/context/locales/en.js

@@ -978,7 +978,7 @@ export default {
         language: 'Language',
 
         fast_with_sleep: 'Fast with Sleep',
-        fasting_with_sleep:'Fasting with Sleep',
+        fasting_with_sleep: 'Fasting with Sleep',
         long_fast: 'Long Fast',
         move_more: 'Move More',
         move_every_hour: 'Move Every Hour',
@@ -1088,6 +1088,7 @@ export default {
         add_my_first_activity: 'Add My First Activity',
 
         choose_photo: 'Choose from Photos',
+        import_wechat: 'Import from Chat',
         camera: 'Camera',
         delete: 'Delete',
         photos: 'Photos',
@@ -1113,7 +1114,7 @@ export default {
 
         check_begin_at: 'Check-in begins {{time}}',
         check_begin_at2: '{{time}} Check-in begins',
-        check_reopen:'Check-In reopens {{time}}',
+        check_reopen: 'Check-In reopens {{time}}',
         kcal: ' kcal',
         km: ' km',
         steps: 'steps',
@@ -1179,39 +1180,39 @@ export default {
         follow_system: 'Follow System',
 
         switch: 'Switch',
-        save:'Save',
+        save: 'Save',
         lf_progress_title: 'Long Fast in Progress',
         lf_progress_desc: 'Do you want to switch it to Intermittent Fasting?',
         if_progress_title: 'Intermittent Fasting in Progress',
         if_progress_desc: 'Do you want to switch it to Long Fast?',
 
-        save_as_if_title:'Saving as Intermittent Fasting',
-        save_as_if_desc:'Fasting that lasts less than 24 hours will be saved as Intermittent Fasting',
-        save_as_if_toast:'Saved to \'Fast/Recents\'',
-        save_as_lf_title:'Saving as Long Fast',
-        save_as_lf_desc:'Fasting that lasts 24 hours or more will be saved as Long Fast',
-        save_as_lf_toast:'Saved to \'Long Fast/Recents\'',
-
-        sleep_well:'Sleep Well.',
-        think_goal_title:'Think you\'ve hit {{steps}} steps this hour?',
-        think_so:'I Think So!',
-        end_soon:'Ending soon {{time}}',
-        open_soon:'Opening soon {{time}}',
-        check_in_available:'Check In available {{time}}',
-        hit_steps:'Hit {{steps}} steps within the hour',
-
-        change_goal:'Change Goal',
-        hit_steps2:'Hit {{steps}} steps',
-        hour_step_goal:'Hourly Step Goal',
-        avg_total_steps:'Average {{avg}} steps, Total {{total}} steps',
-        conflict_resolve:'Time Conflict Resolved',
-
-        edit_my_name:'Edit my name',
-        enter_my_name:'Enter my name',
-
-        share_check_in:'{{date}} {{type}} Check-In',
-        share_all_journal:'{{date}} Journal',
-        share_food_journal:'{{date}} Food Journal',
-        share_activity_journal:'{{date}} Activity Journal',
+        save_as_if_title: 'Saving as Intermittent Fasting',
+        save_as_if_desc: 'Fasting that lasts less than 24 hours will be saved as Intermittent Fasting',
+        save_as_if_toast: 'Saved to \'Fast/Recents\'',
+        save_as_lf_title: 'Saving as Long Fast',
+        save_as_lf_desc: 'Fasting that lasts 24 hours or more will be saved as Long Fast',
+        save_as_lf_toast: 'Saved to \'Long Fast/Recents\'',
+
+        sleep_well: 'Sleep Well.',
+        think_goal_title: 'Think you\'ve hit {{steps}} steps this hour?',
+        think_so: 'I Think So!',
+        end_soon: 'Ending soon {{time}}',
+        open_soon: 'Opening soon {{time}}',
+        check_in_available: 'Check In available {{time}}',
+        hit_steps: 'Hit {{steps}} steps within the hour',
+
+        change_goal: 'Change Goal',
+        hit_steps2: 'Hit {{steps}} steps',
+        hour_step_goal: 'Hourly Step Goal',
+        avg_total_steps: 'Average {{avg}} steps, Total {{total}} steps',
+        conflict_resolve: 'Time Conflict Resolved',
+
+        edit_my_name: 'Edit my name',
+        enter_my_name: 'Enter my name',
+
+        share_check_in: '{{date}} {{type}} Check-In',
+        share_all_journal: '{{date}} Journal',
+        share_food_journal: '{{date}} Food Journal',
+        share_activity_journal: '{{date}} Activity Journal',
     }
 }

+ 38 - 37
src/context/locales/zh.js

@@ -979,7 +979,7 @@ export default {
         language: '语言',
 
         fast_with_sleep: '断食与睡眠',
-        fasting_with_sleep:'断食与睡眠',
+        fasting_with_sleep: '断食与睡眠',
         long_fast: '长断食',
         move_more: '走一走',
         move_every_hour: '每小时走一走',
@@ -1091,6 +1091,7 @@ export default {
         add_my_first_activity: '添加我的第一个活动',
 
         choose_photo: '从手机相册选择',
+        import_wechat: '从聊天导入',
         camera: '拍摄',
         delete: '删除',
         photos: '相册',
@@ -1116,7 +1117,7 @@ export default {
 
         check_begin_at: '打卡将于 {{time}} 开放',
         check_begin_at2: '{{time}} 打卡开放',
-        check_reopen:'打卡将于{{time}}重新开放',
+        check_reopen: '打卡将于{{time}}重新开放',
         kcal: ' 千卡',
         km: ' 公里',
         steps: '步',
@@ -1179,40 +1180,40 @@ export default {
         follow_wechat: '跟随微信',
         follow_system: '跟随系统',
 
-        switch:'转换',
-        save:'保存',
-        lf_progress_title:'长断食进行中',
-        lf_progress_desc:'要将它转换为间歇性断食吗?',
-        if_progress_title:'间歇性断食进行中',
-        if_progress_desc:'要将它转换为长断食吗?',
-
-        save_as_if_title:'保存为间歇性断食',
-        save_as_if_desc:'持续时间不足24小时的断食将被保存为间歇性断食',
-        save_as_if_toast:'已保存至“断食/最近”',
-        save_as_lf_title:'保存为长断食',
-        save_as_lf_desc:'持续24小时或更长时间的断食将被保存为长断食',
-        save_as_lf_toast:'已保存至“长断食/最近”',
-
-        sleep_well:'睡个好觉',
-        think_goal_title:'本小时走够{{steps}}步了吗?',
-        think_so:'我想是的!',
-        end_soon:'打卡即将关闭 {{time}}',
-        open_soon:'打卡即将开放 {{time}}',
-        check_in_available:'打卡已开放 {{time}}',
-        hit_steps:'本小时走够{{steps}}步',
-
-        change_goal:'更改目标',
-        hit_steps2:'走够{{steps}}步',
-        hour_step_goal:'每小时步数目标',
-        avg_total_steps:'平均 {{avg}} 步,全天 {{total}} 步',
-        conflict_resolve:'时间冲突已解决',
-
-        edit_my_name:'编辑名字',
-        enter_my_name:'取个名字',
-
-        share_check_in:'{{date}}{{type}}打卡',
-        share_all_journal:'{{date}}日记',
-        share_food_journal:'{{date}}饮食日记',
-        share_activity_journal:'{{date}}活动日记',
+        switch: '转换',
+        save: '保存',
+        lf_progress_title: '长断食进行中',
+        lf_progress_desc: '要将它转换为间歇性断食吗?',
+        if_progress_title: '间歇性断食进行中',
+        if_progress_desc: '要将它转换为长断食吗?',
+
+        save_as_if_title: '保存为间歇性断食',
+        save_as_if_desc: '持续时间不足24小时的断食将被保存为间歇性断食',
+        save_as_if_toast: '已保存至“断食/最近”',
+        save_as_lf_title: '保存为长断食',
+        save_as_lf_desc: '持续24小时或更长时间的断食将被保存为长断食',
+        save_as_lf_toast: '已保存至“长断食/最近”',
+
+        sleep_well: '睡个好觉',
+        think_goal_title: '本小时走够{{steps}}步了吗?',
+        think_so: '我想是的!',
+        end_soon: '打卡即将关闭 {{time}}',
+        open_soon: '打卡即将开放 {{time}}',
+        check_in_available: '打卡已开放 {{time}}',
+        hit_steps: '本小时走够{{steps}}步',
+
+        change_goal: '更改目标',
+        hit_steps2: '走够{{steps}}步',
+        hour_step_goal: '每小时步数目标',
+        avg_total_steps: '平均 {{avg}} 步,全天 {{total}} 步',
+        conflict_resolve: '时间冲突已解决',
+
+        edit_my_name: '编辑名字',
+        enter_my_name: '取个名字',
+
+        share_check_in: '{{date}}{{type}}打卡',
+        share_all_journal: '{{date}}日记',
+        share_food_journal: '{{date}}饮食日记',
+        share_activity_journal: '{{date}}活动日记',
     }
 }

+ 37 - 4
src/features/health/MainDayNightCard.tsx

@@ -17,6 +17,16 @@ import { setMode } from "@/store/health";
 import { IconSwitch1, IconSwitch2 } from "@/components/basic/Icons";
 import { getScenario, getWindowStatus } from "./hooks/health_hooks";
 import { useTranslation } from "react-i18next";
+import { useRouter } from "@tarojs/taro";
+
+let useActionSheet;
+let useRoute;
+let useNavigation;
+if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
+    useNavigation = require("@react-navigation/native").useNavigation
+    useActionSheet = require('@expo/react-native-action-sheet').useActionSheet
+}
 
 export default function MainDayNightCard(props: {
     count: number,
@@ -26,8 +36,33 @@ export default function MainDayNightCard(props: {
     scale: number
 }) {
     const health = useSelector((state: any) => state.health);
-    const [isDay, setIsDay] = useState(isCurrentTimeInRange(health.windows.night_day.day.period.start_time, health.windows.night_day.day.period.end_time))
-    const [isDayMode, setIsDayMode] = useState(isCurrentTimeInRange(health.windows.night_day.day.period.start_time, health.windows.night_day.day.period.end_time))
+    let router
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+    const { day } = health.windows.night_day
+    const isTempDay = () => {
+        if (router.params.window == 'DAY') {
+            return true
+        }
+        if (router.params.window == 'NIGHT') {
+            return false
+        }
+        if (isCurrentTimeInRange(day.period.start_time, day.period.end_time)) {
+            return true
+        }
+        return false
+    }
+    
+    const [isDayMode, setIsDayMode] = useState(isTempDay)
     const user = useSelector((state: any) => state.user);
     
     const dispatch = useDispatch();
@@ -36,11 +71,9 @@ export default function MainDayNightCard(props: {
     useEffect(() => {
         const { day } = health.windows.night_day
         if (isCurrentTimeInRange(day.period.start_time, day.period.end_time)) {
-            setIsDay(true)
             setIsDayMode(true)
         }
         else {
-            setIsDay(false)
             setIsDayMode(false)
         }
     }, [])

+ 34 - 16
src/features/health/MainFastEatCard.tsx

@@ -24,15 +24,17 @@ import { setMode } from "@/store/health";
 import { IconSwitch1, IconSwitch2 } from "@/components/basic/Icons";
 import { getDurationArc, getScenario, getStartArc, getWindowStatus } from "./hooks/health_hooks";
 import { useTranslation } from "react-i18next";
-let useNavigation;
+import { useRouter } from "@tarojs/taro";
 
 let checkNotification;
 let min = 0
 let max = 0
 let defaultTimestamp = 0
 let useActionSheet;
-
+let useRoute;
+let useNavigation;
 if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
     useNavigation = require("@react-navigation/native").useNavigation
     checkNotification = require('@/utils/native_permission_check').checkNotification;
     useActionSheet = require('@expo/react-native-action-sheet').useActionSheet
@@ -44,6 +46,19 @@ export default function MainFastEatCard(props: {
     onClick: Function,
     scale: number
 }) {
+    let router
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+
 
 
     const [showModal, setShowModal] = useState(false)
@@ -63,20 +78,23 @@ export default function MainFastEatCard(props: {
     const health = useSelector((state: any) => state.health);
     const dispatch = useDispatch()
 
-
     const { fast, eat } = health.windows.fast_eat
-    const t1 = new Date().getTime()
-    // const isTempFast = true
-    // const isTempFast = eat.status!='OG'&&(fast.status == 'WAIT_FOR_END' ||
-    //     fast.target.start_time <= t1 && fast.target.end_time >= t1) ||
-    //     isCurrentTimeInRange(fast.period.start_time, fast.period.end_time)
-
-    // const isTempFast = eat.status != 'OG' && (isCurrentTimeInRange(fast.period.start_time, fast.period.end_time) ||
-    //     fast.target.start_time <= t1 && fast.target.end_time >= t1 ||
-    //     fast.status == 'WAIT_FOR_END'
-    // )
-
-    const isTempFast = fast.status == 'OG' || (isCurrentTimeInRange(fast.period.start_time, fast.period.end_time) && eat.status == 'WFS')
+
+    const isTempFast = () => {
+        if (router.params.window == 'FAST') {
+            return true
+        }
+        if (router.params.window == 'EAT') {
+            return false
+        }
+        if (fast.status == 'OG') {
+            return true
+        }
+        if (eat.status == 'WFS' && isCurrentTimeInRange(fast.period.start_time, fast.period.end_time)) {
+            return true
+        }
+        return false
+    }
     const [isFastMode, setIsFastMode] = useState(isTempFast)
     const { t } = useTranslation()
 
@@ -93,7 +111,7 @@ export default function MainFastEatCard(props: {
     useEffect(() => {
         const { fast, eat } = health.windows.fast_eat
 
-        if (isTempFast){
+        if (isTempFast()) {
             setIsFastMode(true)
             dispatch(setMode('FAST'))
         }

+ 46 - 6
src/features/health/MainSleepActiveCard.tsx

@@ -10,6 +10,16 @@ import { durationArc, isCurrentTimeInRange, startArc } from "./util";
 import { setMode } from "@/store/health";
 import { getScenario, getThemeColor, getWindowStatus } from "./hooks/health_hooks";
 import { useTranslation } from "react-i18next";
+import { useRouter } from "@tarojs/taro";
+
+let useActionSheet;
+let useRoute;
+let useNavigation;
+if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
+    useNavigation = require("@react-navigation/native").useNavigation
+    useActionSheet = require('@expo/react-native-action-sheet').useActionSheet
+}
 
 export default function MainSleepActiveCard(props: {
     count: any,
@@ -18,12 +28,42 @@ export default function MainSleepActiveCard(props: {
     onClick: Function,
     scale: number
 }) {
-    const [isSleepMode, setIsSleepMode] = useState(true)
+    const health = useSelector((state: any) => state.health);
+    let router
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+    const { sleep, active } = health.windows.sleep_active
+    const isTempSleep = () => {
+        if (router.params.window == 'SLEEP') {
+            return true
+        }
+        if (router.params.window == 'ACTIVE') {
+            return false
+        }
+        if (active.status == 'WFS' && isCurrentTimeInRange(sleep.period.start_time, sleep.period.end_time)) {
+            return true
+        }
+        if (active.status == 'OG') {
+            return false
+        }
+        return false
+    }
+
+    const [isSleepMode, setIsSleepMode] = useState(isTempSleep)
 
     const user = useSelector((state: any) => state.user);
-    const health = useSelector((state: any) => state.health);
+
     const dispatch = useDispatch()
-    const {t} = useTranslation()
+    const { t } = useTranslation()
 
 
     useEffect(() => {
@@ -133,7 +173,7 @@ export default function MainSleepActiveCard(props: {
             const status = getWindowStatus(health.windows, isSleepMode ? 'SLEEP' : 'ACTIVE')
 
             return {
-                color: status == WindowStatusType.upcoming?'#B2B2B2':isSleepMode ? MainColorType.sleep : MainColorType.active,
+                color: status == WindowStatusType.upcoming ? '#B2B2B2' : isSleepMode ? MainColorType.sleep : MainColorType.active,
                 lineWidth: 4,
                 borderColor: '#F5F5F5',
                 offset: 0
@@ -142,7 +182,7 @@ export default function MainSleepActiveCard(props: {
         return null;
     }
 
-    function showDotAnimation(){
+    function showDotAnimation() {
         if (health.mode == 'SLEEP' || health.mode == 'ACTIVE') {
             const status = getWindowStatus(health.windows, isSleepMode ? 'SLEEP' : 'ACTIVE')
             if (status == WindowStatusType.process) return true;
@@ -163,7 +203,7 @@ export default function MainSleepActiveCard(props: {
             currentDot={currentDot()}
             scale={props.scale ?? 1.0}
             showCurrentDotAnimation={showDotAnimation()}
-            />
+        />
     }
 
     return <View style={{ width: rpxToPx(634 / 3), display: 'flex', flexShrink: 0, flexDirection: 'column', alignItems: 'center' }} onClick={() => props.onClick()}>

+ 28 - 25
src/features/health/MainSwiper.tsx

@@ -53,31 +53,34 @@ export default function MainSwiper(props: { count: number, pageChanged: Function
 
 
     useEffect(() => {
-        // if (router.params && router.params.window) {
-        //     switch (router.params.window) {
-        //         case 'day':
-        //         case 'night':
-        //             console.log('a')
-        //             dispatch(setTab(0))
-        //             setCurrent(0)
-        //             break
-        //         case 'fast':
-        //         case 'eat':
-        //             console.log('b')
-        //             dispatch(setTab(1))
-        //             setCurrent(1)
-        //             break
-        //         case 'sleep':
-        //         case 'active':
-        //             console.log('c')
-        //             dispatch(setTab(2))
-        //             setCurrent(2)
-        //             break
-        //     }
-        // }
-        // else {
-        dispatch(setTab(1))
-        // }
+        if (router.params && router.params.window) {
+            // setTimeout(() => {
+            switch (router.params.window) {
+                case 'DAY':
+                case 'NIGHT':
+                    dispatch(setTab(0))
+                    setCurrent(0)
+
+                    break
+                case 'FAST':
+                case 'EAT':
+                    dispatch(setTab(1))
+                    setCurrent(1)
+                    break
+                case 'SLEEP':
+                case 'ACTIVE':
+                    dispatch(setTab(2))
+                    setCurrent(2)
+                    break
+            }
+            dispatch(setMode(router.params.window))
+            //     switchMode()
+            // }, 1500)
+
+        }
+        else {
+            dispatch(setTab(1))
+        }
 
     }, [])