Leon 1 jaar geleden
bovenliggende
commit
41f5d35b40

+ 2 - 6
src/_health/components/post_moment_time.tsx

@@ -149,10 +149,6 @@ export default function PostMomentTime(props: {
         return scenario.picker_min_timestamp
     }
 
-    /*
-    type={expandIndex == index ? NewButtonType.alpha : NewButtonType.gray}
-                    color={iFast ? MainColorType.fast : MainColorType.sleep}
-    */
     return <NewModal
         title={props.title ?? '开始时间'}
         dismiss={props.dismiss}
@@ -175,11 +171,11 @@ export default function PostMomentTime(props: {
                 isYesterday: isYesterday
             })
         }}
-        themeColor={getThemeColor(health.mode)}>
+        themeColor={MainColorType.orange}>
         <Card>
             <ChooseDateTime title={null}
                 disable={false}
-                color={getThemeColor(health.mode)}
+                color={MainColorType.orange}
                 expand={!showDurationPicker}
                 choose={() => {
                     setShowDurationPicker(false)

+ 37 - 0
src/_record/components/picker_card.scss

@@ -0,0 +1,37 @@
+.picker_card_bg {
+    position: fixed;
+    z-index: 1000;
+    left: 0;
+    top: 0;
+    width: 100vw;
+    height: 100vh;
+    background-color: rgba($color: #000000, $alpha: 0.9);
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+}
+
+.picker_card {
+    width: 698px;
+    height: 816px;
+    background-color: #fff;
+    position: relative;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    border-radius: 84px;
+}
+
+.picker_card_close {
+    position: absolute;
+    left: 56px;
+    top: 56px;
+    width: 72px;
+    height: 72px;
+    border-radius: 36px;
+    background-color: rgba($color: #000000, $alpha: 0.05);
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}

+ 50 - 0
src/_record/components/picker_card.tsx

@@ -0,0 +1,50 @@
+import { View } from "@tarojs/components";
+import './picker_card.scss'
+import NewButton, { NewButtonType } from "@/_health/base/new_button";
+import { rpxToPx } from "@/utils/tools";
+import { MainColorType } from "@/context/themes/color";
+import { IconClose } from "@/components/basic/Icons";
+import NewDurationPicker, { DurationPickerType } from "@/_health/base/new_durationpicker";
+import { useState } from "react";
+import NewDateTimePicker from "@/_health/base/new_date_time_picker";
+import dayjs from "dayjs";
+
+export default function PickerCard(props: { onClose: any, onConfirm: any, type: string, value: any }) {
+    const [value, setValue] = useState(props.value)
+    return <View className="picker_card_bg">
+        <View className="picker_card">
+            <View className="picker_card_close" onClick={props.onClose}>
+                <IconClose color="#000" width={rpxToPx(32)} height={rpxToPx(32)} />
+            </View>
+            <View className="h50 bold" style={{ marginTop: rpxToPx(120) }}>时间</View>
+            <View style={{ height: 50 }}></View>
+            <View style={{height:rpxToPx(360)}}>
+            {
+                props.type == 'duration' && <NewDurationPicker type={DurationPickerType.normal} value={props.value} onChange={(e) => {
+                    setValue(e)
+                }} />
+            }
+            {
+                props.type == 'datetime' && <NewDateTimePicker date={dayjs(props.value).format('YYYY-MM-DD')} count={1} time={dayjs(props.value).format('HH:mm')}
+                    minTimestamp={new Date(props.value).getTime() - 24 * 3600 * 1000}
+                    maxTimestamp={new Date().getTime()}
+                    onChange={(e) => {
+                        var dt = new Date(`${e[0]}T${e[1]}:00`)
+                        setValue(dt.getTime())
+                    }} color={MainColorType.orange} />
+            }
+            </View>
+            <View style={{ height: rpxToPx(60) }} />
+            <NewButton
+                type={NewButtonType.fill}
+                width={rpxToPx(678)}
+                height={rpxToPx(96)}
+                color={MainColorType.orange}
+                title="确定"
+                onClick={() => {
+                    props.onConfirm(value)
+                }}
+            />
+        </View>
+    </View>
+}

+ 54 - 13
src/_record/components/ring_progress.tsx

@@ -13,6 +13,9 @@ export default function RingProgress(props: {
     height?: number;
     extra?: any;
     count?: number;
+    shareBg?: any;
+    shareCover?: any;
+    isCompleted?: boolean;
 }) {
     const canvasId = props.canvasId ?? new Date().getTime() + ''
     const info = Taro.getWindowInfo ? Taro.getWindowInfo() : Taro.getSystemInfoSync()
@@ -22,8 +25,8 @@ export default function RingProgress(props: {
     const canvasRef = useRef(null);
 
 
-    const canvasWidth = props.width ?? 200
-    const canvasHeight = props.height ?? 200
+    const canvasWidth = props.width ?? 450
+    const canvasHeight = props.height ?? 360
     const scale = props.scale ?? 1
 
     useEffect(() => {
@@ -73,13 +76,15 @@ export default function RingProgress(props: {
         // 设置画布尺寸
 
 
+        if (props.shareBg) {
+            const grd = ctx.createLinearGradient(0, 0, 0, canvasHeight);
+            grd.addColorStop(0, props.shareBg[0])
+            grd.addColorStop(1, props.shareBg[1])
+            ctx.fillStyle = grd;
+            ctx.fillRect(0, 0, canvasWidth, canvasHeight)
+        }
 
 
-        // const grd = ctx.createLinearGradient(0, 0, 0, canvasHeight);
-        // grd.addColorStop(0, '#F0CABF')
-        // grd.addColorStop(1, '#E1CDEE')
-        // ctx.fillStyle = grd;
-        // ctx.fillRect(0, 0, canvasWidth, canvasHeight)
 
         ctx.beginPath();
         ctx.arc(canvasWidth / 2.0, canvasHeight / 2.0, props.radius, 0, 2 * Math.PI);
@@ -90,7 +95,7 @@ export default function RingProgress(props: {
 
         if (props.target) {
             ctx.beginPath();
-            ctx.arc(canvasWidth / 2.0, canvasHeight / 2.0, props.radius, props.target.start, props.target.duration);
+            ctx.arc(canvasWidth / 2.0, canvasHeight / 2.0, props.radius, props.target.start, props.target.start + Math.max(props.target.duration, 0.01));
             ctx.lineWidth = props.target.width;
             ctx.strokeStyle = props.target.color;
             ctx.lineCap = 'round'; // 设置为圆角
@@ -99,7 +104,7 @@ export default function RingProgress(props: {
 
         if (props.real) {
             ctx.beginPath();
-            ctx.arc(canvasWidth / 2.0, canvasHeight / 2.0, props.radius, props.real.start, props.real.duration);
+            ctx.arc(canvasWidth / 2.0, canvasHeight / 2.0, props.radius, props.real.start, props.real.start + Math.max(props.real.duration, 0.01));
             ctx.lineWidth = props.real.width;
             ctx.strokeStyle = props.real.color;
             ctx.lineCap = 'round'; // 设置为圆角
@@ -124,7 +129,7 @@ export default function RingProgress(props: {
         // // 重置混合模式
         // ctx.globalCompositeOperation = 'source-over'
 
-        if (true) {
+        if (!props.isCompleted) {
             var time = new Date();
             var seconds = time.getHours() * 3600 + time.getMinutes() * 60 + time.getSeconds();
             // seconds += props.currentDot.offset! * 60
@@ -161,22 +166,58 @@ export default function RingProgress(props: {
                 ctx.font = `bold ${12}px sans-serif`
                 ctx.fillStyle = '#000'
                 ctx.textAlign = 'center'
-                ctx.fillText(header, 200, 110);
+                ctx.fillText(header, 225, 110);
             }
             if (value) {
                 ctx.font = `bold ${36}px sans-serif`
                 ctx.fillStyle = '#000'
                 ctx.textAlign = 'center'
-                ctx.fillText(value, 200, 164);
+                ctx.fillText(value, 225, 164);
             }
             if (footer) {
                 ctx.font = `bold ${15}px sans-serif`
                 ctx.fillStyle = color
                 ctx.textAlign = 'center'
-                ctx.fillText(footer, 200, 195);
+                ctx.fillText(footer, 225, 195);
             }
         }
 
+        if (props.isCompleted) {
+            if (canvas) {
+                const img1 = canvas.createImage(); // 创建图像对象
+                img1.src = global.checkImg
+                img1.onload = () => {
+                    ctx.drawImage(img1, 162, 30, 200, 170);
+                    ctx.stroke();
+                    if (props.shareCover && canvas) {
+                        save()
+                    }
+                }
+            }
+
+        }
+        else {
+            if (props.shareCover && canvas) {
+                save()
+            }
+        }
+
+
+
+
+    }
+
+    function save() {
+        Taro.canvasToTempFilePath({
+            canvas: canvas,
+            success: (res) => {
+                console.log('图片保存成功:', res.tempFilePath);
+                props.shareCover(res.tempFilePath)
+            },
+            fail: (err) => {
+                console.error('转为图片失败:', err);
+            }
+        });
     }
 
     return <Canvas canvasId={canvasId} id={canvasId} className="canvas" type="2d"

+ 1 - 8
src/_record/pages/log_record.scss

@@ -2,14 +2,7 @@
 //     background: linear-gradient(to bottom, #F0CABF, #E1CDEE)
 // }
 
-.main_bg {
-    position: fixed;
-    left: 0;
-    top: 0;
-    width: 100vw;
-    height: 100vh;
-    z-index: -1;
-}
+
 
 .navi_bar {
     position: fixed;

+ 93 - 80
src/_record/pages/log_record.tsx

@@ -14,12 +14,11 @@ import NewButton, { NewButtonType } from "@/_health/base/new_button";
 import dayjs from "dayjs";
 import { TimeFormatter } from "@/utils/time_format";
 import { useSelector } from "react-redux";
-import { addUserTag, createMoment, updateMoment, userTags } from "@/services/health";
+import { addEvents, addUserTag, createMoment, updateMoment, userTags } from "@/services/health";
 import PostMomentTime from "@/_health/components/post_moment_time";
 
 let useRoute;
 let useNavigation;
-let scenario = '';
 if (process.env.TARO_ENV == 'rn') {
     useRoute = require("@react-navigation/native").useRoute
     useNavigation = require("@react-navigation/native").useNavigation
@@ -30,8 +29,10 @@ export default function LogRecord() {
     const scale = '?x-oss-process=image/format,jpg/resize,w_400'
     const long = useSelector((state: any) => state.long);
     const health = useSelector((state: any) => state.health);
+    const record = useSelector((state: any) => state.record);
     const [pics, setPics] = useState<any>([])
     const [title, setTitle] = useState('')
+    const [chooseTitle, setChooseTitle] = useState('')
     const [desc, setDesc] = useState('')
     const [step, setStep] = useState(0)
     const { t } = useTranslation()
@@ -43,6 +44,8 @@ export default function LogRecord() {
     const [posting, setPosting] = useState(false)
     const [showTimePicker, setShowTimePicker] = useState(false)
 
+    const [tags, setTags] = useState<any>([])
+
 
 
     let router
@@ -58,26 +61,26 @@ export default function LogRecord() {
         router = useRouter()
     }
 
-    const { event_id, is_temp, schedule_id } = router.params
+    const { event_id, is_temp, schedule_id,scenario } = router.params
 
     const moment = router.params.moment ? JSON.parse(router.params.moment) : null
 
     const window = router.params.window ?? health.mode
 
     useEffect(() => {
-        console.log('sss')
+        global.set_time = new Date().getTime()
         getTags()
     }, [])
 
-    function getTags(){
-        userTags({scenario:'EAT'}).then(res=>{
-
+    function getTags() {
+        userTags({ scenario: scenario }).then(res => {
+            setTags((res as any).tags)
         })
     }
 
-    function addTag(){
-        addUserTag({scenario:'EAT',title:title}).then(res=>{
-
+    function addTag() {
+        addUserTag({ scenario: scenario, title: title }).then(res => {
+            getTags()
         })
     }
 
@@ -224,23 +227,18 @@ export default function LogRecord() {
             edit()
             return
         }
-        // var str = selDate + ' ' + time + ':' + dayjs(enterTimestmap).format('ss')
-        // console.log('系统时间',new Date())
-        // console.log('提交日期格式',str)
-        // console.log('转成日期',new Date(str))
-
-        // var date = new Date(selDate + 'T' + time + ':' + dayjs(enterTimestmap).format('ss'))
         var date = TimeFormatter.stringToDate(selDate, time)
         date.setMilliseconds(new Date(enterTimestmap).getMilliseconds())
 
 
         var params: any = {
-            schedule_id: schedule_id,
-            title: title,
-            description: desc,
-            start: {
-                date: dayjs(date.getTime()).format('YYYYMMDD'),
-                timestamp: date.getTime()
+            scenario: scenario, //ACTIVITY
+            type: 'POINT',
+            sub_type: scenario,
+            title: chooseTitle,
+
+            time: {
+                start_timestamp: date.getTime()
             }
         }
 
@@ -248,6 +246,9 @@ export default function LogRecord() {
             params.join_key = router.params.join_id
         }
 
+        var moment:any = {
+            description: desc,
+        }
         if (pics.length > 0) {
             var picList: any = []
             pics.map((item) => {
@@ -260,68 +261,60 @@ export default function LogRecord() {
                     format: item.format
                 })
             })
-            params.media = picList
+            moment.media = picList
         }
+        params.moment = moment
 
 
-        // 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
-        }
 
-        if (is_temp) {
-            params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
-        }
-        params.op_page = window == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
-        // if (moment.target && moment.target.duration) {
-        //     params.duration = durationT//moment.target.duration
+        // if (event_id && event_id != 'undefined') {
+        //     params.event_id = event_id
         // }
 
+        // if (is_temp) {
+        //     params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
+        // }
+        // params.op_page = window == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
 
 
         params.extra = {
             set_time: global.set_time ? global.set_time : new Date().getTime(),
             confirm_time: new Date().getTime()
         }
-        console.log('打卡提交数据', params)
+        // console.log('打卡提交数据', params)
         if (posting) return
         setPosting(true)
-        createMoment(params).then(res => {
-            // setTimeout(() => {
-            setPosting(false)
-            Taro.eventCenter.trigger('refreshMoments', '')
-            // }, 1000)
-
-            if (process.env.TARO_ENV == 'weapp') {
-                // Taro.navigateBack();
-                Taro.redirectTo({
-                    url: '/_health/pages/post_result?data=' + JSON.stringify(res)
-                })
-                // Taro.navigateTo({
-                //     url:'/_health/pages/post_result?data=' + JSON.stringify(res)
-                // })
-            }
-
-            Taro.disableAlertBeforeUnload({
-
+        addEvents(params).then(res => {
+            Taro.showToast({
+                title: '成功',
+                icon: 'success'
             })
-
-            global.refreshWindow()
-            global.refreshHistory()
-
-            if (global.postMomentSuccess) {
-                global.postMomentSuccess()
-            }
-        }).catch(e => {
-            debugger
-            setPosting(false)
         })
+        // createMoment(params).then(res => {
+        //     // setTimeout(() => {
+        //     setPosting(false)
+        //     Taro.eventCenter.trigger('refreshMoments', '')
+        //     // }, 1000)
+
+        //     if (process.env.TARO_ENV == 'weapp') {
+        //         // Taro.navigateBack();
+        //         Taro.redirectTo({
+        //             url: '/_health/pages/post_result?data=' + JSON.stringify(res)
+        //         })
+        //         // Taro.navigateTo({
+        //         //     url:'/_health/pages/post_result?data=' + JSON.stringify(res)
+        //         // })
+        //     }
+
+        //     // global.refreshWindow()
+        //     // global.refreshHistory()
+
+        //     // if (global.postMomentSuccess) {
+        //     //     global.postMomentSuccess()
+        //     // }
+        // }).catch(e => {
+        //     setPosting(false)
+        // })
     }
 
     function edit() {
@@ -331,9 +324,8 @@ export default function LogRecord() {
             schedule_id: schedule_id,
             title: title,
             description: desc,
-            start: {
-                date: dayjs(date.getTime()).format('YYYYMMDD'),
-                timestamp: date.getTime()
+            time: {
+                start_timestamp: date.getTime()
             }
         }
 
@@ -409,8 +401,21 @@ export default function LogRecord() {
         }
     }
 
+    function getBackground() {
+        var time = record.time
+        if (!time) return '#fff'
+        const { background_colors } = time
+        if (!background_colors) {
+            return '#fff'
+        }
+        else if (background_colors.length == 1) {
+            return background_colors[0]
+        }
+        return `linear-gradient(to bottom, ${background_colors[0]}, ${background_colors[1]})`
+    }
+
     return <View style={{ position: 'relative' }}>
-        <View className="main_bg" style={{ background: 'linear-gradient(to bottom, #F0CABF, #E1CDEE)' }} />
+        <View className="main_bg" style={{ background: getBackground() }} />
         <View className="navi_bar" style={{ height: navigationBarHeight }}>
             <View style={{
                 position: 'absolute',
@@ -440,11 +445,17 @@ export default function LogRecord() {
         {
             step == 0 && <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginTop: rpxToPx(152) }}>
                 <Image src={require('@assets/_health/eat.png')} style={{ width: rpxToPx(96), height: rpxToPx(96) }} />
-                <View className="h50 bold">选择打卡的餐次</View>
+                <View className="h50 bold">选择打卡的{scenario=='MEAL'?'餐次':'活动'}</View>
                 <View className="operate_bg">
-                    <View className="operate_item h30 bold" onClick={() => {
-                        setStep(2)
-                    }}>早餐</View>
+                    {
+                        tags.map((item, index) => {
+                            return <View key={index} className="operate_item h30 bold" onClick={() => {
+                                setChooseTitle(item.title)
+                                setStep(2)
+                            }}>{item.title}</View>
+                        })
+                    }
+
                     <View className="operate_item h30 bold" onClick={() => {
                         setStep(1)
                     }}>自定义</View>
@@ -465,7 +476,9 @@ export default function LogRecord() {
                         <View className={title.length == 0 ? 'form_cancel form_confirm h30 bold' : 'form_cancel h30 bold'}
                             onClick={() => {
                                 if (title.length == 0) return
+                                setChooseTitle(title)
                                 setStep(2)
+                                addTag()
                             }}
                         >确定</View>
                     </View>
@@ -474,11 +487,11 @@ export default function LogRecord() {
         }
         {
             step == 2 && <View>
-                <View style={{ display: 'flex', flexDirection: 'row' }} onClick={()=>{
+                <View style={{ display: 'flex', flexDirection: 'row' }} onClick={() => {
                     setStep(0)
                 }}>
                     <View className="sel_tag h34 bold">
-                        {title}
+                        {chooseTitle}
                         <View style={{ width: rpxToPx(6) }} />
                         <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
                     </View>
@@ -530,12 +543,12 @@ export default function LogRecord() {
                 <View className="time_view" onClick={() => {
                     setShowTimePicker(true)
                 }}>
-                    
+
                     <View className="h30" style={{ opacity: 0.3 }}>时间</View>
                     <View style={{ flex: 1 }} />
                     <View className="h30" style={{ opacity: 0.3 }}>{getDate() + time}</View>
                     <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
-                    <View className="border_footer_line" style={{left:rpxToPx(48)}}/>
+                    <View className="border_footer_line" style={{ left: rpxToPx(48) }} />
                 </View>
                 <View style={{ flex: 1 }} />
 

+ 36 - 3
src/_record/pages/time_record.scss

@@ -1,6 +1,3 @@
-page {
-    background: linear-gradient(to bottom, #F0CABF, #E1CDEE)
-}
 
 .navi_bar {
     position: fixed;
@@ -77,4 +74,40 @@ page {
     flex-direction: column;
     align-items: center;
     width: 320px;
+}
+
+.share_icon{
+    position: absolute;
+    right: 48px;
+    top:48px;
+}
+
+.share_bg{
+    position: fixed;
+    left: 0;
+    top: 0;
+    width: 100vw;
+    height: 100vh;
+    z-index: 100;
+    background: linear-gradient(180deg, #000000 0%, #1A1A1A 100%);
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+}
+
+.share_card{
+    width: 698px;
+    height: 932px;
+    display: flex;
+    border-radius: 84px;
+    margin-bottom: 26px;
+    flex-direction: column;
+    overflow: hidden;
+    align-items: center;
+}
+
+.share_canvas{
+    position: absolute;
+    top:-1000px;
 }

+ 602 - 126
src/_record/pages/time_record.tsx

@@ -1,6 +1,6 @@
 import { View, Image } from "@tarojs/components";
 import './time_record.scss'
-import Taro from "@tarojs/taro";
+import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
 import { rpxToPx } from "@/utils/tools";
 import { MainColorType } from "@/context/themes/color";
 import NewButton, { NewButtonType } from "@/_health/base/new_button";
@@ -9,26 +9,212 @@ import NewDateTimePicker from "@/_health/base/new_date_time_picker";
 import dayjs from "dayjs";
 import RingProgress from "../components/ring_progress";
 import NewDurationPicker, { DurationPickerType } from "@/_health/base/new_durationpicker";
-import { IconArrow } from "@/components/basic/Icons";
+import { IconArrow, IconClose } from "@/components/basic/Icons";
+import { useSelector } from "react-redux";
+import { TimeFormatter } from "@/utils/time_format";
+import { addEvents } from "@/services/health";
+import Modal from "@/components/layout/Modal.weapp";
+import { getDurationArc, getStartArc } from "@/features/health/hooks/health_hooks";
+import ShareBtn from "@/components/basic/ShareBtn";
+import PickerCard from "../components/picker_card";
 
 let timer
+let useRoute;
+let useNavigation;
+if (process.env.TARO_ENV == 'rn') {
+    useRoute = require("@react-navigation/native").useRoute
+    useNavigation = require("@react-navigation/native").useNavigation
+}
+
 export default function TimeRecord() {
     const systemInfo: any = Taro.getWindowInfo ? Taro.getWindowInfo() : Taro.getSystemInfoSync();
     const navigationBarHeight = systemInfo.statusBarHeight + 44;
-
+    const record = useSelector((state: any) => state.record);
     const [enterTime] = useState(new Date().getTime())
 
     const [showDatePicker, setShowDatePicker] = useState(false)
     const [showDurationPicker, setShowDurationPicker] = useState(false)
+    const [showEndDatePicker, setShowEndDatePicker] = useState(false)
     const [count, setCount] = useState(0)
+    const [status, setStatus] = useState('WFS')
+    const [info, setInfo] = useState<any>(null)
+    const [loaded, setLoaded] = useState(false)
+    const [showHighlight, setShowHighlight] = useState(false)
+    const [showShare, setShowShare] = useState(false)
+    const [shareUrl, setShareUrl] = useState('')
+
+    let router
+    let navigation;
+    if (useNavigation) {
+        navigation = useNavigation()
+    }
+
+    if (process.env.TARO_ENV == 'rn') {
+        router = useRoute()
+    }
+    else {
+        router = useRouter()
+    }
+
+    const { scenario } = router.params
+
+    if (process.env.TARO_ENV == 'weapp') {
+        useShareAppMessage((e) => {
+            return {
+                title: '分享标题',
+                path: 'pages/clock/Clock',
+                imageUrl: shareUrl
+            }
+        })
+    }
+
 
     useEffect(() => {
-        timer = setInterval(() => { setCount(count => count + 1) }, 1000)
+        const { events } = record
+        events.map((item) => {
+            if (item.scenario == scenario) {
+                setInfo(item)
+                setStatus(item.status)
+                setLoaded(true)
+            }
+        })
+        downloadFile()
+        timer = setInterval(() => {
+            if (showDatePicker || showEndDatePicker || showDurationPicker) return
+            setCount(count => count + 1)
+        }, 1000)
         return () => {
             clearInterval(timer)
         }
     }, [])
 
+    function downloadFile() {
+        Taro.downloadFile({
+            url: 'https://background-pictures.oss-cn-beijing.aliyuncs.com/inapp/checkmark.png',
+            success: (res) => {
+                if (res.statusCode === 200) {
+                    global.checkImg = res.tempFilePath
+
+                } else {
+                }
+            },
+            fail: (err) => {
+            }
+        });
+    }
+
+    function tapClock() {
+        if (status == 'WFS')
+            setShowDurationPicker(true)
+    }
+
+    function start() {
+        // var date = TimeFormatter.stringToDate(selDate, time)
+        // date.setMilliseconds(new Date(enterTimestmap).getMilliseconds())
+
+
+        var params: any = {
+            scenario: scenario, //ACTIVITY
+            type: 'INTERVAL',
+            sub_type: scenario,
+
+            time: {
+                start_timestamp: new Date().getTime(),
+                duration: info.time.duration
+            }
+        }
+
+        if (router.params.join_id) {
+            params.join_key = router.params.join_id
+        }
+
+
+
+
+        // if (event_id && event_id != 'undefined') {
+        //     params.event_id = event_id
+        // }
+
+        // if (is_temp) {
+        //     params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
+        // }
+        // params.op_page = window == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
+
+
+        params.extra = {
+            set_time: global.set_time ? global.set_time : new Date().getTime(),
+            confirm_time: new Date().getTime()
+        }
+        // console.log('打卡提交数据', params)
+        // if (posting) return
+        // setPosting(true)
+        addEvents(params).then(res => {
+            Taro.eventCenter.trigger('refreshClockIndex')
+            setShowHighlight(true)
+            setTimeout(() => {
+                setShowHighlight(false)
+            }, 3000)
+            setInfo((res as any).data)
+            setStatus((res as any).data.status)
+            // Taro.showToast({
+            //     title: '成功',
+            //     icon: 'success'
+            // })
+        })
+    }
+
+    function end() {
+        var params: any = {
+            scenario: scenario, //ACTIVITY
+            type: 'INTERVAL',
+            sub_type: scenario,
+
+            time: {
+                end_timestamp: new Date().getTime()
+            }
+        }
+
+        if (router.params.join_id) {
+            params.join_key = router.params.join_id
+        }
+
+
+        params.extra = {
+            set_time: global.set_time ? global.set_time : new Date().getTime(),
+            confirm_time: new Date().getTime()
+        }
+        addEvents(params).then(res => {
+            setShowHighlight(true)
+            setTimeout(() => {
+                setShowHighlight(false)
+            }, 3000)
+            Taro.eventCenter.trigger('refreshClockIndex')
+            setInfo((res as any).data)
+            setStatus((res as any).data.status)
+            setShareUrl('')
+            // Taro.showToast({
+            //     title: '成功',
+            //     icon: 'success'
+            // })
+        })
+    }
+
+    function update(params) {
+        var data: any = {
+            id: info.id,
+            time: {
+                ...params
+            }
+        }
+        addEvents(data).then(res => {
+            Taro.eventCenter.trigger('refreshClockIndex')
+            setInfo((res as any).data)
+            setShowDatePicker(false)
+            setShowDurationPicker(false)
+            setShowEndDatePicker(false)
+        })
+    }
+
 
     function tapStart() {
         setShowDatePicker(true)
@@ -38,142 +224,432 @@ export default function TimeRecord() {
         setShowDurationPicker(true)
     }
 
-    return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
-        <View className="navi_bar" style={{ height: navigationBarHeight }}>
-            <View style={{
-                position: 'absolute',
-                left: 0,
-                right: 0,
-                bottom: 0,
-                height: 44,
-                display: 'flex',
-                alignItems: 'center',
-                justifyContent: 'center'
-            }}>
-                <Image src={require('@assets/_health/navi_back.png')} style={{
-                    position: 'absolute',
-                    width: rpxToPx(92),
-                    height: rpxToPx(64),
-                    left: 0,
-                    top: 22 - rpxToPx(32)
-                }}
-                    onClick={() => {
-                        Taro.navigateBack()
-                    }}
-                />
-                <View className="h36 bold">upcoming fast</View>
-            </View>
+    function ringExtra() {
+        if (status == 'WFS') {
+            const count = info.time.duration / 1000
+            var str = TimeFormatter.formateDurationBySeconds(count)
+
+            return {
+                header: '',
+                value: str,
+                footer: 'Edit',
+                color: MainColorType.orange
+            }
+        }
+        var percent = 100 * (new Date().getTime() - info.time.start_timestamp) / info.time.duration
+        percent = parseInt(percent + '')
+        return {
+            header: '',
+            value: TimeFormatter.countdown(info.time.start_timestamp),
+            footer: `ELAPSED ${percent}%`,
+            color: MainColorType.g02
+        }
+    }
+
+    function getBackground() {
+        var time = record.time
+        if (!time) return '#fff'
+        const { background_colors } = time
+        if (!background_colors) {
+            return '#fff'
+        }
+        else if (background_colors.length == 1) {
+            return background_colors[0]
+        }
+        return `linear-gradient(to bottom, ${background_colors[0]}, ${background_colors[1]})`
+    }
+    if (!loaded) {
+        return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
+            <View className="main_bg" style={{ background: getBackground() }} />
         </View>
-        <View style={{ height: navigationBarHeight }} />
-        <View className="progress_card">
-            <View onClick={() => {
-                setShowDurationPicker(true)
-            }}>
-                <RingProgress width={400} height={320}
-                    radius={125} canvasId="helloworld"
-                    //scale={0.75}
-                    count={count}
-                    bgRing={{
-                        color: 'rgba(255,255,255,0.25)',
-                        width: 35
-                    }}
-                    target={{
-                        color: 'rgba(255,255,255,0.5)',
-                        width: 35,
-                        start: 0,
-                        duration: 3 / 4 * Math.PI
-                    }}
-                    real={{
-                        color: MainColorType.orange,
-                        width: 35,
-                        start: 0,
-                        duration: 2 / 4 * Math.PI
-                    }}
-                    extra={{
-                        header: 'GOAL',
-                        value: dayjs().format('HH:mm:ss'),
-                        footer: 'Edit',
-                        color: MainColorType.orange
-                    }}
-                />
-            </View>
-            <View className="operate_content">
-                <View className="operate_item">
-                    <View className="g02 h24">STARTED</View>
-                    <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>今天 13:54</View>
-                    <View className="h30 bold" style={{ color: MainColorType.orange }}>Edit Start</View>
+    }
+
+    function doneComponent() {
+        if (status == 'DONE') {
+            return <View className="share_bg" style={{ justifyContent: 'flex-start' }}>
+                {
+                    shareUrl.length == 0 && <View className="share_canvas"><RingProgress
+                        radius={125} canvasId="helloworld_share2"
+                        //scale={0.75}
+                        count={count}
+                        bgRing={{
+                            color: 'rgba(255,255,255,1)',
+                            width: 35
+                        }}
+                        real={{
+                            color: MainColorType.orange,
+                            width: 5,
+                            start: getStartArc(info.time.start_timestamp),
+                            duration: getDurationArc(info.time.start_timestamp, info.time.end_timestamp)
+                        }}
+                        extra={ringExtra()}
+                        isCompleted
+                        shareCover={
+                            url => {
+                                setShareUrl(url)
+                            }
+                        }
+                    /></View>
+                }
+
+                <View className="navi_bar" style={{ height: navigationBarHeight }}>
+                    <View style={{
+                        position: 'absolute',
+                        left: 0,
+                        right: 0,
+                        bottom: 0,
+                        height: 44,
+                        display: 'flex',
+                        alignItems: 'center',
+                        justifyContent: 'center'
+                    }}>
+                        <View style={{
+                            position: 'absolute',
+                            width: rpxToPx(92),
+                            height: rpxToPx(64),
+                            left: 22,
+                            top: 22 - rpxToPx(32)
+                        }}
+                            onClick={() => {
+                                Taro.navigateBack()
+                            }}>
+                            <IconClose color="#fff" width={rpxToPx(64)} height={rpxToPx(64)} />
+                        </View>
+                    </View>
+
                 </View>
-                <View className="operate_item">
-                    <View className="g02 h24">STARTED</View>
-                    <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>今天 13:54</View>
-                    <View className="h30 bold" style={{ color: MainColorType.orange }}>Edit Start</View>
+                <View className="share_card" style={{ background: MainColorType.orange, marginTop: rpxToPx(26) + navigationBarHeight }}>
+                    {
+                        shareUrl.length > 0 ? <Image src={shareUrl} style={{ width: rpxToPx(900), height: rpxToPx(720) }} /> :
+                            <View style={{ width: rpxToPx(900), height: rpxToPx(720), backgroundColor: MainColorType.g02 }} />
+                    }
+                    {
+                        <View className="operate_content" style={{ marginTop: rpxToPx(40) }}>
+                            <View className="operate_item" onClick={() => {
+                                setShowDatePicker(true)
+                            }}>
+                                <View className="g02 h24">STARTED</View>
+                                <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.start_timestamp, true)}</View>
+                                <View className="h30 bold" style={{ color: MainColorType.white }}>Edit Start</View>
+                            </View>
+                            <View className="operate_item" onClick={() => {
+                                setShowEndDatePicker(true)
+                            }}>
+                                <View className="g02 h24">FINISHED</View>
+                                <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.end_timestamp, true)}</View>
+                                <View className="h30 bold" style={{ color: MainColorType.white }}>Edit Finish</View>
+                            </View>
+                        </View>
+                    }
                 </View>
-            </View>
-            <NewButton
-                type={NewButtonType.fill}
-                title="Start fasting"
-                width={rpxToPx(490)}
-                height={rpxToPx(96)}
-                color={MainColorType.orange}
-            />
-        </View>
+                <ShareBtn>
+                    <NewButton
+                        type={NewButtonType.fill}
+                        color={MainColorType.success}
+                        width={rpxToPx(698)}
+                        height={rpxToPx(108)}
+                        title="Send to friends"
+                    />
+                </ShareBtn>
 
-        <View className="eat_card" onClick={() => {
-            Taro.redirectTo({
-                url: './log_record'
-            })
-        }}>
-            <View className="h30 bold">Or share your meals</View>
-            <View className="h24 g02" style={{ marginTop: rpxToPx(12) }}>if you haven't started fasting yet</View>
-            <View className="eat_card_arrow">
-                <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
             </View>
-        </View>
+        }
+    }
 
-        <View className="eat_card" style={{height:rpxToPx(120)}} onClick={() => {
-            Taro.redirectTo({
-                url: './log_record'
-            })
-        }}>
-            <View className="h24 g02" style={{ marginTop: rpxToPx(12) }}>How are you feeling?</View>
-            <View className="eat_card_arrow">
-                <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
+    function render() {
+
+        return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
+            <View className="main_bg" style={{ background: getBackground() }} />
+            <View className="navi_bar" style={{ height: navigationBarHeight }}>
+                <View style={{
+                    position: 'absolute',
+                    left: 0,
+                    right: 0,
+                    bottom: 0,
+                    height: 44,
+                    display: 'flex',
+                    alignItems: 'center',
+                    justifyContent: 'center'
+                }}>
+                    <Image src={require('@assets/_health/navi_back.png')} style={{
+                        position: 'absolute',
+                        width: rpxToPx(92),
+                        height: rpxToPx(64),
+                        left: 0,
+                        top: 22 - rpxToPx(32)
+                    }}
+                        onClick={() => {
+                            Taro.navigateBack()
+                        }}
+                    />
+                    <View className="h36 bold">upcoming fast</View>
+                </View>
             </View>
-        </View>
+            <View style={{ height: navigationBarHeight }} />
+            <View className="progress_card">
+                <View onClick={() => {
+                    tapClock()
+                    // setShowDurationPicker(true)
+                }}>
+                    <RingProgress
+                        radius={125} canvasId="helloworld"
+                        //scale={0.75}
+                        count={count}
+                        bgRing={{
+                            color: 'rgba(255,255,255,0.25)',
+                            width: 35
+                        }}
+                        target={{
+                            color: 'rgba(255,255,255,0.5)',
+                            width: 35,
+                            start: status == 'WFS' ? getStartArc(new Date().getTime()) : getStartArc(info.time.start_timestamp),
+                            duration: status == 'WFS' ? getDurationArc(new Date().getTime(), new Date().getTime() + info.time.duration) : getDurationArc(info.time.start_timestamp, info.time.start_timestamp + info.time.duration)
+                        }}
+                        real={status == 'WFS' ? null : {
+                            color: MainColorType.orange,
+                            width: 35,
+                            start: getStartArc(info.time.start_timestamp),
+                            duration: getDurationArc(info.time.start_timestamp, new Date().getTime())
+                        }}
+                        extra={ringExtra()}
+                    />
+                </View>
+                {
+                    status == 'OG' && <View className="operate_content">
+                        <View className="operate_item" onClick={() => {
+                            setShowDatePicker(true)
+                        }}>
+                            <View className="g02 h24">STARTED</View>
+                            <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.start_timestamp, true)}</View>
+                            <View className="h30 bold" style={{ color: MainColorType.orange }}>Edit Start</View>
+                        </View>
+                        <View className="operate_item" onClick={() => {
+                            setShowDurationPicker(true)
+                        }}>
+                            <View className="g02 h24">{TimeFormatter.formateDurationBySeconds(info.time.duration / 1000)} Goal</View>
+                            <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.target_end_timestamp, true)}</View>
+                            <View className="h30 bold" style={{ color: MainColorType.orange }}>Edit Goal</View>
+                        </View>
+                    </View>
+                }
+                {
+                    status == 'WFS' && <NewButton
+                        type={NewButtonType.fill}
+                        title="Start fasting"
+                        width={rpxToPx(490)}
+                        height={rpxToPx(96)}
+                        color={MainColorType.orange}
+                        onClick={start}
+                    />
+                }
+
+                {
+                    status == 'OG' && <NewButton
+                        type={NewButtonType.fill}
+                        title="End fasting"
+                        width={rpxToPx(490)}
+                        height={rpxToPx(96)}
+                        color={MainColorType.orange}
+                        onClick={end}
+                    />
+                }
+                {
+                    status == 'OG' && <View className="share_icon">
+                        <Image onClick={() => {
+                            setShareUrl('')
+                            setShowShare(true)
+                        }} src={require('@assets/_health/wechat.png')} style={{
+                            width: rpxToPx(72),
+                            height: rpxToPx(72)
+                        }} />
+                    </View>
+                }
 
 
-        <View className="time_card_bg">
-            <View className="time_card" onClick={tapStart}>
-                <View className="h30" style={{ opacity: 0.4 }}>Start</View>
-                <View className="h44 bold" style={{ marginTop: rpxToPx(12) }}>10:00</View>
-            </View>
-            <View className="time_card" onClick={tapGoal}>
-                <View className="h30" style={{ opacity: 0.4 }}>Goal</View>
-                <View className="h44 bold" style={{ marginTop: rpxToPx(12) }}>10:00</View>
             </View>
+            {
+                status == 'WFS' && <View className="eat_card" onClick={() => {
+                    Taro.redirectTo({
+                        url: `./log_record?scenario=${scenario == 'FAST' ? 'MEAL' : 'ACTIVITY'}`
+                    })
+                }}>
+                    <View className="h30 bold">Or share your meals</View>
+                    <View className="h24 g02" style={{ marginTop: rpxToPx(12) }}>if you haven't started fasting yet</View>
+                    <View className="eat_card_arrow">
+                        <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
+                    </View>
+                </View>
+            }
+
+            {
+                status == 'OG' && <View className="eat_card" style={{ height: rpxToPx(120) }} onClick={() => {
+                    Taro.redirectTo({
+                        url: `./log_record?scenario=${scenario == 'FAST' ? 'MEAL' : 'ACTIVITY'}`
+                    })
+                }}>
+                    <View className="h24 g02" style={{ marginTop: rpxToPx(12) }}>How are you feeling?</View>
+                    <View className="eat_card_arrow">
+                        <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
+                    </View>
+                </View>
+            }
+
+
+            {/* {
+            showDurationPicker && <Modal
+                testInfo={null}
+                dismiss={() => {
+                    setShowDurationPicker(false)
+                }}
+                confirm={() => { }}>
+                {
+                    <NewDurationPicker type={DurationPickerType.normal} value={info.time.duration} onChange={(e) => {
+                        console.log(e)
+                        var obj = JSON.parse(JSON.stringify(info))
+                        obj.time.duration = e
+                        setInfo(obj)
+                    }} />
+                }
+            </Modal>
+        } */}
+            {
+                showShare && <View className="share_bg">
+                    {
+                        shareUrl == '' && <View className="share_canvas">
+                            <RingProgress
+                                radius={125} canvasId="helloworld_share"
+                                //scale={0.75}
+                                count={count}
+                                bgRing={{
+                                    color: 'rgba(255,255,255,0.25)',
+                                    width: 35
+                                }}
+                                target={{
+                                    color: 'rgba(255,255,255,0.5)',
+                                    width: 35,
+                                    start: status == 'WFS' ? getStartArc(new Date().getTime()) : getStartArc(info.time.start_timestamp),
+                                    duration: status == 'WFS' ? getDurationArc(new Date().getTime(), new Date().getTime() + info.time.duration) : getDurationArc(info.time.start_timestamp, info.time.start_timestamp + info.time.duration)
+                                }}
+                                real={status == 'WFS' ? null : {
+                                    color: MainColorType.orange,
+                                    width: 35,
+                                    start: getStartArc(info.time.start_timestamp),
+                                    duration: getDurationArc(info.time.start_timestamp, new Date().getTime())
+                                }}
+                                extra={ringExtra()}
+                                shareBg={[record.time.background_colors[0], record.time.background_colors[1]]}
+                                shareCover={
+                                    url => {
+                                        setShareUrl(url)
+                                    }
+                                }
+                            />
+                        </View>
+                    }
+                    <View className="navi_bar" style={{ height: navigationBarHeight }}>
+                        <View style={{
+                            position: 'absolute',
+                            left: 0,
+                            right: 0,
+                            bottom: 0,
+                            height: 44,
+                            display: 'flex',
+                            alignItems: 'center',
+                            justifyContent: 'center'
+                        }}>
+                            <View style={{
+                                position: 'absolute',
+                                width: rpxToPx(92),
+                                height: rpxToPx(64),
+                                left: 22,
+                                top: 22 - rpxToPx(32)
+                            }}
+                                onClick={() => {
+                                    setShowShare(false)
+                                }}>
+                                <IconClose color="#fff" width={rpxToPx(64)} height={rpxToPx(64)} />
+                            </View>
+                        </View>
+                    </View>
+                    <View className="share_card" style={{ background: record.time.background_colors[1] }}>
+                        {
+                            shareUrl.length > 0 ? <Image src={shareUrl} style={{ width: rpxToPx(900), height: rpxToPx(720) }} /> :
+                                <View style={{ width: rpxToPx(900), height: rpxToPx(720), backgroundColor: MainColorType.g02 }} />
+                        }
+                        {
+                            status == 'OG' && <View className="operate_content" style={{ marginTop: rpxToPx(40) }}>
+                                <View className="operate_item">
+                                    <View className="g02 h24">STARTED</View>
+                                    <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.start_timestamp, true)}</View>
+                                </View>
+                                <View className="operate_item">
+                                    <View className="g02 h24">{TimeFormatter.formateDurationBySeconds(info.time.duration / 1000)} Goal</View>
+                                    <View className="h44 bold" style={{ marginTop: rpxToPx(8), marginBottom: rpxToPx(8) }}>{TimeFormatter.dateTimeFormate(info.time.target_end_timestamp, true)}</View>
+                                </View>
+                            </View>
+                        }
+                    </View>
+                    <ShareBtn>
+                        <NewButton
+                            type={NewButtonType.fill}
+                            color={MainColorType.success}
+                            width={rpxToPx(698)}
+                            height={rpxToPx(108)}
+                            title="Send to friends"
+                        />
+                    </ShareBtn>
+                </View>
+            }
         </View>
-        <NewButton
-            onClick={() => { }}
-            type={NewButtonType.fill}
-            color={MainColorType.orange}
-            width={rpxToPx(669)}
-            height={rpxToPx(96)}
-            title="开始断食"
-        />
+    }
+    return <View>
+        {
+            status == 'DONE' ? doneComponent() : render()
+        }
+        {
+            showDatePicker && <PickerCard onClose={() => { setShowDatePicker(false) }}
+                value={info.time.start_timestamp}
+                type="datetime"
+                onConfirm={(e) => {
+                    update({
+                        start_timestamp: e
+                    })
+                    console.log(e)
+                    // var obj = JSON.parse(JSON.stringify(info))
+                    // obj.time.duration = e
+                    // setInfo(obj)
+                }}
+            />
+        }
         {
-            showDatePicker && <NewDateTimePicker date={dayjs().format('YYYY-MM-DD')} count={1} time={dayjs().format('HH:mm')}
-                minTimestamp={new Date().getTime() - 24 * 3600 * 1000}
-                maxTimestamp={new Date().getTime()}
-                onChange={(e) => {
-                    // if (props.dateChange)
-                    //     props.dateChange(e[0])
-                    // if (props.timeChange)
-                    //     props.timeChange(e[1])
-                    // props.change(e)
-                }} color={MainColorType.orange} />
+            showEndDatePicker && <PickerCard onClose={() => { setShowDatePicker(false) }}
+                value={info.time.end_timestamp}
+                type="datetime"
+                onConfirm={(e) => {
+                    update({
+                        end_timestamp: e
+                    })
+                    console.log(e)
+                    // var obj = JSON.parse(JSON.stringify(info))
+                    // obj.time.duration = e
+                    // setInfo(obj)
+                }}
+            />
         }
         {
-            showDurationPicker && <NewDurationPicker type={DurationPickerType.normal} />
+            showDurationPicker && <PickerCard onClose={() => { setShowDurationPicker(false) }}
+                value={info.time.duration}
+                type="duration"
+                onConfirm={(e) => {
+                    var obj = JSON.parse(JSON.stringify(info))
+                    obj.time.duration = e
+                    setInfo(obj)
+                    if (status == 'WFS') return
+                    update({
+                        duration: e
+                    })
+                }}
+            />
         }
     </View>
 }

+ 9 - 0
src/app.scss

@@ -10,6 +10,15 @@ page {
     }
 }
 
+.main_bg {
+    position: fixed;
+    left: 0;
+    top: 0;
+    width: 100vw;
+    height: 100vh;
+    z-index: -1;
+}
+
 .container {
     display: flex;
     flex-direction: column;

+ 2 - 2
src/components/navigation/TabBar.tsx

@@ -65,10 +65,10 @@ export default function Component(props: { index: number }) {
             <Image className='tabbar-icon' src={selIndex == 4 ? require('@assets/_health/social_sel.png') : require('@assets/_health/social.png')} />
             <View className={selIndex == 4 ? 'tabbar-item-text-sel' : 'tabbar-item-text'}>{t('health.moments')}</View>
         </View>
-        <View className={selIndex == 1 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(1)}>
+        {/* <View className={selIndex == 1 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(1)}>
             <Image className='tabbar-icon' src={selIndex == 1 ? require('@assets/_health/compass_sel.png') : require('@assets/_health/compass.png')} />
             <View className={selIndex == 1 ? 'tabbar-item-text-sel' : 'tabbar-item-text'}>{t('health.discover')}</View>
-        </View>
+        </View> */}
         <View className={selIndex == 3 ? 'tabbar-item tabbar-item-sel' : 'tabbar-item'} onClick={() => switchTab(3)}>
             <Image className='tabbar-icon' src={selIndex == 3 ? require('@assets/_health/user_sel.png') : require('@assets/_health/user.png')} />
             <View className={selIndex == 3 ? 'tabbar-item-text-sel' : 'tabbar-item-text'}>{t('health.me')}</View>

+ 11 - 2
src/pages/clock/ClockIndex.scss

@@ -1,5 +1,14 @@
-page {
-    background: linear-gradient(to bottom, #F0CABF, #E1CDEE)
+// page {
+//     background: linear-gradient(to bottom, #F0CABF, #E1CDEE)
+// }
+
+.main_bg{
+    position: fixed;
+    left: 0;
+    top: 0;
+    width: 100vw;
+    height: 100vh;
+    z-index: -1;
 }
 
 .operate_panel {

+ 98 - 15
src/pages/clock/ClockIndex.tsx

@@ -5,12 +5,22 @@ import TabBar from "@/components/navigation/TabBar";
 import { IconNext } from "@/components/basic/Icons";
 import { rpxToPx } from "@/utils/tools";
 import { useDispatch, useSelector } from "react-redux";
-import { useEffect } from "react";
+import { useEffect, useState } from "react";
 import { homeInfo } from "@/services/health";
+import dayjs from "dayjs";
+import { setEvents, setTimeData } from "@/store/record";
+import { TimeFormatter } from "@/utils/time_format";
+import { getInfo } from "@/services/user";
+import Taro from "@tarojs/taro";
 
-
+var timer
 export default function ClockIndex() {
     const user = useSelector((state: any) => state.user);
+    const record = useSelector((state: any) => state.record);
+    const [loaded, setLoaded] = useState(false)
+    const [home, setHome] = useState<any>(null)
+    const [count, setCount] = useState(0)
+    const [currentTimeData, setCurrentTimeData] = useState<any>(null)
     const dispatch = useDispatch();
     global.dispatch = dispatch;
 
@@ -37,10 +47,38 @@ export default function ClockIndex() {
     }]
 
     useEffect(() => {
-        homeInfo().then(res => {
+        getHomeData()
+    }, [user.isLogin])
 
+    function getHomeData() {
+        homeInfo().then(res => {
+            setLoaded(true)
+            setHome(res)
+            setCount(1)
+            dispatch(setEvents((res as any).events))
         })
-    }, [user.isLogin])
+    }
+
+    useEffect(() => {
+        getInfo()
+        Taro.eventCenter.on('refreshClockIndex', getHomeData)
+        timer = setInterval(() => {
+            setCount(pre => pre + 1)
+        }, 1000)
+        return () => {
+            clearInterval(timer)
+            Taro.eventCenter.off('refreshClockIndex')
+        }
+    }, [])
+    useEffect(() => {
+        getTime()
+    }, [count])
+
+    useEffect(() => {
+        if (currentTimeData) {
+            dispatch(setTimeData(currentTimeData))
+        }
+    }, [currentTimeData])
 
     function tapItem(index) {
         if (!user.isLogin) {
@@ -50,11 +88,11 @@ export default function ClockIndex() {
         switch (index) {
             case 0:
             case 1:
-                jumpPage('/_record/pages/log_record')
+                jumpPage(`/_record/pages/log_record?scenario=${index == 0 ? 'MEAL' : 'ACTIVITY'}`)
                 break;
             case 2:
             case 3:
-                jumpPage('/_record/pages/time_record')
+                jumpPage(`/_record/pages/time_record?scenario=${index == 2 ? 'FAST' : 'SLEEP'}`)
                 break;
             case 4:
                 jumpPage('/_record/pages/metric_record')
@@ -62,17 +100,61 @@ export default function ClockIndex() {
         }
     }
 
-
-    return <View><View
-        onClick={() => {
-            if (!user.isLogin) {
-                jumpPage('/_account/pages/ChooseAuth')
+    function getTime() {
+        if (!home) return
+        var now = dayjs().format('HH:mm')
+        for (var i = 0; i < home.time_messages.length; i++) {
+            var obj = home.time_messages[i]
+            if (now >= obj.start_time && now < obj.end_time) {
+                setCurrentTimeData(obj)
                 return
             }
-            jumpPage('/_record/pages/time_record')
-        }}
-        style={{ height: 100, width: 100, backgroundColor: 'pink' }}>demo</View>
-        <View className="h60 bold" style={{ marginLeft: rpxToPx(52) }}>早上好</View>
+        }
+        setCurrentTimeData(home.time_messages[home.time_messages.length - 1])
+    }
+
+    function getBackground() {
+        var time = record.time
+        if (!time) return '#fff'
+        const { background_colors } = time
+        if (!background_colors) {
+            return '#fff'
+        }
+        else if (background_colors.length == 1) {
+            return background_colors[0]
+        }
+        return `linear-gradient(to bottom, ${background_colors[0]}, ${background_colors[1]})`
+    }
+
+    function itemTime(item) {
+        if (item.scenario == 'FAST') {
+            if (home.events && home.events.length > 0 && home.events[0].status == 'OG') {
+                return TimeFormatter.countdown(home.events[0].time.start_timestamp)
+            }
+        }
+        else if (item.scenario == 'SLEEP') {
+            if (home.events && home.events.length > 0 && home.events[1].status == 'OG') {
+                return TimeFormatter.countdown(home.events[1].time.start_timestamp)
+            }
+        }
+        return ''
+    }
+
+    if (!loaded) return <View />
+
+
+    return <View>
+        <View className="main_bg" style={{ background: getBackground() }} />
+        <View
+            onClick={() => {
+                if (!user.isLogin) {
+                    jumpPage('/_account/pages/ChooseAuth')
+                    return
+                }
+                jumpPage('/_record/pages/time_record')
+            }}
+            style={{ height: 100, width: 100, opacity: 0 }}>demo</View>
+        <View className="h60 bold" style={{ marginLeft: rpxToPx(52) }}>{record.time ? record.time.greeting : ''}</View>
         <View className="h44 bold" style={{ marginLeft: rpxToPx(52), marginTop: rpxToPx(66), marginBottom: rpxToPx(58) }}>打卡</View>
         <View className="operate_panel">
             {
@@ -82,6 +164,7 @@ export default function ClockIndex() {
 
                     }}>
                         <View className="h36 bold">{item.title}</View>
+                        <View className="h50 bold">{itemTime(item)}</View>
                         <View style={{ flex: 1 }} />
                         <View style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
                             <IconNext width={rpxToPx(36)} color="#000" />

+ 1 - 1
src/pages/moment/moment_detail_share.tsx

@@ -123,7 +123,7 @@ export default function MomentDetailShare(props: { user: any, canvas_id?: string
                 const width = 292 * dpr; // 矩形宽度
                 const height = 72 * dpr; // 矩形高度
                 const radius = 18 * dpr; // 圆角半径
-
+ 
                 // 绘制带圆角的矩形
 
                 ctx.beginPath();

+ 31 - 0
src/store/record.tsx

@@ -0,0 +1,31 @@
+
+import { createSlice } from "@reduxjs/toolkit";
+
+
+interface RecordState {
+    time:any,
+    events:any,
+}
+
+const initialState: RecordState = {
+    time:null,
+    events:null,
+}
+
+const recordSlice = createSlice({
+    name: 'access',
+    initialState,
+    reducers: {
+
+        setTimeData(state, action) {
+            state.time = action.payload
+        },
+        setEvents(state, action) {
+            state.events = action.payload
+        },
+
+    }
+});
+
+export default recordSlice.reducer;
+export const { setTimeData,setEvents } = recordSlice.actions;

+ 3 - 1
src/store/store.tsx

@@ -15,6 +15,7 @@ import targetReducer from './set_target';
 import accessReducer from './access';
 import healthReducer from './health'
 import longReducer from './long'
+import recordReducer from './record'
 
 const store = configureStore({
   reducer: {
@@ -35,7 +36,8 @@ const store = configureStore({
     target: targetReducer,
     access: accessReducer,
     health: healthReducer,
-    long: longReducer
+    long: longReducer,
+    record: recordReducer,
   },
 });
 

+ 20 - 19
src/utils/time_format.ts

@@ -3,9 +3,16 @@ const timezone = require('dayjs/plugin/timezone')
 import Taro from '@tarojs/taro'
 import dayjs from 'dayjs'
 import { kIsIOS } from './tools'
+import isToday from 'dayjs/plugin/isToday';
+import isTomorrow from 'dayjs/plugin/isTomorrow'
+import isYesterday from 'dayjs/plugin/isYesterday'
+
 
 dayjs.extend(utc)
 dayjs.extend(timezone)
+dayjs.extend(isToday);
+dayjs.extend(isTomorrow);
+dayjs.extend(isYesterday);
 
 
 
@@ -74,9 +81,7 @@ export class TimeFormatter {
 
     // 判断是否是今天
     if (
-      inputDate.getDate() === currentDate.getDate() &&
-      inputDate.getMonth() === currentDate.getMonth() &&
-      inputDate.getFullYear() === currentDate.getFullYear()
+      dayjs(timestamp).isToday()
     ) {
       return `${TimeFormatter.getTodayUnit()} ${TimeFormatter.formatTime(inputDate)}`;
     }
@@ -86,9 +91,7 @@ export class TimeFormatter {
     yesterday.setDate(currentDate.getDate() - 1);
 
     if (
-      inputDate.getDate() === yesterday.getDate() &&
-      inputDate.getMonth() === yesterday.getMonth() &&
-      inputDate.getFullYear() === yesterday.getFullYear()
+      dayjs(timestamp).isYesterday()
     ) {
       return `${TimeFormatter.getYesterdayUnit()} ${TimeFormatter.formatTime(inputDate)}`;
     }
@@ -98,9 +101,7 @@ export class TimeFormatter {
     tomorrow.setDate(currentDate.getDate() + 1);
 
     if (
-      inputDate.getDate() === tomorrow.getDate() &&
-      inputDate.getMonth() === tomorrow.getMonth() &&
-      inputDate.getFullYear() === tomorrow.getFullYear()
+      dayjs(timestamp).isTomorrow()
     ) {
       return `${TimeFormatter.getTomorrowUnit()} ${TimeFormatter.formatTime(inputDate)}`;
     }
@@ -117,29 +118,29 @@ export class TimeFormatter {
 
     // 判断是否是今天
     if (
-      inputDate.getDate() === currentDate.getDate() &&
-      inputDate.getMonth() === currentDate.getMonth() &&
-      inputDate.getFullYear() === currentDate.getFullYear()
+      dayjs(timestamp).isToday()
     ) {
       // if (global.language == 'en') {
       //   return `${TimeFormatter.padZero(inputDate.getHours())}:${TimeFormatter.padZero(inputDate.getMinutes())} ${TimeFormatter.getTodayUnit()}`
       // }
-      return `${TimeFormatter.getTodayUnit()} ${TimeFormatter.padZero(inputDate.getHours())}:${TimeFormatter.padZero(inputDate.getMinutes())}`;
+      return `${TimeFormatter.getTodayUnit()} ${dayjs(timestamp).format('HH:mm')}`;
     }
 
     // 判断是否是昨天
-    const yesterday = new Date();
-    yesterday.setDate(currentDate.getDate() - 1);
 
     if (
-      inputDate.getDate() === yesterday.getDate() &&
-      inputDate.getMonth() === yesterday.getMonth() &&
-      inputDate.getFullYear() === yesterday.getFullYear()
+      dayjs(timestamp).isYesterday()
     ) {
       // if (global.language == 'en') {
       //   return `${TimeFormatter.padZero(inputDate.getHours())}:${TimeFormatter.padZero(inputDate.getMinutes())} ${TimeFormatter.getYesterdayUnit()}`;
       // }
-      return `${TimeFormatter.getYesterdayUnit()} ${TimeFormatter.padZero(inputDate.getHours())}:${TimeFormatter.padZero(inputDate.getMinutes())}`;
+      return `${TimeFormatter.getYesterdayUnit()} ${dayjs(timestamp).format('HH:mm')}`;
+    }
+
+    if (
+      dayjs(timestamp).isTomorrow()
+    ) {
+      return `${TimeFormatter.getTomorrowUnit()} ${dayjs(timestamp).format('HH:mm')}`;
     }
 
     // if (global.language == 'en') {