|
@@ -30,11 +30,12 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
const [showModal, setShowModal] = useState(false)
|
|
const [showModal, setShowModal] = useState(false)
|
|
|
const [needTerminal, setNeedTerminal] = useState(false)
|
|
const [needTerminal, setNeedTerminal] = useState(false)
|
|
|
const [isPaused, setIsPaused] = useState(false);
|
|
const [isPaused, setIsPaused] = useState(false);
|
|
|
|
|
+ const [isPosting,setIsPosting] = 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, setPickerValue] = useState<any[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -60,7 +61,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
index: index,
|
|
index: index,
|
|
|
time: startTime,
|
|
time: startTime,
|
|
|
duration: props.targetCount,
|
|
duration: props.targetCount,
|
|
|
- type: 'GROUP'
|
|
|
|
|
|
|
+ type: 'WORK'
|
|
|
}]
|
|
}]
|
|
|
setGroups(array)
|
|
setGroups(array)
|
|
|
saveCache(array)
|
|
saveCache(array)
|
|
@@ -93,7 +94,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
})
|
|
})
|
|
|
- setPcikerValue(selects)
|
|
|
|
|
|
|
+ setPickerValue(selects)
|
|
|
setPickerItems(items)
|
|
setPickerItems(items)
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
@@ -101,16 +102,21 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
if (!isPaused) {
|
|
if (!isPaused) {
|
|
|
timer = setInterval(() => {
|
|
timer = setInterval(() => {
|
|
|
setCount((count) => count + 1)
|
|
setCount((count) => count + 1)
|
|
|
- }, 1000)
|
|
|
|
|
|
|
+ }, 500)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return () => clearInterval(timer)
|
|
return () => clearInterval(timer)
|
|
|
}, [isPaused])
|
|
}, [isPaused])
|
|
|
|
|
|
|
|
function resume() {
|
|
function resume() {
|
|
|
|
|
+ debugger
|
|
|
|
|
+ if (timer){
|
|
|
|
|
+ clearInterval(timer)
|
|
|
|
|
+ timer = null
|
|
|
|
|
+ }
|
|
|
timer = setInterval(() => {
|
|
timer = setInterval(() => {
|
|
|
setCount((count) => count + 1)
|
|
setCount((count) => count + 1)
|
|
|
- }, 1000)
|
|
|
|
|
|
|
+ }, 500)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function planTime() {
|
|
function planTime() {
|
|
@@ -120,7 +126,6 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
|
|
|
|
|
function durationTime() {
|
|
function durationTime() {
|
|
|
var str = TimeFormatter.formateTimeNow(startTime)
|
|
var str = TimeFormatter.formateTimeNow(startTime)
|
|
|
- // setLastStrTime(str)
|
|
|
|
|
lastStrTime = str
|
|
lastStrTime = str
|
|
|
return str
|
|
return str
|
|
|
|
|
|
|
@@ -145,13 +150,18 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function finish() {
|
|
function finish() {
|
|
|
|
|
+
|
|
|
setTempTime(new Date().getTime())
|
|
setTempTime(new Date().getTime())
|
|
|
- if (workout.item.schemas[0].values.length > 0) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var schema = workout.item.schemas[0]
|
|
|
|
|
+ if (workout.item.schemas[0].values.length > 0 && schema.format != 'TIME_SECONDS') {
|
|
|
|
|
+
|
|
|
clearInterval(timer)
|
|
clearInterval(timer)
|
|
|
setShowModal(true)
|
|
setShowModal(true)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ clearInterval(timer)
|
|
|
|
|
+ timer = null
|
|
|
|
|
+ resume()
|
|
|
var array = groups;
|
|
var array = groups;
|
|
|
var time = new Date().getTime()
|
|
var time = new Date().getTime()
|
|
|
array.push({
|
|
array.push({
|
|
@@ -167,13 +177,17 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
|
function start() {
|
|
|
|
|
+ console.log(new Date().getTime())
|
|
|
|
|
+ clearInterval(timer)
|
|
|
|
|
+ timer = null
|
|
|
|
|
+ resume()
|
|
|
var array = groups;
|
|
var array = groups;
|
|
|
var time = new Date().getTime()
|
|
var time = new Date().getTime()
|
|
|
array.push({
|
|
array.push({
|
|
|
code: workout.item.code,
|
|
code: workout.item.code,
|
|
|
index: index + 1,
|
|
index: index + 1,
|
|
|
time: time,
|
|
time: time,
|
|
|
- type: 'GROUP'
|
|
|
|
|
|
|
+ type: 'WORK'
|
|
|
})
|
|
})
|
|
|
setStartTime(time)
|
|
setStartTime(time)
|
|
|
setIndex(index + 1)
|
|
setIndex(index + 1)
|
|
@@ -205,7 +219,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
function getUnit() {
|
|
function getUnit() {
|
|
|
var schema = workout.item.schemas[0]
|
|
var schema = workout.item.schemas[0]
|
|
|
var units = schema.values
|
|
var units = schema.values
|
|
|
- if (schema.log_type == 'TIME_SECONDS') {
|
|
|
|
|
|
|
+ if (schema.format == 'TIME_SECONDS') {
|
|
|
return units[units.length - 1].unit
|
|
return units[units.length - 1].unit
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -214,13 +228,36 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function totalValue() {
|
|
function totalValue() {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
var count = 0
|
|
var count = 0
|
|
|
var schema = workout.item.schemas[0]
|
|
var schema = workout.item.schemas[0]
|
|
|
|
|
+ if (schema.format == 'TIME_SECONDS') {
|
|
|
|
|
+ // for (var i=0;i<groups.length;i++){
|
|
|
|
|
+ // var obj = groups[i]
|
|
|
|
|
+ // if (obj.type=='REST'){
|
|
|
|
|
+ // count+= Math.floor((obj.time-groups[i-1].time)/1000)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ debugger
|
|
|
|
|
+
|
|
|
|
|
+ groups.map(item => {
|
|
|
|
|
+ if (item.type == 'WORK') {
|
|
|
|
|
+ var t = Math.floor((item.end - item.start) / 1000)
|
|
|
|
|
+ t = t<1?1:t
|
|
|
|
|
+ console.log(t)
|
|
|
|
|
+ count += t
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ return count
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (var i = 0; i < groups.length; i++) {
|
|
for (var i = 0; i < groups.length; i++) {
|
|
|
var obj = groups[i]
|
|
var obj = groups[i]
|
|
|
- if (obj.type == 'GROUP') {
|
|
|
|
|
|
|
+ if (obj.type == 'WORK') {
|
|
|
var temp = 0
|
|
var temp = 0
|
|
|
- if (schema.log_type == 'TIME_SECONDS') {
|
|
|
|
|
|
|
+ if (schema.format == 'TIME_SECONDS') {
|
|
|
temp = parseInt(obj.value + '') * 3600 + parseInt(obj.value2 + '') * 60 + parseInt(obj.value3 + '')
|
|
temp = parseInt(obj.value + '') * 3600 + parseInt(obj.value2 + '') * 60 + parseInt(obj.value3 + '')
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -242,6 +279,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function postData() {
|
|
function postData() {
|
|
|
|
|
+ setIsPosting(true)
|
|
|
var date = new Date()
|
|
var date = new Date()
|
|
|
var strDate = formateDate(date)
|
|
var strDate = formateDate(date)
|
|
|
|
|
|
|
@@ -249,7 +287,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
|
|
|
|
|
for (var i = 0; i < groups.length; i++) {
|
|
for (var i = 0; i < groups.length; i++) {
|
|
|
var obj = groups[i]
|
|
var obj = groups[i]
|
|
|
- if (obj.type == 'GROUP') {
|
|
|
|
|
|
|
+ if (obj.type == 'WORK') {
|
|
|
obj.start = obj.time
|
|
obj.start = obj.time
|
|
|
obj.end = groups[i + 1].time
|
|
obj.end = groups[i + 1].time
|
|
|
obj.value = groups[i + 1].value
|
|
obj.value = groups[i + 1].value
|
|
@@ -279,7 +317,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
for (var i = 0; i < groups.length; i++) {
|
|
for (var i = 0; i < groups.length; i++) {
|
|
|
var obj = groups[i]
|
|
var obj = groups[i]
|
|
|
var values: any = []
|
|
var values: any = []
|
|
|
- if (obj.type == 'GROUP') {
|
|
|
|
|
|
|
+ if (obj.type == 'WORK') {
|
|
|
if (obj.value) {
|
|
if (obj.value) {
|
|
|
if (units) {
|
|
if (units) {
|
|
|
values.push({
|
|
values.push({
|
|
@@ -360,7 +398,9 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
|
|
|
|
|
props.end()
|
|
props.end()
|
|
|
global.refreshWorkout()
|
|
global.refreshWorkout()
|
|
|
- }).catch(e => { })
|
|
|
|
|
|
|
+ }).catch(e => {
|
|
|
|
|
+ setIsPosting(false)
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -376,29 +416,32 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
|
|
|
|
|
function terminal() {
|
|
function terminal() {
|
|
|
clearInterval(timer)
|
|
clearInterval(timer)
|
|
|
- setTempTime(new Date().getTime())
|
|
|
|
|
|
|
+ var tempTimestamp = new Date().getTime()
|
|
|
|
|
+ setTempTime(tempTimestamp)
|
|
|
Taro.showModal({
|
|
Taro.showModal({
|
|
|
title: '提示',
|
|
title: '提示',
|
|
|
content: '确认结束?',
|
|
content: '确认结束?',
|
|
|
success: function (res) {
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
- if (workout.item.schemas[0].values.length > 0) {
|
|
|
|
|
|
|
+ var schema = workout.item.schemas[0]
|
|
|
|
|
+ if (workout.item.schemas[0].values.length > 0 && schema.format != 'TIME_SECONDS') {
|
|
|
checkEnd()
|
|
checkEnd()
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var array = groups;
|
|
var array = groups;
|
|
|
- var time = new Date().getTime()
|
|
|
|
|
|
|
+ // var time = new Date().getTime()
|
|
|
array.push({
|
|
array.push({
|
|
|
index: index,
|
|
index: index,
|
|
|
- time: time,
|
|
|
|
|
|
|
+ time: tempTimestamp,
|
|
|
type: 'REST'
|
|
type: 'REST'
|
|
|
})
|
|
})
|
|
|
- setIsDoing(false)
|
|
|
|
|
|
|
+ // setIsDoing(false)
|
|
|
setGroups(array)
|
|
setGroups(array)
|
|
|
|
|
|
|
|
postData()
|
|
postData()
|
|
|
} else if (res.cancel) {
|
|
} else if (res.cancel) {
|
|
|
|
|
+ debugger
|
|
|
resume()
|
|
resume()
|
|
|
console.log('用户点击取消')
|
|
console.log('用户点击取消')
|
|
|
}
|
|
}
|
|
@@ -409,7 +452,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function numChange(e) {
|
|
function numChange(e) {
|
|
|
- debugger
|
|
|
|
|
|
|
+ setPickerValue(e)
|
|
|
setShowModal(false)
|
|
setShowModal(false)
|
|
|
var array = groups;
|
|
var array = groups;
|
|
|
array.push({
|
|
array.push({
|
|
@@ -433,6 +476,26 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function total() {
|
|
function total() {
|
|
|
|
|
+ var schema = workout.item.schemas[0]
|
|
|
|
|
+ if (schema.format == 'TIME_SECONDS') {
|
|
|
|
|
+ var count = 0
|
|
|
|
|
+ // groups.map(item => {
|
|
|
|
|
+ // if (item.type == 'REST') {
|
|
|
|
|
+ // count += parseInt(item.value) * 3600 + parseInt(item.value2) * 60 + parseInt(item.value3)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+
|
|
|
|
|
+ for (var i = 0; i < groups.length; i++) {
|
|
|
|
|
+ var obj = groups[i]
|
|
|
|
|
+ if (obj.type == 'REST') {
|
|
|
|
|
+ count += Math.floor((obj.time - groups[i - 1].time) / 1000)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!count) {
|
|
|
|
|
+ return '0小时0分钟0秒'
|
|
|
|
|
+ }
|
|
|
|
|
+ return TimeFormatter.workoutTime(count)
|
|
|
|
|
+ }
|
|
|
var count = 0
|
|
var count = 0
|
|
|
for (var i = 0; i < groups.length; i++) {
|
|
for (var i = 0; i < groups.length; i++) {
|
|
|
var obj = groups[i]
|
|
var obj = groups[i]
|
|
@@ -459,6 +522,15 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
return count + unit.substring(0, unit.length - 1)
|
|
return count + unit.substring(0, unit.length - 1)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function getGroupValue(item) {
|
|
|
|
|
+ var schema = workout.item.schemas[0]
|
|
|
|
|
+ if (schema.format == 'TIME_SECONDS') {
|
|
|
|
|
+ return ''
|
|
|
|
|
+ return item.value + item.value2 + item.value3
|
|
|
|
|
+ }
|
|
|
|
|
+ return item.value + (item.value2 ? 'x' + item.value2 : '') + (item.value3 ? 'x' + item.value3 : '')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function pickerContent() {
|
|
function pickerContent() {
|
|
|
var color = workout.item.theme_color
|
|
var color = workout.item.theme_color
|
|
|
var title = '本组训练'
|
|
var title = '本组训练'
|
|
@@ -474,6 +546,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
showBtns={true}
|
|
showBtns={true}
|
|
|
onCancel={() => {
|
|
onCancel={() => {
|
|
|
resume()
|
|
resume()
|
|
|
|
|
+ setNeedTerminal(false)
|
|
|
setShowModal(false)
|
|
setShowModal(false)
|
|
|
}} />
|
|
}} />
|
|
|
</View>
|
|
</View>
|
|
@@ -489,7 +562,7 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
}
|
|
}
|
|
|
return <View key={index} className={item.type == 'REST' ? 'item_group' : 'item_group item_rest'} style={{ justifyContent: 'space-between', color: '#fff' }}>
|
|
return <View key={index} className={item.type == 'REST' ? 'item_group' : 'item_group item_rest'} style={{ justifyContent: 'space-between', color: '#fff' }}>
|
|
|
<Text>{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
|
|
<Text>{item.type == 'REST' ? `第${item.index}组` : '组间休息'}</Text>
|
|
|
- {item.type == 'REST' && <Text style={{ color: workout.item.theme_color }}>{item.value}{item.value2 ? 'x' + item.value2 : ''}{item.value3 ? 'x' + item.value3 : ''}</Text>}
|
|
|
|
|
|
|
+ {item.type == 'REST' && <Text style={{ color: workout.item.theme_color }}>{getGroupValue(item)}</Text>}
|
|
|
<Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
|
|
<Text>{twoTimeDuration(groups[index - 1].time, item.time)}</Text>
|
|
|
</View>
|
|
</View>
|
|
|
})
|
|
})
|
|
@@ -498,13 +571,13 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
{
|
|
{
|
|
|
isDoing ? <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
isDoing ? <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
<Text className="working_index">第{index}组</Text>
|
|
<Text className="working_index">第{index}组</Text>
|
|
|
- <Text className="working_duration">{durationTime()}</Text>
|
|
|
|
|
- <ChooseScenarioBtn onClick={finish} title="完成本组" background={workout.item.theme_color} />
|
|
|
|
|
|
|
+ <Text className="working_duration">{isPosting?lastStrTime:durationTime()}</Text>
|
|
|
|
|
+ <ChooseScenarioBtn onClick={finish} disable={isPosting} title="完成本组" background={workout.item.theme_color} />
|
|
|
</View> :
|
|
</View> :
|
|
|
<View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
<View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
<Text className="working_index">组间休息</Text>
|
|
<Text className="working_index">组间休息</Text>
|
|
|
- <Text className="working_duration">{durationTime()}</Text>
|
|
|
|
|
- <ChooseScenarioBtn onClick={start} title="开始下一组" background={workout.item.theme_color} />
|
|
|
|
|
|
|
+ <Text className="working_duration" >{isPosting?lastStrTime:durationTime()}</Text>
|
|
|
|
|
+ <ChooseScenarioBtn onClick={start} disable={isPosting} title="开始下一组" background={workout.item.theme_color} />
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
</View>
|
|
</View>
|
|
@@ -512,24 +585,34 @@ export default function Component(props: { targetCount: any, end: Function }) {
|
|
|
<Text className="working_end" onClick={terminal}>结束训练</Text>
|
|
<Text className="working_end" onClick={terminal}>结束训练</Text>
|
|
|
<View style={{ height: 50 }} />
|
|
<View style={{ height: 50 }} />
|
|
|
|
|
|
|
|
- <Text>实时训练统计</Text>
|
|
|
|
|
- <Text>总量</Text>
|
|
|
|
|
- <Text>{total()}</Text>
|
|
|
|
|
- <Text>总用时</Text>
|
|
|
|
|
- <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%' }}>
|
|
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
- <Text>计划用时</Text>
|
|
|
|
|
- <Text>{planTime()}</Text>
|
|
|
|
|
- </View>
|
|
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
- <Text>已进行</Text>
|
|
|
|
|
- <Text>{groups.length > 0 && TimeFormatter.formateTimeNow(groups[0].time)}</Text>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ !router.params.content_only && <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
|
|
+ <Text>实时训练统计</Text>
|
|
|
|
|
+ <Text>总量</Text>
|
|
|
|
|
+ <Text>{total()}</Text>
|
|
|
|
|
+ <Text>总用时</Text>
|
|
|
</View>
|
|
</View>
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
- <Text>{groups.length > 0 && new Date().getTime() > groups[0].time + props.targetCount * 1000 ? '已超时' : '距结束'}</Text>
|
|
|
|
|
- <Text>{groups.length > 0 && TimeFormatter.countdown(groups[0].time + props.targetCount * 1000)}</Text>
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ !router.params.content_only && <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', width: '100%' }}>
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
+ <Text>计划用时</Text>
|
|
|
|
|
+ <Text>{planTime()}</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
+ <Text>已进行</Text>
|
|
|
|
|
+ <Text>{groups.length > 0 && TimeFormatter.formateTimeNow(groups[0].time)}</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
|
|
+ <Text>{groups.length > 0 && new Date().getTime() > groups[0].time + props.targetCount * 1000 ? '已超时' : '距结束'}</Text>
|
|
|
|
|
+ <Text>{groups.length > 0 && TimeFormatter.countdown(groups[0].time + props.targetCount * 1000)}</Text>
|
|
|
|
|
+ </View>
|
|
|
</View>
|
|
</View>
|
|
|
- </View>
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
{
|
|
{
|
|
|
showModal && <Modal dismiss={() => {
|
|
showModal && <Modal dismiss={() => {
|
|
|
setShowModal(false)
|
|
setShowModal(false)
|