Commit 247e14c0 authored by hewenhao's avatar hewenhao

feat: update

parent f4fb6e1a
...@@ -34,5 +34,17 @@ ...@@ -34,5 +34,17 @@
"错误.wav": { "错误.wav": {
"u": "https://cdn.jkwljy.com/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav", "u": "https://cdn.jkwljy.com/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav",
"ossName": "/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav" "ossName": "/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav"
},
"引导页-A和B通关.wav": {
"u": "https://cdn.jkwljy.com/pk-math/39xS7n44dr7UfLvHkhAoTfkYVpgV.wav",
"ossName": "/pk-math/39xS7n44dr7UfLvHkhAoTfkYVpgV.wav"
},
"猫猫说话背景声.wav": {
"u": "https://cdn.jkwljy.com/pk-math/3BsHxobKFTM5jEHkSic2rKmwb5nU.wav",
"ossName": "/pk-math/3BsHxobKFTM5jEHkSic2rKmwb5nU.wav"
},
"打字音效.wav": {
"u": "https://cdn.jkwljy.com/pk-math/4153quBKosW4xvgWAM4EqTtZqjNM.wav",
"ossName": "/pk-math/4153quBKosW4xvgWAM4EqTtZqjNM.wav"
} }
} }
...@@ -27,5 +27,14 @@ export default { ...@@ -27,5 +27,14 @@ export default {
}, },
"错误.wav": { "错误.wav": {
"u": "https://cdn.jkwljy.com/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav" "u": "https://cdn.jkwljy.com/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav"
},
"引导页-A和B通关.wav": {
"u": "https://cdn.jkwljy.com/pk-math/39xS7n44dr7UfLvHkhAoTfkYVpgV.wav"
},
"猫猫说话背景声.wav": {
"u": "https://cdn.jkwljy.com/pk-math/3BsHxobKFTM5jEHkSic2rKmwb5nU.wav"
},
"打字音效.wav": {
"u": "https://cdn.jkwljy.com/pk-math/4153quBKosW4xvgWAM4EqTtZqjNM.wav"
} }
} as const } as const
...@@ -47,6 +47,7 @@ Component({ ...@@ -47,6 +47,7 @@ Component({
}, },
attached () { attached () {
this._tickTime = Date.now()
this._tick = this.data.startValue this._tick = this.data.startValue
this.start() this.start()
console.log(this) console.log(this)
...@@ -59,15 +60,17 @@ Component({ ...@@ -59,15 +60,17 @@ Component({
} }
}, },
getCount () { getCount () {
const bias = +((Date.now() - this._tickTime) / 1000).toFixed(1)
if (this.data.isDown) { if (this.data.isDown) {
return this.data.startValue - this._tick return this.data.startValue - this._tick + bias
} }
return this._tick return this._tick + bias
}, },
start () { start () {
this.stop() this.stop()
this._timer = setInterval(() => { this._timer = setInterval(() => {
this._tickTime = Date.now()
const isDown = this.data.isDown const isDown = this.data.isDown
if (isDown) { if (isDown) {
this._tick -= 1 this._tick -= 1
......
...@@ -7,7 +7,7 @@ const MainHeader = () => { ...@@ -7,7 +7,7 @@ const MainHeader = () => {
<View className={styles.chapter}> <View className={styles.chapter}>
<View className={styles.chapterContent}> <View className={styles.chapterContent}>
<View className={styles.chapterName}> <View className={styles.chapterName}>
<Text>第 1 单元</Text> <Text>第 1 部分</Text>
</View> </View>
<View className={styles.chapterTips}><Text>二年级下·上半学期</Text></View> <View className={styles.chapterTips}><Text>二年级下·上半学期</Text></View>
</View> </View>
......
...@@ -51,6 +51,22 @@ const Scene1 = ({ onNext }: Scene1Props) => { ...@@ -51,6 +51,22 @@ const Scene1 = ({ onNext }: Scene1Props) => {
} }
}, [onNext, isActive]) }, [onNext, isActive])
const fn = useCallback(() => {
setIsActive(true)
}, [])
const fn1 = useCallback(() => {
handleEnd(1)
}, [handleEnd])
const fn2 = useCallback(() => {
handleEnd(2)
}, [handleEnd])
const fn3 = useCallback(() => {
handleEnd(3)
}, [handleEnd])
return ( return (
<View className={cs.viewport}> <View className={cs.viewport}>
<View className={cs.viewport_body}> <View className={cs.viewport_body}>
...@@ -65,19 +81,19 @@ const Scene1 = ({ onNext }: Scene1Props) => { ...@@ -65,19 +81,19 @@ const Scene1 = ({ onNext }: Scene1Props) => {
<View className={styles.dialog}> <View className={styles.dialog}>
{current === 0 && ( {current === 0 && (
<View className={styles.modal_1}> <View className={styles.modal_1}>
<TextPrinter textList={Text1} onEnd={() => handleEnd(1)}></TextPrinter> <TextPrinter textList={Text1} onEnd={fn1}></TextPrinter>
</View> </View>
)} )}
{current === 1 && ( {current === 1 && (
<View className={styles.modal_2}> <View className={styles.modal_2}>
<TextPrinter textList={Text2} onEnd={() => handleEnd(2)} /> <TextPrinter textList={Text2} onEnd={fn2} />
</View> </View>
)} )}
{current === 2 && ( {current === 2 && (
<View className={styles.modal_2}> <View className={styles.modal_2}>
<TextPrinter <TextPrinter
textList={Text3} textList={Text3}
onEnd={() => handleEnd(3)} onEnd={fn3}
/> />
</View> </View>
)} )}
...@@ -85,7 +101,7 @@ const Scene1 = ({ onNext }: Scene1Props) => { ...@@ -85,7 +101,7 @@ const Scene1 = ({ onNext }: Scene1Props) => {
<View className={styles.modal_3}> <View className={styles.modal_3}>
<TextPrinter <TextPrinter
textList={Text4} textList={Text4}
onEnd={() => setIsActive(true)} onEnd={fn}
/> />
</View> </View>
)} )}
......
import { View, Text, Image, ScrollView } from '@tarojs/components' import { View, Text, Image, ScrollView } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import { useFormatTick } from '@/hooks' import { useFormatTick } from '@/hooks'
import { useMemo } from 'react' import { useMemo, useEffect } from 'react'
import { palyAudio } from '@/utils/play-audio'
import audio from '@/assets/oss/assets-audio'
import assets from '@/assets/oss/assets-guide' import assets from '@/assets/oss/assets-guide'
import cs from './index.module.scss' import cs from './index.module.scss'
...@@ -53,6 +55,12 @@ const Scene4 = (props: Scene4Props) => { ...@@ -53,6 +55,12 @@ const Scene4 = (props: Scene4Props) => {
const icons = useMemo(() => getIcon(level), [level]) const icons = useMemo(() => getIcon(level), [level])
useEffect(() => {
if (isCurrent) {
palyAudio(audio['引导页-A和B通关.wav'].u)
}
}, [isCurrent])
const isActive = true const isActive = true
const timeFmt = useFormatTick(time * 1000) const timeFmt = useFormatTick(time * 1000)
......
import { useState, useEffect, useRef } from 'react' import { useState, useEffect, useRef } from 'react'
import { Text } from '@tarojs/components' import { Text } from '@tarojs/components'
import { createInnerAudioContext } from '@tarojs/taro'
import audio from '@/assets/oss/assets-audio'
// @ts-ignore
const innerAudioContext = createInnerAudioContext({ useWebAudioImplement: true })
export function getAudio (src: string) {
innerAudioContext.src = src
innerAudioContext.loop = true
innerAudioContext.volume = 0.3
return innerAudioContext
}
type TextPrinterProps = { type TextPrinterProps = {
textList: { text: string }[]; textList: { text: string }[];
...@@ -18,6 +30,9 @@ const TextPrinter = (props: TextPrinterProps) => { ...@@ -18,6 +30,9 @@ const TextPrinter = (props: TextPrinterProps) => {
useEffect(() => { useEffect(() => {
let animationFrameId: number | null = null let animationFrameId: number | null = null
let lastFrameTime: number | null = null let lastFrameTime: number | null = null
const audioPlayer = getAudio(audio['打字音效.wav'].u)
audioPlayer.play()
const shouldDisplayNextChar = (timestamp: number, spd: number) => { const shouldDisplayNextChar = (timestamp: number, spd: number) => {
if (!lastFrameTime) { if (!lastFrameTime) {
...@@ -36,12 +51,16 @@ const TextPrinter = (props: TextPrinterProps) => { ...@@ -36,12 +51,16 @@ const TextPrinter = (props: TextPrinterProps) => {
const animateText = (timestamp) => { const animateText = (timestamp) => {
let currentText = textList[currentTextIndex.current] let currentText = textList[currentTextIndex.current]
if (!currentText) return if (!currentText) {
audioPlayer.stop()
return
}
if (charIndex.current >= currentText.text.length) { if (charIndex.current >= currentText.text.length) {
charIndex.current = 0 charIndex.current = 0
currentTextIndex.current += 1 currentTextIndex.current += 1
if (currentTextIndex.current >= textList.length) { if (currentTextIndex.current >= textList.length) {
onEnd && onEnd() onEnd && onEnd()
audioPlayer.stop()
return return
} }
/** 停顿 */ /** 停顿 */
...@@ -60,6 +79,7 @@ const TextPrinter = (props: TextPrinterProps) => { ...@@ -60,6 +79,7 @@ const TextPrinter = (props: TextPrinterProps) => {
animationFrameId = requestAnimationFrame(animateText) animationFrameId = requestAnimationFrame(animateText)
return () => { return () => {
audioPlayer.stop()
if (animationFrameId) { if (animationFrameId) {
cancelAnimationFrame(animationFrameId) cancelAnimationFrame(animationFrameId)
} }
......
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