Leon 1 rok pred
rodič
commit
66ad4b4f5e

+ 19 - 12
src/_health/pages/add_moment.tsx

@@ -45,6 +45,7 @@ export default function AddMoment() {
     const [durationT, setDurationT] = useState(0)
     const dispatch = useDispatch()
     const health = useSelector((state: any) => state.health);
+    const long = useSelector((state: any) => state.long);
     const [timestamp, setTimestamp] = useState(new Date().getTime())
     const [showTimePicker, setShowTimePicker] = useState(false)
     const [isYesterday, setIsYesterday] = useState(false)
@@ -79,10 +80,12 @@ export default function AddMoment() {
 
     const moment = router.params.moment ? JSON.parse(router.params.moment) : null
 
+    const window = router.params.window??health.mode
+
     useEffect(() => {
         global.set_time = new Date().getTime()
-
-        getLabelsEvent({ window: health.mode, use: is_temp ? 'ONE_RECORD' : '' }).then(res => {
+        
+        getLabelsEvent({ window: window, use: is_temp ? 'ONE_RECORD' : '' }).then(res => {
             setLabels((res as any).labels)
             if (is_temp && title == '') {
                 // setShowTitlePicker(true)
@@ -252,9 +255,9 @@ export default function AddMoment() {
         }
 
         if (is_temp) {
-            params.event = health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
+            params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
         }
-        params.op_page = health.mode == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
+        params.op_page = window == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
         // if (moment.target && moment.target.duration) {
         //     params.duration = durationT//moment.target.duration
         // }
@@ -345,7 +348,7 @@ export default function AddMoment() {
         }
 
         if (is_temp) {
-            params.event = health.mode == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
+            params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
         }
 
         if (durationT) {
@@ -556,9 +559,9 @@ export default function AddMoment() {
                 setShowTimePicker(true)
             }}>
                 <StatusIndicator type={StatusType.big}
-                    color={getThemeColor(health.mode)}
+                    color={getThemeColor(window)}
                     fontSize={rpxToPx(30)}
-                    fontColor={getThemeColor(health.mode)}
+                    fontColor={getThemeColor(window)}
                     text={getDate() + time}>
                     <IconCheck color="#fff" width={rpxToPx(24)} height={24} />
                 </StatusIndicator>
@@ -567,8 +570,8 @@ export default function AddMoment() {
             </View>
 
             <Input className="meal_name" value={title}
-                placeholder={health.mode == 'EAT' ? t('health.meal_label') : t('health.activity_title')}
-                style={{ caretColor: getThemeColor(health.mode) }}
+                placeholder={window == 'EAT' ? t('health.meal_label') : t('health.activity_title')}
+                style={{ caretColor: getThemeColor(window) }}
                 // cursorColor='#ff0000'
                 onFocus={() => {
                     setTitleFocus(true)
@@ -597,7 +600,7 @@ export default function AddMoment() {
                             labels.map((item, index) => {
                                 return <View className="add_page_tag_btn"
                                     style={{
-                                        backgroundColor: item.title == title ? getThemeColor(health.mode) : '#B2B2B21A',
+                                        backgroundColor: item.title == title ? getThemeColor(window) : '#B2B2B21A',
                                         color: item.title == title ? '#fff' : '#000'
                                     }}
                                     key={index} onClick={() => {
@@ -657,7 +660,7 @@ export default function AddMoment() {
                 }
             </View>
 
-            <View onClick={chooseLocation} style={{color:MainColorType.link}}>Choose Location</View>
+            {/* <View onClick={chooseLocation} style={{color:MainColorType.link}}>Choose Location</View> */}
 
             {/* <View className="form">
                 {
@@ -676,6 +679,10 @@ export default function AddMoment() {
 
             </View> */}
         </View>
+        <View style={{height:rpxToPx(24)}}/>
+        {
+            router.params.join_id && <FollowInfo user={long.follow}/>
+        }
 
         {/* <FollowInfo /> */}
 
@@ -684,7 +691,7 @@ export default function AddMoment() {
 
         <View className="main_footer"><NewButton
             type={NewButtonType.fill}
-            color={getThemeColor(health.mode)}
+            color={getThemeColor(window)}
             width={rpxToPx(646)}
             height={rpxToPx(96)}
             title={t('health.log_moment')}

+ 81 - 31
src/_health/pages/log_time.tsx

@@ -13,7 +13,7 @@ import { useRouter } from "@tarojs/taro";
 import Card from "../components/card";
 import { MainColorType } from "@/context/themes/color";
 import Taro from "@tarojs/taro";
-import { clockTimes, fastWithSleep } from "@/services/health";
+import { clockTimes, delRecord, fastWithSleep } from "@/services/health";
 import NewDurationPicker, { DurationPickerType } from "../base/new_durationpicker";
 import showAlert from "@/components/basic/Alert";
 import NewDatePicker, { NewDatePickerType } from "../base/new_date_picker";
@@ -22,6 +22,9 @@ import { TimeFormatter } from "@/utils/time_format";
 import StatusIndicator, { StatusType } from "../base/status_indicator";
 import { t } from "i18next";
 import FollowInfo from "@/_moment/components/follow_info";
+import showActionSheet from "@/components/basic/ActionSheet";
+import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
+import LongCard from "@/_moment/components/long_card";
 
 let useRoute;
 let useNavigation;
@@ -56,6 +59,7 @@ export default function LogTime() {
     const type = router.params.type
     const [data, setData] = useState<any>(null)
     const health = useSelector((state: any) => state.health);
+    const long = useSelector((state: any) => state.long);
     const [showGoal, setShowGoal] = useState(router.params.longfast)
     const tapIndex = router.params.index ?? 0
     const [longDuration, setLongDuration] = useState(24)
@@ -615,10 +619,6 @@ export default function LogTime() {
         }
 
 
-        console.log(requestId)
-
-
-
         if (posting) return
         setPosting(true)
         const url = onlyCheck ? '?only_check=true' : ''
@@ -627,6 +627,8 @@ export default function LogTime() {
                 setRequestId(new Date().getTime())
             }
 
+            Taro.eventCenter.trigger('refreshMoments', '')
+
             if ((res as any).result) {
                 setErrors([])
                 setConflicts([])
@@ -806,17 +808,45 @@ export default function LogTime() {
         }
     }
 
-    function cancelAlert(){
+    function moreOption(isNew: boolean) {
+        const { window,join_id } = router.params
+        showActionSheet({
+            title: '更多选项',
+            itemList: isNew ? ['开始新的打卡'] : [window == 'FAST' ? '添加断食结束' : '添加起床'],
+            success: (res) => {
+                if (res == 0) {
+                    if (isNew) {
+                        cancelAlert()
+                    }
+                    else {
+                        //jumpPage(`/_health/pages/log_time?type=home&index=${health.mode == 'FAST' ? 3 : 2}&single=${sceniaro.status == 'OG' ? 1 : 0}&is_start=0&window=${health.mode}&op_page=${health.mode == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`)
+                        jumpPage(`./log_time?hide_more=1&join_id=${join_id}&type=home&index=${window == 'FAST' ? 3 : 2}&single=0&is_start=0&window=${window}&op_page=${window == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`)
+                    }
+                }
+            }
+        })
+    }
+
+    function cancelAlert() {
         showAlert({
-            title:'放弃旧的,开始新的?',
-            content:'',
-            showCancel:true,
-            cancelText:'取消',
-            confirmText:'继续',
-            cancel:()=>{
+            title: '放弃旧的,开始新的?',
+            content: '',
+            showCancel: true,
+            cancelText: '取消',
+            confirmText: '继续',
+            cancel: () => {
                 console.log('cancel')
             },
-            confirm:()=>{
+            confirm: () => {
+                const { window,join_id } = router.params
+
+                delRecord({ ids: [getScenario(health.windows, window).window_id] }).then(res => {
+                    Taro.eventCenter.trigger('refreshMoments', '')
+                    global.refreshWindow()
+                    Taro.redirectTo({
+                        url:`./log_time?hide_more=1&join_id=${join_id}&index=${window == 'FAST' ? 0 : 1}&single=1&is_start=1&window=${window}&op_page=${window == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`
+                    })
+                })
                 console.log('confirm')
             }
         })
@@ -1160,24 +1190,44 @@ export default function LogTime() {
     }
 
     function joinContent() {
-        if (router.params.join_id) {
+        if (router.params.join_id && !router.params.hide_more) {
             const { index, window, is_start, single, join_status } = router.params
-            if (window == 'FAST') {
-                // if (index )
-                if (join_status == 'OG' && getScenario(health.windows, 'FAST').status == 'OG') {
-                    return <View onClick={cancelAlert} className="h26" style={{ color: MainColorType.link }}>更多选项</View>
-                }
-                else if (join_status == 'DONE' && getScenario(health.windows, 'FAST').status == 'WFS') {
-                    return <View className="h26" style={{ color: MainColorType.link }}>更多选项</View>
-                }
-            }
-            else {
-                if (join_status == 'OG' && getScenario(health.windows, 'SLEEP').status == 'OG') {
-                    return <View onClick={cancelAlert} className="h26" style={{ color: MainColorType.link }}>更多选项</View>
-                } else if (join_status == 'DONE' && getScenario(health.windows, 'SLEEP').status == 'WFS') {
-                    return <View className="h26" style={{ color: MainColorType.link }}>更多选项</View>
-                }
-            }
+            var status = getScenario(health.windows, window).status
+            return <View style={{ width: rpxToPx(400), height: rpxToPx(72), marginBottom: rpxToPx(24) }}>
+                <NewButton type={NewButtonType.link}
+                    width={rpxToPx(400)}
+                    height={rpxToPx(72)}
+                    title="更多选项"
+                    onClick={() => {
+                        moreOption(status == 'OG')
+                    }}
+                />
+            </View>
+            // return <View onClick={() => {
+            //     moreOption(status == 'OG')
+            // }} className="h26" style={{ color: MainColorType.link }}>更多选项</View>
+            // debugger
+            // if (window == 'FAST') {
+
+            //     // if (index )
+            //     if (join_status == 'OG' && getScenario(health.windows, window).status == 'OG') {
+            //         return <View onClick={()=>{
+            //             moreOption(true)
+            //         }} className="h26" style={{ color: MainColorType.link }}>更多选项</View>
+            //     }
+            //     else if (join_status == 'DONE' && getScenario(health.windows, 'FAST').status == 'WFS') {
+            //         return <View onClick={()=>{
+            //             moreOption(false)
+            //         }} className="h26" style={{ color: MainColorType.link }}>更多选项</View>
+            //     }
+            // }
+            // else {
+            //     if (join_status == 'OG' && getScenario(health.windows, 'SLEEP').status == 'OG') {
+            //         return <View onClick={cancelAlert} className="h26" style={{ color: MainColorType.link }}>更多选项</View>
+            //     } else if (join_status == 'DONE' && getScenario(health.windows, 'SLEEP').status == 'WFS') {
+            //         return <View className="h26" style={{ color: MainColorType.link }}>更多选项</View>
+            //     }
+            // }
         }
         return <View />
     }
@@ -1240,7 +1290,7 @@ export default function LogTime() {
             }}>{expectText()}</View>
         }
         {
-            router.params.join_id && <FollowInfo />
+            router.params.join_id && <FollowInfo user={long.follow}/>//<LongCard join={long.join} link={{}} hideJoin={true}/>//<FollowInfo />
         }
 
 

+ 19 - 18
src/_moment/components/follow_info.tsx

@@ -1,7 +1,8 @@
 import { rpxToPx } from "@/utils/tools";
 import { View, Text, Textarea, Image, Input, ScrollView } from "@tarojs/components";
 
-export default function FollowInfo() {
+export default function FollowInfo(props: { user: any }) {
+
     return <View style={{
         width: rpxToPx(698),
         height: rpxToPx(128),
@@ -11,26 +12,26 @@ export default function FollowInfo() {
         flexDirection: 'column',
         justifyContent: 'center',
         // marginTop:rpxToPx(36),
-        paddingLeft:rpxToPx(30),
-        boxSizing:'border-box',
-        marginLeft:rpxToPx(26)
+        paddingLeft: rpxToPx(30),
+        boxSizing: 'border-box',
+        marginLeft: rpxToPx(26)
     }}>
         <View className="h20 g02">接自</View>
-        <View style={{display:'flex',
-            flexDirection:'row',
-            alignItems:'center',
-            marginTop:rpxToPx(8)
+        <View style={{
+            display: 'flex',
+            flexDirection: 'row',
+            alignItems: 'center',
+            marginTop: rpxToPx(8)
         }}>
-            <View className="h26">用户A</View>
-            <View style={{
-                width:rpxToPx(36),
-                height:rpxToPx(36),
-                borderRadius:rpxToPx(18),
-                marginLeft:rpxToPx(8),
-                marginRight:rpxToPx(8),
-                backgroundColor:'pink'
-            }}/>
-            <View className="h26">跟卡</View>
+            <View className="h26">{props.user.nickname}</View>
+            <Image style={{
+                width: rpxToPx(36),
+                height: rpxToPx(36),
+                borderRadius: rpxToPx(18),
+                marginLeft: rpxToPx(8),
+                marginRight: rpxToPx(8),
+            }} src={props.user.avatar}/>
+            {/* <View className="h26">跟卡</View> */}
         </View>
     </View>
 }

+ 45 - 15
src/_moment/components/long_card.tsx

@@ -4,24 +4,28 @@ import './long_card.scss'
 import { rpxToPx } from "@/utils/tools";
 import ShareBtn from "@/components/basic/ShareBtn";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
-import { useSelector } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";
 import { getScenario } from "@/features/health/hooks/health_hooks";
+import { setFollow, setJoinData } from "@/store/long";
 
-export default function LongCard(props: { join?: any, link?: any }) {
-    const { status, key } = props.join
+export default function LongCard(props: { join?: any, link?: any, user?: any, hideJoin?: boolean }) {
+    const { status, key, from } = props.join
     const { window } = props.link
     const linkStatus = props.link.status
     const health = useSelector((state: any) => state.health);
+    const dispatch = useDispatch()
     let type = 0
     function join(e) {
         if (process.env.TARO_ENV == 'weapp') {
             e.stopPropagation()
         }
-        console.log(health)
-        debugger
+        if (props.user){
+            dispatch(setFollow(props.user))
+        }
+        dispatch(setJoinData(props.join))
 
         if (window == 'ACTIVE' || window == 'EAT') {
-            jumpPage(`/_health/pages/add_moment?join_id=${key}&is_temp=${true}`)
+            jumpPage(`/_health/pages/add_moment?join_id=${key}&is_temp=${true}&window=${window}`)
         }
         else {
             if (window == 'FAST') {
@@ -57,37 +61,63 @@ export default function LongCard(props: { join?: any, link?: any }) {
 
     function users() {
         return <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
-            <View className="long_avatar"></View>
+            {
+                props.join.users.map((item, index) => {
+                    return <Image className="long_avatar" style={{
+                        zIndex: 10 - index,
+                        marginLeft: index == 0 ? 0 : -rpxToPx(20)
+                    }} src={item.avatar} key={index} />
+                })
+            }
+            {/* <View className="long_avatar"></View> */}
             <View className="h26" style={{ marginLeft: rpxToPx(6) }}>跟卡</View>
         </View>
     }
 
-    if (type == 1)
+    if (from)
         return <View className="long_card_bg" style={{
             flexDirection: 'column',
             paddingTop: rpxToPx(18),
             paddingBottom: rpxToPx(18)
         }}>
             <View className="h20 g02" style={{ marginBottom: rpxToPx(6) }}>接自</View>
-            <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }}>
+            <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
+                <View className="h26">{from.nickname}</View>
                 {
                     users()
                 }
-                <View className="h26 bold" style={{ color: MainColorType.link }} onClick={join}>立即加入</View>
+                <View style={{ flex: 1 }} />
+                {
+                    status == 'JOIN' && <View className="h26 bold" style={{ color: MainColorType.link }} onClick={join}>立即加入</View>
+                }
+                {
+                    status == 'SHARE' && <ShareBtn onClick={share}>
+                        <View className="h26 bold" style={{ color: MainColorType.success }} >邀请好友加入</View>
+                    </ShareBtn>
+                }
+
             </View>
         </View>
     if (status == 'JOIN')
         return <View className="long_card_bg long_card_begin">
-            <View className="h26 g02">一起接龙打卡</View>
-            {/* {
-                users()
-            } */}
+            {
+                (!props.join || props.join.user_count == 0) && <View className="h26 g02">一起接龙打卡</View>
+            }
+
+            {
+                props.join && props.join.user_count > 0 && users()
+            }
             <View className="h26 bold" style={{ color: MainColorType.link }} onClick={join}>立即加入</View>
         </View>
 
     if (status == 'SHARE') {
         return <View className="long_card_bg long_card_begin">
-            <View className="h26 g02">一起接龙打卡 </View>
+            {
+                (!props.join || props.join.user_count == 0) && <View className="h26 g02">一起接龙打卡</View>
+            }
+            {
+                props.join && props.join.user_count > 0 && users()
+            }
             <ShareBtn onClick={share}>
                 <View className="h26 bold" style={{ color: MainColorType.success }} >邀请好友加入</View>
             </ShareBtn>

+ 1 - 0
src/features/trackTimeDuration/components/Rings.weapp.tsx

@@ -6,6 +6,7 @@ import { useEffect, useRef, useState } from "react";
 import { useSelector } from "react-redux";
 import '../../../app.scss'
 
+
 export type RingCommon = {
     useCase: string;
     status: string;

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

@@ -131,7 +131,7 @@ export default function MomentItem(props: { data: any }) {
                 />
             }
             {
-                join && <LongCard join={join} link={link}/>
+                join && <LongCard join={join} link={link} user={user}/>
             }
 
             <View style={{ padding: kSpace }} />

+ 6 - 0
src/pages/moment/moment_main.tsx

@@ -94,9 +94,11 @@ export default function MomentMain() {
 
         Taro.eventCenter.on('followUser', listenFollowUser)
         Taro.eventCenter.on('unfollowUser', listenUnfollowUser)
+        Taro.eventCenter.on('refreshMoments', refreshMoments)
         return () => {
             Taro.eventCenter.off('followUser')
             Taro.eventCenter.off('unfollowUser')
+            Taro.eventCenter.off('refreshMoments')
             clearInterval(timer)
         }
 
@@ -113,6 +115,10 @@ export default function MomentMain() {
         myFriends()
     }
 
+    function refreshMoments(e){
+        myFriends()
+    }
+
 
 
     useEffect(() => {

+ 34 - 0
src/store/long.tsx

@@ -0,0 +1,34 @@
+
+import { createSlice } from "@reduxjs/toolkit";
+
+
+interface LongState {
+    // scenario: null,
+    join: any,
+    follow:any,
+}
+
+const initialState: LongState = {
+    // scenario: null,
+    join: null,
+    follow:null
+}
+
+const longSlice = createSlice({
+    name: 'access',
+    initialState,
+    reducers: {
+
+        setJoinData(state, action) {
+            state.join = action.payload
+        },
+        setFollow(state, action) {
+            state.follow = action.payload
+        },
+
+
+    }
+});
+
+export default longSlice.reducer;
+export const { setJoinData,setFollow } = longSlice.actions;

+ 3 - 1
src/store/store.tsx

@@ -14,6 +14,7 @@ import ringReducer from './ring';
 import targetReducer from './set_target';
 import accessReducer from './access';
 import healthReducer from './health'
+import longReducer from './long'
 
 const store = configureStore({
   reducer: {
@@ -33,7 +34,8 @@ const store = configureStore({
     ring: ringReducer,
     target: targetReducer,
     access: accessReducer,
-    health: healthReducer
+    health: healthReducer,
+    long: longReducer
   },
 });