Leon 1 سال پیش
والد
کامیت
d080dea329

+ 32 - 11
src/_health/pages/active_plan.tsx

@@ -36,7 +36,8 @@ 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>([])
+    const [list, setList] = useState<any>([])
+    const [loaded, setLoaded] = useState(false)
 
     useEffect(() => {
         getLabelsEvent({ window: health.mode }).then(res => {
@@ -46,9 +47,10 @@ export default function ActivePlan() {
         getDatas()
     }, [])
 
-    function getDatas(){
+    function getDatas() {
         getSchedules({ window: health.mode }).then(res => {
             setList((res as any).data)
+            setLoaded(true)
         })
     }
 
@@ -56,14 +58,34 @@ export default function ActivePlan() {
         setShowModal(true)
     }
 
+    if (!loaded) return <View />
+
     return <View style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
         <Text>Plan my daily life</Text>
         <Text>Header: List top 3 activities that matter most to me/I want to practice to every day</Text>
-        <View className="plan_item" onClick={tapEdit}>
-            <Text>1</Text>
-            <Text style={{ flex: 1 }}>{schedule.title}</Text>
-            <Text style={{ color: getThemeColor('ACTIVE') }}>Tap to customize</Text>
-        </View>
+        {
+            list.length == 0 && <View className="plan_item" onClick={tapEdit}>
+                <Text>1</Text>
+                <Text style={{ flex: 1 }}>{schedule.title}</Text>
+                <Text style={{ color: getThemeColor('ACTIVE') }}>Tap to customize</Text>
+            </View>
+        }
+        {
+            list.map((item, index) => {
+                return <View className="plan_item" key={index}>
+                    <Text>{1 + index}</Text>
+                    <Text style={{ flex: 1 }}>{item.title}</Text>
+                    <Text>{item.time ? item.time : item.time_label}</Text>
+                </View>
+            })
+        }
+        {
+            list.length > 0 && list.length < 3 && <View className="plan_item" onClick={tapEdit}>
+                <Text style={{color: getThemeColor('ACTIVE')}}>+</Text>
+                <Text style={{ flex: 1,color: getThemeColor('ACTIVE') }}>Daily Activity</Text>
+            </View>
+        }
+
 
         {
             showModal && <Modal testInfo={null}
@@ -71,11 +93,10 @@ export default function ActivePlan() {
                     setShowModal(false)
                 }}
                 confirm={() => { }}>
-                <AddLabel labels={labels} defaultValue={schedule.title} disMiss={()=>{
+                <AddLabel labels={labels} defaultValue={list.length==0?schedule.title:''} disMiss={() => {
                     setShowModal(false)
-                    // getDatas()
-                    Taro.navigateBack()
-                }}/>
+                    getDatas()
+                }} />
             </Modal>
         }
     </View>

+ 17 - 7
src/_health/pages/add_moment.tsx

@@ -58,11 +58,14 @@ export default function AddMoment() {
 
     useEffect(() => {
         var obj = JSON.parse(router.params.moment)
+        if (obj.target) {
+            obj.target.timestamp = new Date().getTime()
+            setDurationT(obj.target.duration ?? 0)
+        }
 
-        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')
         // setStartTime(start)
@@ -142,12 +145,19 @@ export default function AddMoment() {
             schedule_id: moment.schedule_id,
             title: moment.title,
             description: desc,
-            start: {
+        }
+
+        if (moment.target) {
+            params.start = {
                 date: dayjs(moment.target.timestamp).format('YYYYMMDD'),
                 timestamp: moment.target.timestamp
-            },
-
-            // real_end_time: meal.target_end_time,
+            }
+        }
+        else {
+            params.start = {
+                date: dayjs().format('YYYYMMDD'),
+                timestamp: new Date().getTime()
+            }
         }
 
         if (title.length > 0) {
@@ -166,7 +176,7 @@ export default function AddMoment() {
         if (moment.event_id) {
             params.event_id = moment.event_id
         }
-        if (moment.target.duration) {
+        if (moment.target && moment.target.duration) {
             params.duration = durationT//moment.target.duration
         }
         createMoment(params).then(res => {

+ 9 - 0
src/_health/pages/schedules_edit.tsx

@@ -148,6 +148,15 @@ export default function SchedulesEdit() {
                                             }
                                         ]}
                                         onClick={() => {
+                                            if (item.window=='ACTIVE'||item.window=='EAT'){
+                                                if (item.list.length==1){
+                                                    Taro.showToast({
+                                                        title:'至少保留一项',
+                                                        icon:'none'
+                                                    })
+                                                    return;
+                                                }
+                                            }
                                             showAlert({
                                                 title: '删除',
                                                 content: '确认删除此计划',

+ 11 - 4
src/_health/pages/schedules_list.tsx

@@ -118,7 +118,14 @@ export default function SchedulesList() {
         })
     }
 
-    function add() {
+    function add(item) {
+        if (item.list.length==5){
+            Taro.showToast({
+                title:'最多添加4个',
+                icon:'none'
+            })
+            return;
+        }
         setShowModal(true)
     }
 
@@ -240,9 +247,9 @@ export default function SchedulesList() {
                                         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>
+                                            onClick={()=>add(item)}>
+                                            <IconAdd color={item.list.length==5?'gray':getThemeColor(item.window)} width={rpxToPx(34)} />
+                                            <View className='toolbar_btn' style={{ color: item.list.length==5?'gray':getThemeColor(item.window) }} >添加</View>
                                             <View style={{ flex: 1 }} />
                                             {/* <View className='toolbar_btn' style={{ color: getThemeColor(health.mode) }} onClick={() => setShowDel(!showDel)}>移除</View> */}
                                         </View>

+ 9 - 3
src/features/health/MainConsole.tsx

@@ -144,7 +144,7 @@ export default function MainConsole(props: { type: WindowType }) {
         if (item.real) {
             return dayjs(item.real.timestamp).format('HH:mm')
         }
-        if (!item.target||!item.target.timestamp){
+        if (!item.target || !item.target.timestamp) {
             return item.time_label
         }
         return dayjs(item.target.timestamp).format('HH:mm')
@@ -562,8 +562,8 @@ export default function MainConsole(props: { type: WindowType }) {
                     }}>
                         <Text>{list[0].title}</Text>
                         <Text>Subtitle</Text>
-                        <View onClick={()=>{
-                            jumpPage('/_health/pages/active_plan?schedule='+JSON.stringify(list.length>0?list[0]:'{}'))
+                        <View onClick={() => {
+                            jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(list.length > 0 ? list[0] : '{}'))
                         }} style={{
                             display: 'flex',
                             flexDirection: 'column',
@@ -713,6 +713,12 @@ export default function MainConsole(props: { type: WindowType }) {
             {
                 detail()
             }
+            {
+                health.mode == 'ACTIVE' && <View onClick={() => {
+                    var list = getScenario(health.windows,health.mode).timeline
+                    jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(list.length > 0 ? list[0] : '{}'))
+                }}>测试</View>
+            }
         </View>
         <View className="main_footer">
             <Text className="main_footer_text" onClick={tapSwitchBtn}>{switchText()}</Text>

+ 1 - 1
src/pages/account/Album.tsx

@@ -48,7 +48,7 @@ export default function Album() {
         }
 
         <View className="photo_wall" onClick={() => {
-            jumpPage('/pages/account/PhotoWall')
+            jumpPage('/pages/account/PhotoWall?window='+window)
         }}>
             <View style={{ flex: 1 }} />
             <Text className="photo_wall_text">Photo Wall</Text>

+ 62 - 15
src/pages/account/PhotoWall.tsx

@@ -1,24 +1,71 @@
-import { View } from "@tarojs/components";
+import { View, Image } from "@tarojs/components";
 import './PhotoWall.scss'
-import Taro from "@tarojs/taro";
-import { useState } from "react";
+import Taro, { useRouter } from "@tarojs/taro";
+import { useEffect, useState } from "react";
 import NewTimePicker from "@/_health/base/new_timepicker";
+import { getAlbums } from "@/services/health";
+
+let useRoute;
+let useNavigation;
+let scenario = '';
+if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
+    useNavigation = require("@react-navigation/native").useNavigation
+}
+
+const scale = '?x-oss-process=image/resize,w_150,limit_0'
 
 export default function PhotoWall() {
     const screenWidth = Taro.getSystemInfoSync().screenWidth
     const space = 2
-    const itemWidth = (screenWidth-space*2)/3.0
-    const [list, setList] = useState(new Array(10).fill("aaa"))
-    return <View style={{display:'flex',flexDirection:'column'}}>
-        <NewTimePicker />
-        <View className="photo_wall">
-        {
-            list.map((item, index) => {
-                return <View key={index} style={{ width: itemWidth, height: itemWidth, backgroundColor: 'pink',marginBottom:space }}></View>
+    const itemWidth = (screenWidth - space * 2) / 3.0
+    const [list, setList] = useState<any>([])
+
+    let router
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+
+    useEffect(() => {
+        getAlbumsData(router.params.window)
+    }, [])
+
+
+    function getAlbumsData(str) {
+        getAlbums({
+            page: 1,
+            limit: 50,
+            window: str
+        }).then(res => {
+            var array: any = [];
+            (res as any).data.map(item => {
+                array.push(...item.images)
             })
-        }
-        <View style={{ width: itemWidth, height: itemWidth }} />
-        <View style={{ width: itemWidth, height: itemWidth }} />
-    </View>
+            setList(array)
+            // setMedias((res as any).data)
+        })
+    }
+    return <View style={{ display: 'flex', flexDirection: 'column' }}>
+        {/* <NewTimePicker /> */}
+        <View className="photo_wall">
+            {
+                list.map((item, index) => {
+                    return <Image key={index}
+                        src={item+scale}
+                        mode="aspectFill"
+                        style={{ width: itemWidth, height: itemWidth, backgroundColor: 'pink', marginBottom: space }} />
+                })
+            }
+            <View style={{ width: itemWidth, height: itemWidth }} />
+            <View style={{ width: itemWidth, height: itemWidth }} />
+        </View>
     </View>
 }