Commit d5d7ee95 authored by hewenhao's avatar hewenhao

feat: update

parent e2ccd7a4
...@@ -17,7 +17,9 @@ type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { ...@@ -17,7 +17,9 @@ type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
'maxValue'?: number; 'maxValue'?: number;
'isDown'?: boolean; 'isDown'?: boolean;
'startValue': number; 'startValue': number;
exceedTime: number;
onTimeup?: () => void; onTimeup?: () => void;
onExceed?: () => void;
}, HTMLElement> }, HTMLElement>
declare namespace JSX{ declare namespace JSX{
......
...@@ -34,12 +34,16 @@ Component({ ...@@ -34,12 +34,16 @@ Component({
startValue: { startValue: {
type: Number, type: Number,
value: 0 value: 0
},
exceedTime: {
type: Number,
value: 20
} }
}, },
data: { data: {
minutes: '00', minutes: '00',
seconds: '00' seconds: '00',
}, },
attached () { attached () {
...@@ -64,7 +68,6 @@ Component({ ...@@ -64,7 +68,6 @@ Component({
start () { start () {
this.stop() this.stop()
this._timer = setInterval(() => { this._timer = setInterval(() => {
console.log(this.data)
const isDown = this.data.isDown const isDown = this.data.isDown
if (isDown) { if (isDown) {
this._tick -= 1 this._tick -= 1
...@@ -72,6 +75,10 @@ Component({ ...@@ -72,6 +75,10 @@ Component({
this.stop() this.stop()
this.triggerEvent('timeup') this.triggerEvent('timeup')
} }
if (this._tick === this.data.exceedTime) {
this.triggerEvent('exceed')
}
} else { } else {
this._tick += 1 this._tick += 1
if (this._tick >= this.data.maxValue) { if (this._tick >= this.data.maxValue) {
......
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
color: #465164; color: #465164;
line-height: 46px; line-height: 46px;
&.red {
color: #FF7770;
}
.icon { .icon {
width: 32px; width: 32px;
height: 32px; height: 32px;
......
import { View, Image } from '@tarojs/components' import { View, Image } from '@tarojs/components'
import { useState, useEffect, useCallback, useMemo, useRef } from 'react' import { useState, useEffect, useCallback, useMemo } from 'react'
import { createSelectorQuery, getCurrentInstance } from '@tarojs/taro' import { createSelectorQuery } from '@tarojs/taro'
import classNames from 'classnames' import classNames from 'classnames'
import { useBoolean } from '@/hooks'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
import { type StageDetail, StageType } from '@/api' import { type StageDetail, StageType } from '@/api'
...@@ -21,6 +22,7 @@ const CountUp = (props: CountUpProps) => { ...@@ -21,6 +22,7 @@ const CountUp = (props: CountUpProps) => {
const isSubmit = useStoreState(state => state.gameModel.isSubmit) const isSubmit = useStoreState(state => state.gameModel.isSubmit)
const submit = useStoreActions(actions => actions.gameModel.submit) const submit = useStoreActions(actions => actions.gameModel.submit)
const [width, setWidth] = useState(0) const [width, setWidth] = useState(0)
const [isExceed, exceedActions] = useBoolean(false)
const questionLength = useMemo(() => { const questionLength = useMemo(() => {
return questionList.length return questionList.length
...@@ -55,13 +57,6 @@ const CountUp = (props: CountUpProps) => { ...@@ -55,13 +57,6 @@ const CountUp = (props: CountUpProps) => {
} }
}, [width, stageDetail.bTime]) }, [width, stageDetail.bTime])
// useEffect(() => {
// if (isSubmit) {
// const comp = getCurrentInstance()?.page?.selectComponent?.(`#${counterId}`) as any
// comp?.stop?.()
// }
// }, [isSubmit, counterId])
const processInnerStyle = useMemo(() => { const processInnerStyle = useMemo(() => {
if (isSubmit) { if (isSubmit) {
return { return {
...@@ -92,9 +87,20 @@ const CountUp = (props: CountUpProps) => { ...@@ -92,9 +87,20 @@ const CountUp = (props: CountUpProps) => {
</View> </View>
)} )}
</View> </View>
<View className={styles.time}> <View className={classNames(styles.time, isExceed && styles.red)}>
<Image src={require('../assets/count-time.png')} className={styles.icon}></Image> {isExceed
<count-up-time maxValue={60 * 60} startValue={startTick} isDown={isOneStop} onTimeup={handleTimeUp} id={counterId} /> ? (<Image src={require('../assets/time-red.png')} className={styles.icon}></Image>)
: (<Image src={require('../assets/count-time.png')} className={styles.icon}></Image>)
}
<count-up-time
exceedTime={20}
onExceed={exceedActions.setTrue}
maxValue={60 * 60}
startValue={startTick}
isDown={isOneStop}
onTimeup={handleTimeUp}
id={counterId}
/>
</View> </View>
</View> </View>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment