|
|
@@ -4,7 +4,7 @@ import IndexItem from '@/features/trackTimeDuration/components/IndexItem';
|
|
|
import Rings from "@/features/trackTimeDuration/components/Rings";
|
|
|
import './Index.scss'
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
-import { useDidHide, useDidShow, useReady } from "@tarojs/taro";
|
|
|
+import { useDidHide, useDidShow, useReady, useShareAppMessage } from "@tarojs/taro";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
import { getInfoSuccess } from "@/store/user";
|
|
|
import { clockHome, clockSummaryRecords, clockSummaryStats, getClockRecords, getClocks, getPlans } from "@/services/trackTimeDuration";
|
|
|
@@ -40,17 +40,22 @@ import { clearNightStore, showNight } from "@/store/night";
|
|
|
import { showDay } from "@/store/day";
|
|
|
import { clientInfo } from "@/services/common";
|
|
|
import { changeFastDuration, changeSleepDuration, setCurrentRecord, setSchedule } from "@/store/ring";
|
|
|
+import { checkAuthorized } from "@/utils/check_authorized";
|
|
|
|
|
|
let GradientText
|
|
|
let useNavigation;
|
|
|
let timer
|
|
|
let pauseTimer = false;
|
|
|
+let AppState;
|
|
|
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
+ AppState = require("react-native").AppState
|
|
|
GradientText = require('@/components/basic/GradientText').default
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
}
|
|
|
|
|
|
+const defaultValue = `[{"scenario":{"name":"FAST_SLEEP","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"},"sleep":{"start_time":"22:00","end_time":"07:00"}}},"current_record":{"scenario":"FAST_SLEEP","status":"WAIT_FOR_START","fast":{"status":"WAIT_FOR_START","target_start_time":1710514800000,"target_end_time":1710576000000},"sleep":{"status":"WAIT_FOR_START","target_start_time":1710540000000,"target_end_time":1710572400000}},"wx_pub_followed":false,"time_input_schema":{"min":60,"max":1380,"step":5},"theme_color":{"fast":"#00FFFF","sleep":"#8183FF"}},{"scenarios":[{"name":"FAST","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"}}},{"name":"SLEEP","count":0,"schedule":{"sleep":{"start_time":"22:00","end_time":"07:00"}}},{"name":"FAST_SLEEP","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"},"sleep":{"start_time":"22:00","end_time":"07:00"}}}],"select_count":0,"theme_color":{"fast":"#00FFFF","sleep":"#8183FF"}}]`
|
|
|
+
|
|
|
export default function Page() {
|
|
|
const dispatch = useDispatch();
|
|
|
global.dispatch = dispatch;
|
|
|
@@ -97,6 +102,11 @@ export default function Page() {
|
|
|
else {
|
|
|
loadRNCache()
|
|
|
}
|
|
|
+
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ AppState.addEventListener('change', handleAppStateChange);
|
|
|
+ }
|
|
|
+
|
|
|
}, [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -105,11 +115,13 @@ export default function Page() {
|
|
|
|
|
|
if (user.isLogin) {
|
|
|
uploadUserClient();
|
|
|
+
|
|
|
+ checkAuthorized();
|
|
|
}
|
|
|
else {
|
|
|
dispatch(clearNightStore());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}, [user.isLogin, time.status])
|
|
|
|
|
|
useReady(async () => {
|
|
|
@@ -121,10 +133,20 @@ export default function Page() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if (process.env.TARO_ENV == 'weapp') {
|
|
|
+ useShareAppMessage((e) => {
|
|
|
+ return {
|
|
|
+ title: t('feature.track_time_duration.common.share_title'),
|
|
|
+ path: 'pages/clock/Clock'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
})
|
|
|
|
|
|
useDidShow(() => {
|
|
|
- setCount(pre=>pre+1)
|
|
|
+ checkTimeZone()
|
|
|
+ setCount(pre => pre + 1)
|
|
|
//resume timer
|
|
|
pauseTimer = false
|
|
|
})
|
|
|
@@ -139,6 +161,36 @@ export default function Page() {
|
|
|
setCount((prevCounter) => prevCounter + 1)
|
|
|
}
|
|
|
|
|
|
+ const handleAppStateChange = (nextAppState) => {
|
|
|
+ checkTimeZone()
|
|
|
+ };
|
|
|
+
|
|
|
+ function checkTimeZone() {
|
|
|
+ var split = new Date().toString().split(' ');
|
|
|
+ var timeZoneFormatted = split[split.length - 2];
|
|
|
+
|
|
|
+
|
|
|
+ Taro.getStorage({
|
|
|
+ key: 'last_tz',
|
|
|
+ success: function (res) {
|
|
|
+ if (res.data && res.data != timeZoneFormatted) {
|
|
|
+
|
|
|
+ if (global.currentStatus != 'WAIT_FOR_START') {
|
|
|
+ Taro.showModal({
|
|
|
+ title: t('feature.track_time_duration.change_tz_alert.title'),
|
|
|
+ content: t('feature.track_time_duration.change_tz_alert.content', { tz: timeZoneFormatted }),
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: t('feature.track_time_duration.change_tz_alert.confirm'),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ complete: function () {
|
|
|
+ Taro.setStorage({ key: 'last_tz', data: timeZoneFormatted })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
function uploadUserClient() {
|
|
|
var systemInfo = Taro.getSystemInfoSync();
|
|
|
var split = new Date().toString().split(' ');
|
|
|
@@ -146,7 +198,7 @@ export default function Page() {
|
|
|
clientInfo({
|
|
|
client: {
|
|
|
client_type: process.env.TARO_ENV == 'weapp' ? 'MP' : 'APP',
|
|
|
- client_version: '1.0'
|
|
|
+ client_version: process.env.TARO_ENV == 'weapp' ? Taro.getAccountInfoSync().miniProgram.version : '1.0'//'1.0'
|
|
|
},
|
|
|
meta: {
|
|
|
language: systemInfo.language,
|
|
|
@@ -206,6 +258,7 @@ export default function Page() {
|
|
|
Promise.all([getClocks(), getPlans()]).then((list) => {
|
|
|
setHomeData(list[0] as any)
|
|
|
global.homeData = list[0]
|
|
|
+ global.currentStatus = (list[0] as any).current_record.status;
|
|
|
var array = (list[1] as any).scenarios
|
|
|
var schedule = null
|
|
|
array.map(item => {
|
|
|
@@ -225,6 +278,8 @@ export default function Page() {
|
|
|
dispatch(setCurrentRecord((list[0] as any).current_record))
|
|
|
dispatch(setSchedule(schedule))
|
|
|
setLoaded(true)
|
|
|
+ }).catch((e)=>{
|
|
|
+ console.log('9527',e)
|
|
|
})
|
|
|
|
|
|
getHistory()
|