Leon 2 yıl önce
ebeveyn
işleme
7087b6e646

+ 3 - 1
src/context/locales/zh.js

@@ -290,7 +290,9 @@ export default {
             picker_end_title:'结束时间',
             camera:'拍摄食物',
             album:'从相册选择',
-            share_title:'我的饮食日记'
+            share_title:'我的饮食日记',
+            prompt:'提示',
+            prompt_detail:'日志列表顺序发生变化,点击刷新'
         },
         track_something: {
             btn_record: '记录',

+ 8 - 4
src/features/food/FoodConsole.tsx

@@ -44,7 +44,6 @@ export default function Component(props: { addItem: Function }) {
             mediaType: ['image'],
             sourceType: [isAlbum ? 'album' : 'camera'],
             success: function (res) {
-                console.log(res)
                 var tempFilePath = res.tempFiles[0].tempFilePath
                 // Taro.editImage({
                 //     src:tempFilePath,
@@ -124,7 +123,13 @@ export default function Component(props: { addItem: Function }) {
                 file_ext: fileExt
             },
             success: (rsp) => {
-                console.log(rsp)
+                if (rsp.statusCode!=200){
+                    Taro.showToast({
+                        title:'操作失败,请检查网络',
+                        icon:'none'
+                    })
+                    return
+                }
                 Taro.uploadFile({
                     url: rsp.data.upload_url,
                     filePath: path,
@@ -165,7 +170,6 @@ export default function Component(props: { addItem: Function }) {
             }
 
         }).then(res => {
-            console.log(res)
             props.addItem(res)
             clearFile()
             setImgUrl('')
@@ -179,7 +183,7 @@ export default function Component(props: { addItem: Function }) {
     return <View style={{ marginBottom: rpxToPx(60) }}>
         <View style={{ display: 'flex', width: rpxToPx(750), alignItems: 'center', justifyContent: 'center', flexDirection: 'column' }}>
             <View style={{ display: 'flex', flexDirection: 'column' }}>
-                {/* <Slider /> */}
+                <Slider />
                 {/* <View className='box11' onClick={()=>choose(true)}>{
                     imgUrl && <Image style={{ width: '100%', height: '100%' }} src={imgUrl} mode="aspectFill" />
                 }

+ 48 - 7
src/features/food/FoodJournal.tsx

@@ -26,7 +26,7 @@ export default function Component() {
     const [total, setTotal] = useState(0)
     const [isLoading, setIsLoading] = useState(false)
     const [loaded, setLoaded] = useState(false)
-    const [showError,setShowError] = useState(false)
+    const [showError, setShowError] = useState(false)
 
     useEffect(() => {
         getTags()
@@ -41,12 +41,21 @@ export default function Component() {
             dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
             setTimeout(() => {
                 getList(1)
-
             }, 200)
-
         }
     })
 
+    //0点刷新一下数据
+    useEffect(() => {
+        const now = new Date();
+        const nextMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 0, 0, 0);
+        const timeUntilMidnight = nextMidnight.getTime() - now.getTime();
+
+        setTimeout(() => {
+            refreshData()
+        }, timeUntilMidnight);
+    }, [])
+
 
 
     usePullDownRefresh(() => {
@@ -61,6 +70,25 @@ export default function Component() {
         // getHistory()
     })
 
+    //0点刷新一下数据
+    function refreshData() {
+        list.map(item => {
+            item.showDate = false
+        })
+
+        var selDate = ''
+        for (var i = 0; i < list.length; i++) {
+            var obj = list[i]
+            if (obj.start.date != selDate) {
+                obj.showDate = true
+                selDate = obj.start.date
+            }
+        }
+
+        setList(list)
+        setCount(count + 1)
+    }
+
     function getTags() {
         getFoodTags({
             type: 'meal_tag'
@@ -109,9 +137,9 @@ export default function Component() {
                 // setList(list.concat((res as any).data))
             }
             var selDate = ''
-            for (var i =0;i<array.length;i++){
+            for (var i = 0; i < array.length; i++) {
                 var obj = array[i]
-                if (obj.start.date!=selDate){
+                if (obj.start.date != selDate) {
                     obj.showDate = true
                     selDate = obj.start.date
                 }
@@ -120,7 +148,7 @@ export default function Component() {
             setIsLoading(false)
         }).catch(e => {
             Taro.stopPullDownRefresh()
-            if (pageIndex==1){
+            if (pageIndex == 1) {
                 setShowError(true)
             }
         })
@@ -133,6 +161,19 @@ export default function Component() {
             temps = []
         }
         temps.unshift(item)
+        temps.map(item => {
+            item.showDate = false
+        })
+
+        var selDate = ''
+        for (var i = 0; i < temps.length; i++) {
+            var obj = temps[i]
+            if (obj.start.date != selDate) {
+                obj.showDate = true
+                selDate = obj.start.date
+            }
+        }
+
         setList(temps)
     }
 
@@ -146,7 +187,7 @@ export default function Component() {
                 <FoodConsole addItem={addItem} />
             }
             {
-                user.isLogin && list && <FoodTimeline array={list} />
+                user.isLogin && list && <FoodTimeline array={list} refresh={()=>getList(1)}/>
             }
             {
                 user.isLogin && showError && <NoData refresh={() => { getList(1) }} />

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

@@ -5,7 +5,7 @@ import { useEffect, useState } from 'react'
 import { delFoodJournal } from '@/services/foodJournal'
 import Taro from '@tarojs/taro'
 
-export default function Component(props: { array: any }) {
+export default function Component(props: { array: any,refresh:Function }) {
     const [list, setList] = useState(props.array)
 
     useEffect(() => {
@@ -58,6 +58,7 @@ export default function Component(props: { array: any }) {
                 delete={() => del(index)} 
                 preview={()=>preview(index)}
                 update={(data)=>updateItem(index,data)}
+                forceRefresh={()=>props.refresh()}
                 />
             })
         }

+ 4 - 1
src/features/food/FoodTimelineItem.scss

@@ -17,10 +17,11 @@
 
 .food_timeline_item_day{
     font-size: 36px;
+    line-height: 36px;
     color: #fff;
     font-weight: bold;
     margin-bottom: 12px;
-    margin-bottom: -8px;
+    margin-bottom: -9px;
 }
 
 .tag-item{
@@ -51,6 +52,7 @@
     width: 304px;
     height: 304px;
     border-radius: 36px;
+    background-color: #1c1c1c;
     overflow: hidden;
 }
 
@@ -89,6 +91,7 @@
 }
 
 .food_share {
+    margin-top: 24px;
     width: 72px;
     height: 72px;
     display: flex;

+ 39 - 16
src/features/food/FoodTimelineItem.tsx

@@ -13,7 +13,10 @@ import { IconShare } from "@/components/basic/Icons";
 import { TimeFormatter } from "@/utils/time_format";
 import { baseUrl } from "@/services/http/api";
 
-export default function Component(props: { data: any, index: number, delete: Function, preview: Function, update: Function }) {
+export default function Component(props: {
+    data: any, index: number,
+    delete: Function, preview: Function, update: Function, forceRefresh?: Function
+}) {
     const common = useSelector((state: any) => state.common);
     const [detail, setDetail] = useState(props.data)
     const [count, setCount] = useState(0)
@@ -71,13 +74,17 @@ export default function Component(props: { data: any, index: number, delete: Fun
     }
 
     function operateActionSheet() {
+        var itemList = [t('feature.food.action_sheet.tag')]
+        var date = TimeFormatter.getMonthAndDayByDate(detail.start.date)
+        if (date == '今天' || date == '昨天') {
+            itemList.push(t('feature.food.action_sheet.start_time'))
+            itemList.push(t('feature.food.action_sheet.end_time'))
+        }
+
+
         Taro.showActionSheet({
             alertText: t('feature.food.action_sheet.alert_text'),
-            itemList: [
-                t('feature.food.action_sheet.tag'),
-                t('feature.food.action_sheet.start_time'),
-                t('feature.food.action_sheet.end_time'),
-            ]
+            itemList: itemList
         })
             .then(res => {
                 switch (res.tapIndex) {
@@ -182,6 +189,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
                 source: detail.media[0].source ? detail.media[0].source : 'album'
             }]
         }, detail.id).then(res => {
+            (res as any).showDate = props.data.showDate
             setDetail(res)
             setCount(count + 1)
 
@@ -210,13 +218,9 @@ export default function Component(props: { data: any, index: number, delete: Fun
                 code: tag.code
             }
         }, detail.id).then(res => {
-            var obj = detail
-            // obj.tags = [tag]
-            obj.meal_tag = {
-                code: tag.code,
-                label: tag.label
-            }
-            setDetail(obj)
+            (res as any).showDate = props.data.showDate
+
+            setDetail(res)
             setCount(count + 1)
 
             props.update(res)
@@ -249,14 +253,33 @@ export default function Component(props: { data: any, index: number, delete: Fun
         editFoodJournal({
             ...obj
         }, detail.id).then(res => {
+            (res as any).showDate = props.data.showDate
             setDetail(res)
             setCount(count + 1)
             props.update(res)
+            if ((res as any).index_change) {
+                showRefreshAlert()
+            }
+
+
         }).catch(e => {
 
         })
     }
 
+    function showRefreshAlert() {
+        Taro.showModal({
+            title: t('feature.food.prompt'),
+            content: t('feature.food.prompt_detail'),
+            showCancel: false,
+            success: function (res) {
+                if (res.confirm) {
+                    props.forceRefresh!()
+                }
+            }
+        })
+    }
+
     function pickerTagIndex() {
         var list = common.meal_tags
         if (detail.meal_tag) {
@@ -298,7 +321,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
             return detail.start.timestamp
         }
         else {
-            return detail.end.timestamp ? detail.end.timestamp : new Date().getTime()
+            return detail.end.timestamp ? detail.end.timestamp : detail.start.timestamp
         }
     }
 
@@ -308,7 +331,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
         <View style={{ flex: 1 }}>
             {
                 <View className="tags">
-                    {detail.showDate && <Text className="food_timeline_item_day">{TimeFormatter.getMonthDayByTimestamp(detail.start.timestamp)}</Text>}
+                    {detail.showDate && <Text className="food_timeline_item_day">{TimeFormatter.getMonthAndDayByDate(detail.start.date)}</Text>}
                     {
                         props.index == 0 && !detail.meal_tag && common.meal_tags.map((item, index) => {
                             return index <= 2 ? <View className="tag-item" onClick={() => updateTag(index)}>
@@ -326,7 +349,7 @@ export default function Component(props: { data: any, index: number, delete: Fun
             {/* <Image className="thumb" src={detail.cover.url} mode="aspectFill" onClick={preview} /> */}
             <Image className="thumb" src={detail.media[0].url + '?x-oss-process=image/resize,w_300,limit_0'} mode="aspectFill" onClick={preview} />
             <View className="food_desc" onClick={operateActionSheet}>
-                {/* <Text className="food_desc_text">{detail.start && TimeFormatter.getMonthDayByTimestamp(detail.start.timestamp)}</Text> */}
+                {/* <Text className="food_desc_text">{detail.start && TimeFormatter.getMonthAndDayByDate(detail.start.timestamp)}</Text> */}
                 <Text className="food_desc_text">{detail.meal_tag && detail.meal_tag.label}</Text>
                 <Text className="food_desc_text">{detail.start && TimeFormatter.getTimeByTimestamp(detail.start.timestamp)}</Text>
                 <Text className="food_desc_text">{detail.end.timestamp && '~' + TimeFormatter.getTimeByTimestamp(detail.end.timestamp)}</Text>

+ 3 - 1
src/features/trackSomething/components/Activity.tsx

@@ -43,7 +43,7 @@ export default function Component(props: any) {
     const [triggered, setTriggered] = useState(true)
     const [showErrorPage, setErrorPage] = useState(false)
     const [showModal, setShowModal] = useState(false)
-
+    const [loaded,setLoaded] = useState(false)
     const [count, setCount] = useState(0)
     let navigation;
     if (useNavigation) {
@@ -109,11 +109,13 @@ export default function Component(props: any) {
                     setLatestRecord(obj.latest_record)
                 }
             }
+            setLoaded(true)
         }).catch(e => {
             setTriggered(false)
             if (list.length == 0) {
                 setErrorPage(true)
             }
+            setLoaded(true)
         })
     }
 

+ 13 - 10
src/features/trackSomething/components/Metric.tsx

@@ -47,9 +47,10 @@ export default function Component(props: any) {
     const [orignalGroups, setOrignalGroups] = useState([])
     const [limits, setLimits] = useState(null)
     const [orders, setOrders] = useState([])
-    const [newOrders,setNewOrders] = useState([])
-    const [resultOrders,setResultOrders] = useState([])
+    const [newOrders, setNewOrders] = useState([])
+    const [resultOrders, setResultOrders] = useState([])
     const [tempMetricItem, setTempMetricItem] = useState(null)
+    const [loaded, setLoaded] = useState(false)
     const dispatch = useDispatch();
     let navigation;
     if (useNavigation) {
@@ -96,11 +97,12 @@ export default function Component(props: any) {
                 list.push({
                     name: item.name,
                     code: item.code,
-                    is_following:true
+                    is_following: true
                 })
             })
             setOrders(list)
             setResultOrders(list)
+            setLoaded(true)
 
         }).catch(e => {
             Taro.stopPullDownRefresh()
@@ -108,6 +110,7 @@ export default function Component(props: any) {
                 setErrorPage(true)
             }
             setTriggered(false)
+            setLoaded(false)
         })
     }
 
@@ -240,7 +243,7 @@ export default function Component(props: any) {
     }
 
     function headerView() {
-        return <TitleView title={t('page.metric.title')} showAddBtn={true} onClick={addBtnClick}>
+        return <TitleView title={t('page.metric.title')} showAddBtn={loaded && !showErrorPage ? true : false} onClick={addBtnClick}>
         </TitleView>
     }
 
@@ -301,7 +304,7 @@ export default function Component(props: any) {
         onPageContainerCancel()
     }
 
-    function modalConfirm(datas,newOrders,resultOrders,groups) {
+    function modalConfirm(datas, newOrders, resultOrders, groups) {
         setOrders(datas)
         setGroups(groups)
         setNewOrders(newOrders)
@@ -393,7 +396,7 @@ export default function Component(props: any) {
                 array.push({
                     name: (item as any).name,
                     code: (item as any).code,
-                    is_following:true
+                    is_following: true
                 })
             })
             // debugger
@@ -418,13 +421,13 @@ export default function Component(props: any) {
         />
 
         {
-            showPageContainer && <Modal dismiss={()=>{
+            showPageContainer && <Modal dismiss={() => {
                 onPageContainerCancel()
                 setShowPageContainer(false)
-            }} confirm={()=>{}}>
+            }} confirm={() => { }}>
                 {
-                metricModalContent()
-            }
+                    metricModalContent()
+                }
             </Modal>
         }
         {/* <PageContainer style={{ backgroundColor: '#1c1c1c' }}

+ 5 - 1
src/pages/clock/Clock.weapp.tsx

@@ -82,6 +82,7 @@ export default function IndexPage() {
   const [showTip, setShowTip] = useState(false)
   const [isModal1, setIsModal1] = useState(false)
   const [debugInfo, setDebugInfo] = useState(null)
+  const [loaded, setLoaded] = useState(false)
 
   let navigation;
   if (useNavigation) {
@@ -299,6 +300,8 @@ export default function IndexPage() {
       machine.context.currentStatus = `${key}.${status}`;//'mixed.ON_GOING2'
       setCheckData(res as any)
 
+      setLoaded(true)
+
       if ((res as any).current_record.status != 'ONGOING1') {
         setSwiperIndex(0)
       }
@@ -321,6 +324,7 @@ export default function IndexPage() {
       }
 
     }).catch(e => {
+      setLoaded(true)
       if (!checkData) {
         setErrorPage(true)
       }
@@ -388,7 +392,7 @@ export default function IndexPage() {
   }
 
   function headerView() {
-    return <TitleView title={t('page.clock.title')} showAddBtn={true}>
+    return <TitleView title={t('page.clock.title')} showAddBtn={loaded && !showErrorPage ? true : false}>
       <StatusIndicator />
     </TitleView>
   }

+ 0 - 16
src/utils/time_format.ts

@@ -201,22 +201,6 @@ export class TimeFormatter {
     }
   }
 
-  static getMonthDayByTimestamp(num: number): string {
-    const dt = new Date(num);
-    const now = new Date();
-    const diff = now.getTime() - dt.getTime();
-    const day = 1000 * 60 * 60 * 24;
-    if (diff < day) {
-      return '今日';
-    } else if (diff < 2 * day) {
-      return '昨日';
-    } else {
-      var month = dt.getMonth() + 1
-      var date = dt.getDate()
-      return month + '月' + date + '日'
-    }
-  }
-
   static getTimeByTimestamp(num: number): string {
     const dt = new Date(num);
     var hour = dt.getHours()