Commit d5d7ee95 authored by hewenhao's avatar hewenhao

feat: update

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