|
@@ -3,7 +3,7 @@ import { TimeFormatter } from "@/utils/time_format";
|
|
|
import { View, Text } from "@tarojs/components";
|
|
import { View, Text } from "@tarojs/components";
|
|
|
import { useEffect, useState } from "react";
|
|
import { useEffect, useState } from "react";
|
|
|
import { ChooseScenarioBtn } from "../common/SpecBtns";
|
|
import { ChooseScenarioBtn } from "../common/SpecBtns";
|
|
|
-import Taro from "@tarojs/taro";
|
|
|
|
|
|
|
+import Taro, { useRouter } from "@tarojs/taro";
|
|
|
import { WorkoutType } from "@/utils/types";
|
|
import { WorkoutType } from "@/utils/types";
|
|
|
import Modal from "@/components/layout/Modal";
|
|
import Modal from "@/components/layout/Modal";
|
|
|
import PickerViews from "@/components/input/PickerViews";
|
|
import PickerViews from "@/components/input/PickerViews";
|
|
@@ -16,7 +16,9 @@ import Box from "@/components/layout/Box";
|
|
|
|
|
|
|
|
var timer
|
|
var timer
|
|
|
var lastStrTime
|
|
var lastStrTime
|
|
|
-export default function Component(props: { targetCount: any, type: WorkoutType, end: Function }) {
|
|
|
|
|
|
|
+export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
|
|
+ const router = useRouter();
|
|
|
|
|
+
|
|
|
const workout = useSelector((state: any) => state.workout);
|
|
const workout = useSelector((state: any) => state.workout);
|
|
|
const [index, setIndex] = useState(1)
|
|
const [index, setIndex] = useState(1)
|
|
|
const [count, setCount] = useState(0)
|
|
const [count, setCount] = useState(0)
|
|
@@ -30,22 +32,40 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
const [isPaused, setIsPaused] = useState(false);
|
|
const [isPaused, setIsPaused] = useState(false);
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
+
|
|
|
const [pickerItems, setPickerItems] = useState<any[]>([])
|
|
const [pickerItems, setPickerItems] = useState<any[]>([])
|
|
|
const [pickerValue, setPcikerValue] = useState<any[]>([])
|
|
const [pickerValue, setPcikerValue] = useState<any[]>([])
|
|
|
|
|
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- var array = [{
|
|
|
|
|
- code: workout.item.code,
|
|
|
|
|
- index: index,
|
|
|
|
|
- time: startTime,
|
|
|
|
|
- type: 'GROUP'
|
|
|
|
|
- }]
|
|
|
|
|
- setGroups(array)
|
|
|
|
|
- saveCache(array)
|
|
|
|
|
- dispatch(startSuccess({
|
|
|
|
|
- start: startTime,
|
|
|
|
|
- code: workout.item.code,
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ if (router.params.restore) {
|
|
|
|
|
+ Taro.getStorage({
|
|
|
|
|
+ key: 'lastWorkout', success: function (res) {
|
|
|
|
|
+ var workouts = JSON.parse(res.data)
|
|
|
|
|
+ debugger
|
|
|
|
|
+ setGroups(workouts)
|
|
|
|
|
+ setStartTime(workouts[workouts.length - 1].time)
|
|
|
|
|
+ }, fail: function (err) {
|
|
|
|
|
+ console.log(err, 'no cache')
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ var array = [{
|
|
|
|
|
+ code: workout.item.code,
|
|
|
|
|
+ index: index,
|
|
|
|
|
+ time: startTime,
|
|
|
|
|
+ duration: props.targetCount,
|
|
|
|
|
+ type: 'GROUP'
|
|
|
|
|
+ }]
|
|
|
|
|
+ setGroups(array)
|
|
|
|
|
+ saveCache(array)
|
|
|
|
|
+ dispatch(startSuccess({
|
|
|
|
|
+ start: startTime,
|
|
|
|
|
+ code: workout.item.code,
|
|
|
|
|
+ duration: props.targetCount
|
|
|
|
|
+ }))
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
var item = workout.item
|
|
var item = workout.item
|
|
@@ -53,20 +73,19 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
var selects: any = []
|
|
var selects: any = []
|
|
|
item.schemas[0].values.map(obj => {
|
|
item.schemas[0].values.map(obj => {
|
|
|
var list: any = []
|
|
var list: any = []
|
|
|
- var min = parseInt(obj.min+'')
|
|
|
|
|
- var max = parseInt(obj.max+'')
|
|
|
|
|
- var step = parseInt(obj.step+'')
|
|
|
|
|
|
|
+ var min = parseInt(obj.min + '')
|
|
|
|
|
+ var max = parseInt(obj.max + '')
|
|
|
|
|
+ var step = parseInt(obj.step + '')
|
|
|
var defaultV = parseInt(obj.default_value)
|
|
var defaultV = parseInt(obj.default_value)
|
|
|
for (var i = min; i <= max; i = i + step) {
|
|
for (var i = min; i <= max; i = i + step) {
|
|
|
list.push(i + obj.unit)
|
|
list.push(i + obj.unit)
|
|
|
- if (defaultV==i+min){
|
|
|
|
|
|
|
+ if (defaultV == i + min) {
|
|
|
selects.push(i)
|
|
selects.push(i)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
items.push(list)
|
|
items.push(list)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
})
|
|
})
|
|
|
- debugger
|
|
|
|
|
setPcikerValue(selects)
|
|
setPcikerValue(selects)
|
|
|
setPickerItems(items)
|
|
setPickerItems(items)
|
|
|
}, [])
|
|
}, [])
|
|
@@ -119,7 +138,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function finish() {
|
|
function finish() {
|
|
|
- if (props.type != WorkoutType.normal) {
|
|
|
|
|
|
|
+ if (workout.item.schemas[0].values.length > 0) {
|
|
|
setTempTime(new Date().getTime())
|
|
setTempTime(new Date().getTime())
|
|
|
clearInterval(timer)
|
|
clearInterval(timer)
|
|
|
setShowModal(true)
|
|
setShowModal(true)
|
|
@@ -172,7 +191,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
|
|
|
|
|
function getValue(str, unit) {
|
|
function getValue(str, unit) {
|
|
|
var i = str.indexOf(unit)
|
|
var i = str.indexOf(unit)
|
|
|
- return str.substring(0, 1)
|
|
|
|
|
|
|
+ return str.substring(0, i)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function postData() {
|
|
function postData() {
|
|
@@ -256,11 +275,13 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
|
uploadWorkout(params).then(res => {
|
|
uploadWorkout(params).then(res => {
|
|
|
|
|
+ clearCache()
|
|
|
dispatch(endSuccess())
|
|
dispatch(endSuccess())
|
|
|
Taro.redirectTo({
|
|
Taro.redirectTo({
|
|
|
- url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(groups)
|
|
|
|
|
|
|
+ url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify((res as any).latest_record)
|
|
|
})
|
|
})
|
|
|
props.end()
|
|
props.end()
|
|
|
|
|
+ global.refreshWorkout()
|
|
|
}).catch(e => { })
|
|
}).catch(e => { })
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -272,7 +293,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
}
|
|
}
|
|
|
setNeedTerminal(true)
|
|
setNeedTerminal(true)
|
|
|
setShowModal(true)
|
|
setShowModal(true)
|
|
|
- clearCache()
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function terminal() {
|
|
function terminal() {
|
|
@@ -282,10 +303,11 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
content: '确认结束?',
|
|
content: '确认结束?',
|
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
- if (props.type != WorkoutType.normal) {
|
|
|
|
|
|
|
+ if (workout.item.schemas[0].values.length > 0) {
|
|
|
checkEnd()
|
|
checkEnd()
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
var array = groups;
|
|
var array = groups;
|
|
|
var time = new Date().getTime()
|
|
var time = new Date().getTime()
|
|
|
array.push({
|
|
array.push({
|
|
@@ -324,7 +346,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ saveCache(array)
|
|
|
setStartTime(tempTime)
|
|
setStartTime(tempTime)
|
|
|
setGroups(array)
|
|
setGroups(array)
|
|
|
resume()
|
|
resume()
|
|
@@ -360,8 +382,7 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
}
|
|
}
|
|
|
return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
|
|
return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
|
|
|
<Text>{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
|
|
<Text>{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
|
|
|
- {item.type == 'REST' && props.type == WorkoutType.number && <Text style={{ color: workout.item.theme_color }}>{item.value}</Text>}
|
|
|
|
|
- {item.type == 'REST' && props.type == WorkoutType.multi && <Text style={{ color: workout.item.theme_color }}>{item.value}x{item.value2}{item.value3?'x'+item.value3:''}</Text>}
|
|
|
|
|
|
|
+ {item.type == 'REST' && <Text style={{ color: workout.item.theme_color }}>{item.value}{item.value2 ? 'x' + item.value2 : ''}{item.value3 ? 'x' + item.value3 : ''}</Text>}
|
|
|
<Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
|
|
<Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
})
|
|
})
|