|
|
@@ -25,12 +25,13 @@ import { t } from "i18next";
|
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
|
let scenario = '';
|
|
|
+let AppState;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
useRoute = require("@react-navigation/native").useRoute
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
+ AppState = require("react-native").AppState
|
|
|
}
|
|
|
|
|
|
-const enter_timestamp = new Date().getTime()
|
|
|
export default function LogTime() {
|
|
|
let router
|
|
|
let navigation;
|
|
|
@@ -45,6 +46,7 @@ export default function LogTime() {
|
|
|
router = useRouter()
|
|
|
}
|
|
|
const [enterTime, setEnterTime] = useState(new Date().getTime())
|
|
|
+ const [enter_timestamp] = useState(new Date().getTime())
|
|
|
|
|
|
const isSingle = router.params.single == '1'
|
|
|
const isFast = router.params.window == 'FAST'
|
|
|
@@ -73,7 +75,7 @@ export default function LogTime() {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -95,7 +97,6 @@ export default function LogTime() {
|
|
|
|
|
|
//前端待处理,日期更新
|
|
|
setTimeout(() => {
|
|
|
- console.log('zzzzzzzzzzzzzzzzzzzz')
|
|
|
setCount(count => count + 1)
|
|
|
setArray(array => {
|
|
|
array.map((item) => {
|
|
|
@@ -105,8 +106,25 @@ export default function LogTime() {
|
|
|
})
|
|
|
}, left)
|
|
|
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ AppState.addEventListener('change', handleAppStateChange);
|
|
|
+ }
|
|
|
+ Taro.onAppShow(() => {
|
|
|
+ setCount(count => count + 1)
|
|
|
+ })
|
|
|
+
|
|
|
}, [])
|
|
|
|
|
|
+ const handleAppStateChange = (nextAppState) => {
|
|
|
+ if (nextAppState != 'active') {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (nextAppState == 'active') {
|
|
|
+ setCount(count => count + 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (autoCheck) {
|
|
|
if (ignoreCheck) {
|
|
|
@@ -148,28 +166,47 @@ export default function LogTime() {
|
|
|
var list: any = []
|
|
|
if (isSingle) {
|
|
|
var timeline: any;
|
|
|
+ var time = dayjs().format('HH:mm')
|
|
|
+ var date = dayjs().format('YYYY-MM-DD')
|
|
|
+
|
|
|
if (isFast) {
|
|
|
timeline = isStart ? fast.timeline[0] : fast.timeline[1]
|
|
|
Taro.setNavigationBarTitle({
|
|
|
title: isStart ? fast.timeline[0].title : fast.timeline[1].title
|
|
|
});
|
|
|
+
|
|
|
+ //特殊处理单场景下,结束,超过24小时,picker设置为target_end_time
|
|
|
+ if (!isStart && new Date().getTime() - fast.timeline[0].target.timestamp>=24*3600*1000) {
|
|
|
+ time = dayjs(fast.timeline[1].target.timestamp).format('HH:mm')
|
|
|
+ date = dayjs(fast.timeline[1].target.timestamp).format('YYYY-MM-DD')
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
timeline = isStart ? sleep.timeline[0] : sleep.timeline[1]
|
|
|
Taro.setNavigationBarTitle({
|
|
|
title: isStart ? sleep.timeline[0].title : sleep.timeline[1].title
|
|
|
});
|
|
|
+
|
|
|
+ //特殊处理单场景下,结束,超过24小时,picker设置为target_end_time
|
|
|
+ if (!isStart && new Date().getTime() - sleep.timeline[0].target.timestamp>=24*3600*1000) {
|
|
|
+ time = dayjs(sleep.timeline[1].target.timestamp).format('HH:mm')
|
|
|
+ date = dayjs(sleep.timeline[1].target.timestamp).format('YYYY-MM-DD')
|
|
|
+ }
|
|
|
}
|
|
|
if (router.params.longfast) {
|
|
|
Taro.setNavigationBarTitle({
|
|
|
title: t('health.long_fast')
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
list.push({
|
|
|
event_id: timeline.event_id,
|
|
|
schedule_id: timeline.schedule_id,
|
|
|
- time: dayjs().format('HH:mm'),
|
|
|
- date: dayjs().format('YYYY-MM-DD'),
|
|
|
+ time: time,
|
|
|
+ date: date,
|
|
|
extra: {
|
|
|
set_time: enterTime,
|
|
|
confirm_time: enterTime
|
|
|
@@ -305,6 +342,7 @@ export default function LogTime() {
|
|
|
// var minute = parseInt(time.split(':')[1])
|
|
|
// var date = obj.date
|
|
|
var now = new Date(obj.date + 'T' + time + ':' + dayjs(enter_timestamp).format('ss'))
|
|
|
+ now.setMilliseconds(new Date(enter_timestamp).getMilliseconds())
|
|
|
// now.setHours(hour)
|
|
|
// now.setMinutes(minute)
|
|
|
// now.setSeconds(0)
|
|
|
@@ -313,7 +351,7 @@ export default function LogTime() {
|
|
|
return timestamp
|
|
|
}
|
|
|
|
|
|
- function tapDone(){
|
|
|
+ function tapDone() {
|
|
|
var findError = false
|
|
|
for (var i = 0; i < array.length; i++) {
|
|
|
var obj = array[i]
|
|
|
@@ -341,7 +379,7 @@ export default function LogTime() {
|
|
|
}
|
|
|
|
|
|
function tapCommit(onlyCheck, firstCheck = false, save_confirm = null) {
|
|
|
-
|
|
|
+
|
|
|
for (var i = 0; i < array.length; i++) {
|
|
|
var obj = array[i]
|
|
|
if (obj.time == '' || obj.date == '') {
|
|
|
@@ -352,9 +390,9 @@ export default function LogTime() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -466,16 +504,16 @@ export default function LogTime() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- function getLogMethod(list){
|
|
|
+ function getLogMethod(list) {
|
|
|
// if (isSingle) return 'LOG_ONCE'
|
|
|
- if (list.length==1) return 'LOG_ONCE'
|
|
|
+ if (list.length == 1) return 'LOG_ONCE'
|
|
|
const { status } = data
|
|
|
if (status == 'OG2_MISALIGNED') return 'LOG_MULTIPLE'
|
|
|
if (status == 'OG2_NO1') return 'LOG_MULTIPLE'
|
|
|
- if (status == 'WFS' && list.length>1) return 'LOG_MULTIPLE'
|
|
|
- if (status == 'OG1' && list.length>2) return 'LOG_MULTIPLE'
|
|
|
- if (status == 'OG2' && list.length>3) return 'LOG_MULTIPLE'
|
|
|
-
|
|
|
+ if (status == 'WFS' && list.length > 1) return 'LOG_MULTIPLE'
|
|
|
+ if (status == 'OG1' && list.length > 2) return 'LOG_MULTIPLE'
|
|
|
+ if (status == 'OG2' && list.length > 3) return 'LOG_MULTIPLE'
|
|
|
+
|
|
|
return 'LOG_ONCE'
|
|
|
}
|
|
|
|
|
|
@@ -606,7 +644,7 @@ export default function LogTime() {
|
|
|
if (minutes > 0) {
|
|
|
str += minutes + TimeFormatter.getMinutesUnit(minutes)
|
|
|
}
|
|
|
- if (hour == 0 && minutes == 0){
|
|
|
+ if (hour == 0 && minutes == 0) {
|
|
|
str = 0 + TimeFormatter.getMinutesUnit(0)
|
|
|
}
|
|
|
return str
|