Commit 247e14c0 authored by hewenhao's avatar hewenhao

feat: update

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