Leon 2 سال پیش
والد
کامیت
004a657b5d

+ 0 - 2
src/components/input/LimitPickers.tsx

@@ -169,7 +169,6 @@ const Component = forwardRef((props: {
         const day = date.getDate();
         const time = `${year}-${expandZero(month)}-${expandZero(day)}T${expandZero(hours[values[1]])}:${expandZero(minutes[values[2]])}:${expandZero((new Date(global.set_time)).getSeconds())}`;
         console.log(global.set_time)
-        debugger
         if (getTimestamp(time) > global.set_time) {
             Taro.showToast({
                 icon: 'none',
@@ -182,7 +181,6 @@ const Component = forwardRef((props: {
             var limitDate = new Date(props.limit)
 
             if (getTimestamp(time) < props.limit) {
-                debugger
                 Taro.showToast({
                     icon: 'none',
                     title: t('feature.common.toast.max_time_value'),

+ 1 - 1
src/components/input/PickerViews.tsx

@@ -45,7 +45,7 @@ const Component = forwardRef((props: {
         getConfirmData: confirm
     }));
 
-    return <View className='modal_content'>
+    return <View className='modal_content' catchMove>
         <Text className='modal_title' style={{ color: color }}>{props.title ? props.title : '测试标题 '}</Text>
         <PickerView value={v}
             onChange={onPickerChange}

+ 8 - 2
src/components/layout/Modal.tsx

@@ -49,8 +49,14 @@ export default function Modal(props: {
             </View>
     }
 
+    function longPress(e) {
+        if (process.env.TARO_ENV == 'weapp') {
+            e.stopPropagation()
+        }
+    }
+
 
-    return <View className='modal' catchMove >
+    return <View className='modal' catchMove onLongPress={longPress}>
         <View style={{ flex: 1, width: 375, flexShrink: 0 }} onClick={(e) => {
             if (process.env.TARO_ENV == 'weapp') {
                 e.stopPropagation()
@@ -60,7 +66,7 @@ export default function Modal(props: {
                 props.testInfo ? props.testInfo : null
             }
         </View>
-        <View className='modal_bottom_content' style={{flexShrink:0}} onClick={onClick}>
+        <View className='modal_bottom_content' style={{ flexShrink: 0 }} onClick={onClick}>
             {/* <Text className='modal_title' style={{ color: color }}>{props.title ? props.title : '测试标题 '}</Text> */}
             {
                 props.children

+ 28 - 17
src/context/locales/zh.js

@@ -19,17 +19,17 @@ export default {
         metric: {
             title: '指标',
         },
-        food:{
-            title:'饮食',
+        food: {
+            title: '饮食',
         },
         more: {
             title: '更多',
-            un_login:'未登录',
-            stone:'逆龄石',
-            stone_desc:'会员体系升级中,期间指标记录限时免逆龄石记录\n敬请期待',
-            setting:'设置',
-            reset_session:'重置session',
-            debug_mode:'走查模式'
+            un_login: '未登录',
+            stone: '逆龄石',
+            stone_desc: '会员体系升级中,期间指标记录限时免逆龄石记录\n敬请期待',
+            setting: '设置',
+            reset_session: '重置session',
+            debug_mode: '走查模式'
         },
         choose_scenario: {
             title: '选择生物钟',
@@ -53,8 +53,8 @@ export default {
             btn_create_account: '',
             btn_login: '登录',
             btn_wechat: '微信登录',
-            btn_signup:'注册',
-            slogan:'健康生物钟'
+            btn_signup: '注册',
+            slogan: '健康生物钟'
         },
         auth: {
             agreement: '已阅读并同意《用户协议》和《隐私政策》',
@@ -73,7 +73,7 @@ export default {
         user_profile: {
             title: '编辑资料',
             nickname: '昵称',
-            save:'保存'
+            save: '保存'
         }
 
 
@@ -93,13 +93,13 @@ export default {
             toast: {
                 min_value: '不能再小了',
                 max_value: '不能再大了',
-                min_metric_count:'选择至少{{count}}项',
-                max_metric_count:'高级会员可选择{{count}}项以上',
+                min_metric_count: '选择至少{{count}}项',
+                max_metric_count: '高级会员可选择{{count}}项以上',
                 min_time_value: '不能再晚了',
                 max_time_value: '不能再早了',
                 update_success: '更新成功',
-                input_nickname:'请输入昵称',
-                ongoing:'请先完成记录',//进行中点击加号,actionsheet item时弹此提示
+                input_nickname: '请输入昵称',
+                ongoing: '请先完成记录',//进行中点击加号,actionsheet item时弹此提示
             },
             action_sheet: {
                 delete: '删除'
@@ -274,6 +274,17 @@ export default {
                 not_started: '未开始'
             }
         },
+        food: {
+            action_sheet: {
+                tag: '标签',
+                title: '选择要编辑的信息',
+                start_time: '开始时间',
+                end_time: '结束时间'
+            },
+            picker_tag_title:'编辑标签',
+            picker_start_title:'开始时间',
+            picker_end_title:'结束时间'
+        },
         track_something: {
             btn_record: '记录',
             picker_datetime: '记录时间',
@@ -302,8 +313,8 @@ export default {
                 un_login: '未登录',
                 login_can_check: '登录后可记录',
                 check_unlock_data: '记录解锁趋势',
-                choose_metric:'选择指标项',
-                order:'调整排序'
+                choose_metric: '选择指标项',
+                order: '调整排序'
 
             },
             werun_auth: {

+ 1 - 0
src/features/food/FoodJournal.tsx

@@ -58,6 +58,7 @@ export default function Component() {
         setIsLoading(true)
         var page = pageIndex + 1
         setPageIndex(page)
+        getList(page)
     }
 
 

+ 11 - 2
src/features/food/FoodTimeline.tsx

@@ -10,7 +10,7 @@ export default function Component(props: { array: any }) {
 
     useEffect(() => {
         setList(props.array)
-    }, [props.array.length])
+    }, [props.array,props.array.length])
 
     function del(index) {
         delFoodJournal(list[index].id).then(res => {
@@ -32,10 +32,19 @@ export default function Component(props: { array: any }) {
         })
     }
 
+    function updateItem(index,data){
+        list[index] = data
+        setList(list)
+    }
+
     return <View style={{ flexDirection: 'column', display: 'flex' }}>
         {
             list.map((item, index) => {
-                return <FoodTimelineItem data={item} key={index} delete={() => del(index)} preview={()=>preview(index)}/>
+                return <FoodTimelineItem data={item} index={index} key={index} 
+                delete={() => del(index)} 
+                preview={()=>preview(index)}
+                update={(data)=>updateItem(index,data)}
+                />
             })
         }
     </View>

+ 91 - 8
src/features/food/FoodTimelineItem.tsx

@@ -8,12 +8,14 @@ import LimitPickers from "@/components/input/LimitPickers";
 import Modal from "@/components/layout/Modal";
 import { ColorType } from "@/context/themes/color";
 import { useSelector } from "react-redux";
+import PickerViews from "@/components/input/PickerViews";
 
-export default function Component(props: { data: any, delete: Function, preview: Function }) {
+export default function Component(props: { data: any, index: number, delete: Function, preview: Function, update: Function }) {
     const common = useSelector((state: any) => state.common);
     const [detail, setDetail] = useState(props.data)
     const [count, setCount] = useState(0)
     const [showModal, setShowModal] = useState(false)
+    const [showTagModal, setShowTagModal] = useState(false)
     const [isStart, setIsStart] = useState(false)
     const { t } = useTranslation()
 
@@ -31,7 +33,7 @@ export default function Component(props: { data: any, delete: Function, preview:
 
     function showActionSheet() {
         Taro.showActionSheet({
-            itemList: [t('feature.common.action_sheet.delete'), '餐前时间', '餐后时间']
+            itemList: [t('feature.common.action_sheet.delete')]
         })
             .then(res => {
                 switch (res.tapIndex) {
@@ -46,14 +48,35 @@ export default function Component(props: { data: any, delete: Function, preview:
                             }
                         })
                         break;
+                }
+            })
+            .catch(err => {
+                console.log(err.errMsg)
+            })
+    }
+
+    function operateActionSheet() {
+        Taro.showActionSheet({
+            alertText: t('feature.food.action_sheet.title'),
+            itemList: [t('feature.food.action_sheet.tag'),
+            t('feature.food.action_sheet.start_time'),
+            t('feature.food.action_sheet.end_time')]
+        })
+            .then(res => {
+                switch (res.tapIndex) {
+                    case 0:
+                        setShowTagModal(true)
+                        break;
                     case 1:
                         {
+                            global.set_time = new Date().getTime()
                             setIsStart(true)
                             setShowModal(true)
                         }
                         break;
                     case 2:
                         {
+                            global.set_time = new Date().getTime()
                             setIsStart(false)
                             setShowModal(true)
                         }
@@ -80,6 +103,8 @@ export default function Component(props: { data: any, delete: Function, preview:
             }
             setDetail(obj)
             setCount(count + 1)
+
+            props.update(res)
         }).catch(e => {
 
         })
@@ -111,6 +136,7 @@ export default function Component(props: { data: any, delete: Function, preview:
         }, detail.id).then(res => {
             setDetail(res)
             setCount(count + 1)
+            props.update(res)
         }).catch(e => {
 
         })
@@ -123,18 +149,63 @@ export default function Component(props: { data: any, delete: Function, preview:
         return (hour < 10 ? '0' + hour : hour) + ':' + (minute < 10 ? '0' + minute : minute)
     }
 
+    function pickerTagIndex() {
+        var list = common.meal_tags
+        if (detail.meal_tag) {
+            for (var i = 0; i < list.length; i++) {
+                if (list[i].label == detail.meal_tag.label) {
+                    return i;
+                }
+            }
+        }
+
+        return 0;
+    }
+
+    function pickerTagItems() {
+        var list = common.meal_tags
+        var tags: any = []
+        list.map(item => {
+            tags.push(item.label)
+        })
+        return [tags];
+    }
+
+    function tagChanged(data) {
+        setShowTagModal(false)
+        updateTag(data[0])
+    }
+
+    function getPickerLimit() {
+        if (isStart) {
+            return new Date().getTime() - 7 * 24 * 3600 * 1000
+        }
+        else {
+            return detail.start.timestamp
+        }
+    }
+
+    function getPickerInitValue() {
+        if (isStart) {
+            return detail.start.timestamp
+        }
+        else {
+            return detail.end.timestamp ? detail.end.timestamp : new Date().getTime()
+        }
+    }
+
     return <View className="food_timeline_item" onLongPress={showActionSheet}>
         {/* <View className="thumb" style={{backgroundColor:'pink'}}/> */}
         <View className="tags">
             {
-                common.meal_tags.map((item, index) => {
+                props.index == 0 && !detail.meal_tag && common.meal_tags.map((item, index) => {
                     return <Text onClick={() => updateTag(index)}>{item.label}</Text>
                 })
             }
         </View>
         <View className="thumb_bg">
             <Image className="thumb" src={detail.cover} mode="aspectFill" onClick={preview} />
-            <View className="food_desc">
+            <View className="food_desc" onClick={operateActionSheet}>
                 <Text>{detail.meal_tag && detail.meal_tag.label}</Text>
                 <Text>{detail.start && getTime(detail.start.timestamp)} </Text>
                 {
@@ -147,10 +218,10 @@ export default function Component(props: { data: any, delete: Function, preview:
             showModal && <Modal dismiss={() => { setShowModal(false) }} confirm={() => { setShowModal(false) }}>
                 <View className='modal_content'>
                     <LimitPickers
-                        isRealTime={true} time={new Date().getTime()} limit={new Date().getTime() - 120 * 24 * 3600 * 1000}
-                        title={isStart ? '餐前時間' : '餐後時間'}
-                        themeColor={ColorType.fast}
-                        limitDay={120} onCancel={() => { setShowModal(false) }}
+                        isRealTime={true} time={getPickerInitValue()} limit={getPickerLimit()}
+                        title={isStart ? t('feature.food.picker_start_title') : t('feature.food.picker_end_title')}
+                        themeColor={ColorType.food}
+                        limitDay={7} onCancel={() => { setShowModal(false) }}
                         onChange={(e) => {
                             updateTime(e)
                             setShowModal(false)
@@ -158,6 +229,18 @@ export default function Component(props: { data: any, delete: Function, preview:
                 </View>
             </Modal>
         }
+        {
+            showTagModal && <Modal dismiss={() => { setShowTagModal(false) }} confirm={() => { setShowTagModal(false) }}>
+                <PickerViews title={t('feature.food.picker_tag_title')}
+                    value={[pickerTagIndex()]}
+                    items={pickerTagItems()}
+                    onChange={(e) => { tagChanged(e) }}
+                    onCancel={() => { setShowTagModal(false) }}
+                    themeColor={ColorType.food}
+
+                />
+            </Modal>
+        }
 
     </View>
 }