|
|
@@ -1,7 +1,7 @@
|
|
|
import { View, Text, Image, PageContainer } from '@tarojs/components'
|
|
|
import './IndexConsole.scss'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
-import { useSelector } from 'react-redux';
|
|
|
+import { useDispatch, useSelector } from 'react-redux';
|
|
|
import { endFast, endSleep, startFast, startSleep } from "../actions/TrackTimeActions";
|
|
|
import { jumpPage } from '../hooks/Common';
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
|
@@ -11,6 +11,9 @@ import { getColor, getTimePickerTitle } from '../hooks/Console';
|
|
|
import { rpxToPx, vibrate } from '@/utils/tools';
|
|
|
import { TimeFormatter } from '@/utils/time_format';
|
|
|
import Modal from '@/components/layout/Modal.weapp';
|
|
|
+import Taro, { useDidShow } from '@tarojs/taro';
|
|
|
+import { wxPubFollow } from '@/services/permission';
|
|
|
+import { setWXFollow } from '@/store/permission';
|
|
|
|
|
|
let useNavigation;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
@@ -25,9 +28,10 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
const [fastDuration, setFastDuration] = useState<number>(0);
|
|
|
const [sleepDuration, setSleepDuration] = useState<number>(0);
|
|
|
const [expand, setExpand] = useState(false);
|
|
|
-
|
|
|
+ const permission = useSelector((state: any) => state.permission);
|
|
|
+ const common = useSelector((state: any) => state.common);
|
|
|
const [firstEnter, setFirstEnter] = useState(true);
|
|
|
-
|
|
|
+ const dispatch = useDispatch();
|
|
|
const [showTimeoutPicker, setShowTimeoutPicker] = useState(false)
|
|
|
|
|
|
// const [fastPickerValue, setFastPickerValue] = useState([0, 0])
|
|
|
@@ -40,6 +44,12 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
navigation = useNavigation()
|
|
|
}
|
|
|
|
|
|
+ useDidShow(() => {
|
|
|
+ wxPubFollow({ force_refresh: true }).then(res => {
|
|
|
+ dispatch(setWXFollow((res as any).wx_pub_followed));
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (currentRecord.fast) {
|
|
|
var fastCount = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
|
|
|
@@ -104,7 +114,7 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
operateType = 'endSleep'
|
|
|
global.pauseIndexTimer = true
|
|
|
|
|
|
-
|
|
|
+
|
|
|
var last_check_time = props.record.current_record.last_real_check_time
|
|
|
if (last_check_time + 24 * 3600 * 1000 <= new Date().getTime()) {
|
|
|
setShowTimeoutPicker(true)
|
|
|
@@ -131,8 +141,8 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
|
|
|
var last_check_time = props.record.current_record.last_real_check_time
|
|
|
|
|
|
- if (last_check_time + 24 * 3600 * 1000 <= new Date().getTime()||
|
|
|
- props.record.current_record.fast.real_check_time+24 * 3600 * 1000 <= new Date().getTime()) {
|
|
|
+ if (last_check_time + 24 * 3600 * 1000 <= new Date().getTime() ||
|
|
|
+ props.record.current_record.fast.real_check_time + 24 * 3600 * 1000 <= new Date().getTime()) {
|
|
|
setShowTimeoutPicker(true)
|
|
|
return
|
|
|
}
|
|
|
@@ -154,10 +164,19 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
|
|
|
var title = getTimePickerTitle(currentRecord, t, operateType == 'endFast')
|
|
|
var color = getColor(currentRecord, operateType == 'endFast')
|
|
|
+ var duration = 0
|
|
|
+ if (operateType == 'startFast' && currentRecord.fast) {
|
|
|
+ duration = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
|
|
|
+ }
|
|
|
+ if (operateType == 'startSleep' && currentRecord.sleep) {
|
|
|
+ duration = currentRecord.sleep.target_end_time - currentRecord.sleep.target_start_time
|
|
|
+ }
|
|
|
return <View className="modal_content">
|
|
|
<LimitPickers ref={limitPickerRef} limit={limit} limitDay={8}
|
|
|
themeColor={color}
|
|
|
title={title}
|
|
|
+ showEndTime={operateType == 'startFast' || operateType == 'startSleep'}
|
|
|
+ duration={duration}
|
|
|
onCancel={hidePicker} onChange={(e) => {
|
|
|
pickerConfirm(e)
|
|
|
global.pauseIndexTimer = false
|
|
|
@@ -173,7 +192,7 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
var targetTime = props.record.current_record.fast.target_end_time
|
|
|
if (props.record.current_record.status == 'ONGOING3') {
|
|
|
limit = 0
|
|
|
- targetTime = props.record.current_record.sleep.real_end_time+60*1000
|
|
|
+ targetTime = props.record.current_record.sleep.real_end_time + 60 * 1000
|
|
|
}
|
|
|
return <View className="modal_content">
|
|
|
<LimitTimeoutPickers ref={limitPickerRef} limit={limit} limitDay={7}
|
|
|
@@ -220,39 +239,102 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
global.pauseIndexTimer = false
|
|
|
}
|
|
|
|
|
|
- function pickerConfirm(t: number) {
|
|
|
+
|
|
|
+ function followWxPub() {
|
|
|
+ const resource = common.resources.filter((item: any) => {
|
|
|
+ return item.code == 'follow_wx_pub'
|
|
|
+ })
|
|
|
+
|
|
|
+ jumpPage('/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url)
|
|
|
+ }
|
|
|
+
|
|
|
+ function pickerConfirm(t1: number) {
|
|
|
// hidePicker()
|
|
|
- var date = new Date(t)
|
|
|
+ var date = new Date(t1)
|
|
|
var setDate = new Date(global.set_time);
|
|
|
date.setMilliseconds(setDate.getMilliseconds());
|
|
|
date.setSeconds(setDate.getSeconds());
|
|
|
|
|
|
- t = date.getTime();
|
|
|
+ t1 = date.getTime();
|
|
|
|
|
|
switch (operateType) {
|
|
|
case 'startFast':
|
|
|
- startFast(t, fastDuration).then(res => {
|
|
|
+ startFast(t1, fastDuration).then(res => {
|
|
|
global.indexPageRefresh()
|
|
|
setFirstEnter(false)
|
|
|
hidePicker()
|
|
|
+
|
|
|
+ if (permission.wxPubFollow) {
|
|
|
+ Taro.showModal({
|
|
|
+ title: t('feature.track_time_duration.reminders.fast_end_title'),
|
|
|
+ content:
|
|
|
+ t('feature.track_time_duration.reminders.enable_post_fast_content',
|
|
|
+ { time: TimeFormatter.dateDescription(t1 + fastDuration, true) + ' ' + TimeFormatter.timeDescription(t1 + fastDuration) }
|
|
|
+ ),
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.ok')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Taro.showModal({
|
|
|
+ title: t('feature.track_time_duration.reminders.fast_end_title'),
|
|
|
+ content: t('feature.track_time_duration.reminders.post_fast_content',
|
|
|
+ { time: TimeFormatter.dateDescription(t1 + fastDuration, true) + ' ' + TimeFormatter.timeDescription(t1 + fastDuration) }
|
|
|
+ ),
|
|
|
+ cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ followWxPub()
|
|
|
+ } else if (res.cancel) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
break
|
|
|
case 'startSleep':
|
|
|
- startSleep(t, sleepDuration).then(res => {
|
|
|
+ startSleep(t1, sleepDuration).then(res => {
|
|
|
global.indexPageRefresh()
|
|
|
setFirstEnter(false)
|
|
|
hidePicker()
|
|
|
+
|
|
|
+ if (permission.wxPubFollow) {
|
|
|
+ Taro.showModal({
|
|
|
+ title: t('feature.track_time_duration.reminders.wake_title'),
|
|
|
+ content:
|
|
|
+ t('feature.track_time_duration.reminders.enable_post_sleep_content',
|
|
|
+ { time: TimeFormatter.dateDescription(t1 + sleepDuration, true) + ' ' + TimeFormatter.timeDescription(t1 + sleepDuration) }),
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.ok')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Taro.showModal({
|
|
|
+ title: t('feature.track_time_duration.reminders.wake_title'),
|
|
|
+ content: t('feature.track_time_duration.reminders.post_sleep_content',
|
|
|
+ { time: TimeFormatter.dateDescription(t1 + sleepDuration, true) + ' ' + TimeFormatter.timeDescription(t1 + sleepDuration) }),
|
|
|
+ cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ followWxPub()
|
|
|
+ } else if (res.cancel) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
break
|
|
|
case 'endSleep':
|
|
|
- endSleep(t).then(res => {
|
|
|
+ endSleep(t1).then(res => {
|
|
|
global.indexPageRefresh()
|
|
|
setFirstEnter(false)
|
|
|
hidePicker()
|
|
|
})
|
|
|
break
|
|
|
case 'endFast':
|
|
|
- endFast(t).then(res => {
|
|
|
+ endFast(t1).then(res => {
|
|
|
global.indexPageRefresh()
|
|
|
setFirstEnter(false)
|
|
|
hidePicker()
|
|
|
@@ -300,10 +382,10 @@ export default function IndexConsole(props: { record: any }) {
|
|
|
}}
|
|
|
onClick={() => { alert('b') }}
|
|
|
onClickOverlay={() => { alert('a') }}
|
|
|
- onAfterLeave={() => {
|
|
|
+ onAfterLeave={() => {
|
|
|
hidePicker()
|
|
|
// setShowTimeoutPicker(false)
|
|
|
- }}
|
|
|
+ }}
|
|
|
show={showTimeoutPicker} round={true} overlay={true} position='bottom'
|
|
|
>
|
|
|
{
|