|
|
@@ -8,7 +8,10 @@ import { WorkoutType } from "@/utils/types";
|
|
|
import Modal from "@/components/layout/Modal";
|
|
|
import PickerViews from "@/components/input/PickerViews";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
-import { startSuccess } from "@/store/workout";
|
|
|
+import { endSuccess, startSuccess } from "@/store/workout";
|
|
|
+import { uploadWorkout } from "@/services/workout";
|
|
|
+import './WorkoutStopWatch.scss'
|
|
|
+import Box from "@/components/layout/Box";
|
|
|
|
|
|
|
|
|
var timer
|
|
|
@@ -27,23 +30,45 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
const [isPaused, setIsPaused] = useState(false);
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
- const items = [[1, 2, 3, 4, 5, 6]]
|
|
|
- const [selIndex, setSelIndex] = useState([1])
|
|
|
- const multiItems = [[10, 20, 30, 40], [1, 2, 3, 4, 5]]
|
|
|
- const multiSel = [1, 1]
|
|
|
+ const [pickerItems, setPickerItems] = useState<any[]>([])
|
|
|
+ const [pickerValue, setPcikerValue] = useState<any[]>([])
|
|
|
|
|
|
useEffect(() => {
|
|
|
var array = [{
|
|
|
+ code: workout.item.code,
|
|
|
index: index,
|
|
|
time: startTime,
|
|
|
- type: 'start'
|
|
|
+ type: 'GROUP'
|
|
|
}]
|
|
|
setGroups(array)
|
|
|
saveCache(array)
|
|
|
dispatch(startSuccess({
|
|
|
start: startTime,
|
|
|
- id: 1
|
|
|
+ code: workout.item.code,
|
|
|
}))
|
|
|
+
|
|
|
+
|
|
|
+ var item = workout.item
|
|
|
+ var items: any = []
|
|
|
+ var selects: any = []
|
|
|
+ item.schemas[0].values.map(obj => {
|
|
|
+ var list: any = []
|
|
|
+ var min = parseInt(obj.min+'')
|
|
|
+ var max = parseInt(obj.max+'')
|
|
|
+ var step = parseInt(obj.step+'')
|
|
|
+ var defaultV = parseInt(obj.default_value)
|
|
|
+ for (var i = min; i <= max; i = i + step) {
|
|
|
+ list.push(i + obj.unit)
|
|
|
+ if (defaultV==i+min){
|
|
|
+ selects.push(i)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ items.push(list)
|
|
|
+
|
|
|
+ })
|
|
|
+ debugger
|
|
|
+ setPcikerValue(selects)
|
|
|
+ setPickerItems(items)
|
|
|
}, [])
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -103,9 +128,10 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
var array = groups;
|
|
|
var time = new Date().getTime()
|
|
|
array.push({
|
|
|
+ code: workout.item.code,
|
|
|
index: index,
|
|
|
time: time,
|
|
|
- type: 'end'
|
|
|
+ type: 'REST'
|
|
|
})
|
|
|
setIsDoing(false)
|
|
|
setStartTime(time)
|
|
|
@@ -117,9 +143,10 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
var array = groups;
|
|
|
var time = new Date().getTime()
|
|
|
array.push({
|
|
|
+ code: workout.item.code,
|
|
|
index: index + 1,
|
|
|
time: time,
|
|
|
- type: 'start'
|
|
|
+ type: 'GROUP'
|
|
|
})
|
|
|
setStartTime(time)
|
|
|
setIndex(index + 1)
|
|
|
@@ -139,12 +166,108 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
Taro.removeStorage({ key: 'lastWorkout' })
|
|
|
}
|
|
|
|
|
|
- function checkEnd() {
|
|
|
- if (groups[groups.length - 1].type == 'end') {
|
|
|
+ function formateDate(date) {
|
|
|
+ return (date.getFullYear() + '') + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ function getValue(str, unit) {
|
|
|
+ var i = str.indexOf(unit)
|
|
|
+ return str.substring(0, 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ function postData() {
|
|
|
+ var date = new Date()
|
|
|
+ var strDate = formateDate(date)
|
|
|
+
|
|
|
+ var records: any = []
|
|
|
+
|
|
|
+ for (var i = 0; i < groups.length; i++) {
|
|
|
+ var obj = groups[i]
|
|
|
+ if (obj.type == 'GROUP') {
|
|
|
+ obj.start = obj.time
|
|
|
+ obj.end = groups[i + 1].time
|
|
|
+ obj.value = groups[i + 1].value
|
|
|
+ obj.value2 = groups[i + 1].value2
|
|
|
+ obj.value3 = groups[i + 1].value3
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (i != groups.length - 1) {
|
|
|
+ obj.start = obj.time
|
|
|
+ obj.end = groups[i + 1].time
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var i = groups.length - 1; i >= 0; i--) {
|
|
|
+ var obj = groups[i]
|
|
|
+ if (obj.type == 'REST') {
|
|
|
+ groups.splice(i, 1)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var units = workout.item.schemas[0].values
|
|
|
+ for (var i = 0; i < groups.length; i++) {
|
|
|
+ var obj = groups[i]
|
|
|
+ var values: any = []
|
|
|
+ if (obj.type == 'GROUP') {
|
|
|
+ values.push({
|
|
|
+ value: getValue(obj.value, units[0].unit)
|
|
|
+ })
|
|
|
+ if (obj.value2) {
|
|
|
+ values.push({
|
|
|
+ value: getValue(obj.value2, units[1].unit)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (obj.value3) {
|
|
|
+ values.push({
|
|
|
+ value: getValue(obj.value3, units[2].unit)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ records.push({
|
|
|
+ type: obj.type,
|
|
|
+ start: {
|
|
|
+ date: formateDate(new Date(obj.start)),
|
|
|
+ timestamp: obj.start
|
|
|
+ },
|
|
|
+ end: {
|
|
|
+ date: formateDate(new Date(obj.end)),
|
|
|
+ timestamp: obj.end
|
|
|
+ },
|
|
|
+ values: values
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ var params = {
|
|
|
+ date: strDate,
|
|
|
+ timestamp: date.getTime(),
|
|
|
+ code: workout.item.code,
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ code: workout.item.code,
|
|
|
+ groups: records
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ uploadWorkout(params).then(res => {
|
|
|
+ dispatch(endSuccess())
|
|
|
Taro.redirectTo({
|
|
|
url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(groups)
|
|
|
})
|
|
|
props.end()
|
|
|
+ }).catch(e => { })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function checkEnd() {
|
|
|
+ if (groups[groups.length - 1].type == 'REST') {
|
|
|
+ postData()
|
|
|
return
|
|
|
}
|
|
|
setNeedTerminal(true)
|
|
|
@@ -168,15 +291,12 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
array.push({
|
|
|
index: index,
|
|
|
time: time,
|
|
|
- type: 'end'
|
|
|
+ type: 'REST'
|
|
|
})
|
|
|
setIsDoing(false)
|
|
|
setGroups(array)
|
|
|
|
|
|
- Taro.redirectTo({
|
|
|
- url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(array)
|
|
|
- })
|
|
|
- props.end()
|
|
|
+ postData()
|
|
|
} else if (res.cancel) {
|
|
|
resume()
|
|
|
console.log('用户点击取消')
|
|
|
@@ -193,16 +313,14 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
array.push({
|
|
|
index: index,
|
|
|
time: tempTime,
|
|
|
- value: e.length > 0 ? multiItems[0][e[0]] : items[e[0]],
|
|
|
- value2: e.length > 0 ? multiItems[1][e[1]] : null,
|
|
|
- type: 'end'
|
|
|
+ value: e.length > 0 ? pickerItems[0][e[0]] : pickerItems[e[0]],
|
|
|
+ value2: e.length > 1 ? pickerItems[1][e[1]] : null,
|
|
|
+ value3: e.length > 2 ? pickerItems[2][e[2]] : null,
|
|
|
+ type: 'REST'
|
|
|
})
|
|
|
setIsDoing(false)
|
|
|
if (needTerminal) {
|
|
|
- Taro.redirectTo({
|
|
|
- url: '/pages/workout/WorkoutDetail?detail=' + JSON.stringify(groups)
|
|
|
- })
|
|
|
- props.end()
|
|
|
+ postData()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -213,26 +331,15 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
}
|
|
|
|
|
|
function pickerContent() {
|
|
|
- var item = workout.item
|
|
|
- console.log(item)
|
|
|
- var color = ColorType.workout
|
|
|
+ var color = workout.item.theme_color
|
|
|
var title = '本组训练'
|
|
|
|
|
|
- var items:any = []
|
|
|
- var selects:any=[]
|
|
|
- item.schemas[0].values.map(obj=>{
|
|
|
- var list:any = []
|
|
|
- for (var i=obj.min;i<=obj.max;i=i+obj.step){
|
|
|
- list.push(i+obj.unit)
|
|
|
- }
|
|
|
- items.push(list)
|
|
|
- selects.push(0)
|
|
|
- })
|
|
|
+
|
|
|
return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
|
<PickerViews
|
|
|
onChange={numChange}
|
|
|
- items={items}
|
|
|
- value={selects}
|
|
|
+ items={pickerItems}
|
|
|
+ value={pickerValue}
|
|
|
themeColor={color}
|
|
|
title={title}
|
|
|
showBtns={true}
|
|
|
@@ -243,37 +350,38 @@ export default function Component(props: { targetCount: any, type: WorkoutType,
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
- return <View style={{ color: ColorType.workout, flexDirection: 'column', display: 'flex' }}>
|
|
|
- <Text>平板支撑</Text>
|
|
|
- <Text>计时训练</Text>
|
|
|
+ return <View style={{ color: workout.item.theme_color, flexDirection: 'column', display: 'flex' }}>
|
|
|
+ <Text className="working_title">{workout.item.name}</Text>
|
|
|
+ <Text className="working_subtitle">计时训练</Text>
|
|
|
{
|
|
|
groups.length > 1 && groups.map((item, index) => {
|
|
|
if (index == 0) {
|
|
|
return <View />
|
|
|
}
|
|
|
return <View key={index} style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%', color: '#fff' }}>
|
|
|
- <Text>{item.type == 'end' ? `第${item.index}组` : '组间休息'}</Text>
|
|
|
- {item.type == 'end' && props.type == WorkoutType.number && <Text style={{ color: ColorType.workout }}>{item.value}个</Text>}
|
|
|
- {item.type == 'end' && props.type == WorkoutType.multi && <Text style={{ color: ColorType.workout }}>{item.value}x{item.value2}个</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>}
|
|
|
<Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
|
|
|
</View>
|
|
|
})
|
|
|
}
|
|
|
- {
|
|
|
- isDoing && <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
- <Text>第{index}组</Text>
|
|
|
- <Text>{durationTime()}</Text>
|
|
|
- <ChooseScenarioBtn onClick={finish} title="完成本组" background={ColorType.workout} />
|
|
|
- </View>
|
|
|
- }
|
|
|
- {
|
|
|
- !isDoing && <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
- <Text>组间休息</Text>
|
|
|
- <Text>{durationTime()}</Text>
|
|
|
- <ChooseScenarioBtn onClick={start} title="开始下一组" background={ColorType.workout} />
|
|
|
- </View>
|
|
|
- }
|
|
|
- <Text style={{ color: 'red' }} onClick={terminal}>结束训练</Text>
|
|
|
+ <Box>
|
|
|
+ {
|
|
|
+ isDoing ? <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
+ <Text className="working_index">第{index}组</Text>
|
|
|
+ <Text className="working_duration">{durationTime()}</Text>
|
|
|
+ <ChooseScenarioBtn onClick={finish} title="完成本组" background={workout.item.theme_color} />
|
|
|
+ </View> :
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
+ <Text className="working_index">组间休息</Text>
|
|
|
+ <Text className="working_duration">{durationTime()}</Text>
|
|
|
+ <ChooseScenarioBtn onClick={start} title="开始下一组" background={workout.item.theme_color} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <Text className="working_end" onClick={terminal}>结束训练</Text>
|
|
|
<View style={{ height: 50 }} />
|
|
|
<Text>总用时</Text>
|
|
|
<View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%' }}>
|