Commit b5ddd076 authored by hewenhao's avatar hewenhao

feat: 答题页

parent dc082867
...@@ -41,4 +41,4 @@ ...@@ -41,4 +41,4 @@
"tabIndent": "insertSpaces", "tabIndent": "insertSpaces",
"tabSize": 2 "tabSize": 2
} }
} }
\ No newline at end of file
...@@ -49,7 +49,6 @@ export default { ...@@ -49,7 +49,6 @@ export default {
desc: '你的位置信息将用于小程序位置接口的效果展示', desc: '你的位置信息将用于小程序位置接口的效果展示',
}, },
}, },
lazyCodeLoading: "requiredComponents",
usingComponents: { usingComponents: {
"custom-wrapper": "./custom-wrapper" "custom-wrapper": "./custom-wrapper"
} }
......
...@@ -35,7 +35,6 @@ Component({ ...@@ -35,7 +35,6 @@ Component({
}, },
attached () { attached () {
console.log(this)
this._tick = 0 this._tick = 0
this.startCount() this.startCount()
}, },
...@@ -50,7 +49,6 @@ Component({ ...@@ -50,7 +49,6 @@ Component({
this.stop() this.stop()
this._timer = setInterval(() => { this._timer = setInterval(() => {
this._tick += 1 this._tick += 1
console.log(this.data.maxValue)
if (this._tick >= this.data.maxValue) { if (this._tick >= this.data.maxValue) {
this.stop() this.stop()
this.triggerEvent('timeup') this.triggerEvent('timeup')
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
display: inline-block; display: inline-block;
margin: 0 8px; margin: 0 8px;
vertical-align: middle; vertical-align: middle;
min-width: 56PX; min-width: 112px;
height: 56PX; height: 112px;
background: #F7F7F7; background: #F7F7F7;
border-radius: 16PX; border-radius: 32px;
border: 3PX solid #E5E5E5; border: 6px solid #E5E5E5;
font-size: 40PX; font-size: 80px;
font-family: HelveticaNeue-Medium, HelveticaNeue; font-family: HelveticaNeue-Medium, HelveticaNeue;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
line-height: 56PX; line-height: 112px;
text-align: center; text-align: center;
&.has_answer { &.has_answer {
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
} }
&.is_compare { &.is_compare {
border-radius: 28PX; border-radius: 56px;
border-color: rgba(23,134,247,0.5); border-color: rgba(23,134,247,0.5);
background-color: #F1F5FF; background-color: #F1F5FF;
} }
......
...@@ -5,16 +5,17 @@ import { useStoreState } from '@/store/hooks' ...@@ -5,16 +5,17 @@ import { useStoreState } from '@/store/hooks'
import styles from './count-up.module.scss' import styles from './count-up.module.scss'
const maxNum = 10 const speed = 4
const speed = 3
const maxDuration = maxNum * speed
const id = '_process__' const id = '_process__'
const CountUp = () => { const CountUp = () => {
const currentQuestionIndex = useStoreState(states => states.gameModel.currentQuestionIndex) const currentQuestionIndex = useStoreState(states => states.gameModel.currentQuestionIndex)
const questionList = useStoreState(state => state.gameModel.questionList)
const [width, setWidth] = useState(0) const [width, setWidth] = useState(0)
const questionLength = useMemo(() => {
return questionList.length
}, [questionList])
useEffect(() => { useEffect(() => {
const query = createSelectorQuery() const query = createSelectorQuery()
...@@ -31,15 +32,15 @@ const CountUp = () => { ...@@ -31,15 +32,15 @@ const CountUp = () => {
const roleStyle = useMemo(() => { const roleStyle = useMemo(() => {
return { return {
transform: `translateX(${width}px)`, transform: `translateX(${width}px)`,
transition: `transform ${maxNum * speed}s linear`, transition: `transform ${questionLength * speed}s linear`,
} }
}, [width]) }, [width, questionLength])
const processInnerStyle = useMemo(() => { const processInnerStyle = useMemo(() => {
return { return {
width: `${currentQuestionIndex * 100 / maxNum}%` width: `${currentQuestionIndex * 100 / questionLength}%`
} }
}, [currentQuestionIndex]) }, [currentQuestionIndex, questionLength])
const handleTimeUp = useCallback(() => { const handleTimeUp = useCallback(() => {
console.log('upd1') console.log('upd1')
......
import { View, Image, CustomWrapper } from '@tarojs/components' import { View, Image, CustomWrapper } from '@tarojs/components'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
import { useCallback } from 'react' import { useCallback, useMemo } from 'react'
import classNames from 'classnames' import classNames from 'classnames'
import styles from './page-footer.module.scss' import styles from './page-footer.module.scss'
...@@ -8,6 +8,10 @@ import styles from './page-footer.module.scss' ...@@ -8,6 +8,10 @@ import styles from './page-footer.module.scss'
const PageFooter = () => { const PageFooter = () => {
const currentQuestionIndex = useStoreState(states => states.gameModel.currentQuestionIndex) const currentQuestionIndex = useStoreState(states => states.gameModel.currentQuestionIndex)
const canGoNext = useStoreState(states => states.gameModel.canGoNext) const canGoNext = useStoreState(states => states.gameModel.canGoNext)
const questionList = useStoreState(states => states.gameModel.questionList)
const isLastQuestion = useMemo(() => {
return questionList.length === currentQuestionIndex + 1
}, [questionList, currentQuestionIndex])
const updateCurrentIndex = useStoreActions(actions => actions.gameModel.updateCurrentIndex) const updateCurrentIndex = useStoreActions(actions => actions.gameModel.updateCurrentIndex)
const clearUserAnswer = useStoreActions(actions => actions.gameModel.clearUserAnswer) const clearUserAnswer = useStoreActions(actions => actions.gameModel.clearUserAnswer)
...@@ -32,7 +36,7 @@ const PageFooter = () => { ...@@ -32,7 +36,7 @@ const PageFooter = () => {
className={classNames(styles.btn_right, !canGoNext && styles.disabled)} className={classNames(styles.btn_right, !canGoNext && styles.disabled)}
hoverClass={canGoNext ? styles.is_active : null} hoverClass={canGoNext ? styles.is_active : null}
onClick={handleGoNext} onClick={handleGoNext}
>下一题</View> >{isLastQuestion ? '提交' : '下一题'}</View>
</View> </View>
</View> </View>
</CustomWrapper> </CustomWrapper>
......
.content { .content {
font-size: 40PX;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
line-height: 49PX;
min-height: 100%; min-height: 100%;
font-size: 32px;
font-weight: 500;
color: #465164;
line-height: 56px;
&.is_sample { &.is_sample {
font-size: 80px;
display: flex; display: flex;
line-height: 112px;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
......
...@@ -21,7 +21,9 @@ const QuestionBlank = (props: QuestionBlankProps) => { ...@@ -21,7 +21,9 @@ const QuestionBlank = (props: QuestionBlankProps) => {
return ( return (
<View className={classNames(styles.content, styles.is_sample)}> <View className={classNames(styles.content, styles.is_sample)}>
{tree.map(item => renderRichText(item))} <View>
{tree.map(item => renderRichText(item))}
</View>
</View> </View>
) )
} }
......
.content { .content {
font-size: 16PX; font-size: 32px;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
line-height: 28PX; line-height: 58px;
&.is_sample { &.is_sample {
font-size: 40PX; font-size: 80px;
font-weight: 500; font-weight: 500;
line-height: 49PX; line-height: 98px;
padding-top: 48PX; padding-top: 96px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
} }
.option_wrap { .option_wrap {
padding: 32PX 16PX 0 16PX; padding: 64px 32px 0 32px;
} }
.option_item { .option_item {
margin-bottom: 12PX; margin-bottom: 24px;
background: #F0F2F9; background: #F0F2F9;
border-radius: 24px; border-radius: 24px;
display: flex; display: flex;
...@@ -39,15 +39,27 @@ ...@@ -39,15 +39,27 @@
} }
} }
.is_active {
.option_index {
color: #FFC056;
&::after {
background: #FFC056;
}
}
.option_content {
color: #FFC056;
}
}
.option_index { .option_index {
font-size: 20PX; font-size: 40px;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
line-height: 28PX; line-height: 56px;
padding: 5PX 6PX 5PX 14PX; padding: 10px 12px 10px 28px;
position: relative; position: relative;
width: 32PX; width: 64px;
height: 32PX; height: 64px;
text-align: center; text-align: center;
&::after { &::after {
...@@ -55,18 +67,18 @@ ...@@ -55,18 +67,18 @@
position: absolute; position: absolute;
right: 0; right: 0;
top: 50%; top: 50%;
width: 1PX; width: 2px;
height: 14PX; height: 28px;
background: rgba(70,81,100,0.3); background: rgba(70,81,100,0.3);
border-radius: 2px; border-radius: 2px;
margin-top: -7PX; margin-top: -14px;
} }
} }
.option_content { .option_content {
padding: 8PX 14PX 8PX 12PX; padding: 16px 28px 16px 24px;
font-size: 18PX; font-size: 36px;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
line-height: 25PX; line-height: 50px;
} }
...@@ -2,67 +2,66 @@ ...@@ -2,67 +2,66 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
padding-top: 32PX; padding-top: 64px;
padding-right: 30PX; padding-right: 60px;
} }
.top { .top {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
padding-right: 15PX; padding-right: 30px;
padding-bottom: 6PX; padding-bottom: 12px;
width: 228PX; width: 465px;
box-sizing: border-box; box-sizing: border-box;
} }
.center { .center {
font-size: 40PX; font-size: 80px;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
line-height: 49PX; line-height: 98px;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.divisor { .divisor {
width: 172PX; width: 344px;
height: 72PX; height: 144px;
background-image: url(../../assets/vertical-division.png); background-image: url(../../assets/vertical-division.png);
background-size: 100% 100%; background-size: 100% 100%;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 0 20PX 0 30PX; padding: 0 40px 0 60px;
box-sizing: border-box; box-sizing: border-box;
} }
.num_item { .num_item {
width: 56PX; width: 112px;
height: 56PX; height: 112px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.dividor { .dividor {
width: 56PX; width: 112px;
height: 56PX; height: 112px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.bottom { .bottom {
width: 162PX; width: 324px;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
margin-left: 66PX; margin-left: 132px;
padding: 0 20PX 12PX 20PX; padding: 0 30px 24px 40px;
margin-right: -10PX;
box-sizing: border-box; box-sizing: border-box;
position: relative; position: relative;
&::after { &::after {
height: 4PX; height: 8px;
background: rgba(23,134,247,0.9); background: rgba(23,134,247,0.9);
border-radius: 2PX; border-radius: 4px;
content: " "; content: " ";
position: absolute; position: absolute;
bottom: 0; bottom: 0;
...@@ -74,8 +73,8 @@ ...@@ -74,8 +73,8 @@
.footer { .footer {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
width: 228PX; width: 456px;
padding-right: 15PX; padding-right: 30px;
padding-top: 6PX; padding-top: 12px;
box-sizing: border-box; box-sizing: border-box;
} }
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
} }
.plain { .plain {
line-height: 30px; vertical-align: middle;
} }
.table { .table {
......
export default definePageConfig({ export default definePageConfig({
navigationBarTitleText: 'pk-math', navigationBarTitleText: 'pk-math',
navigationStyle: 'custom', navigationStyle: 'custom',
renderer: 'skyline', // renderer: 'skyline',
usingComponents: { usingComponents: {
'count-up-time': '../../../native-components/count-up/index' 'count-up-time': '../../../native-components/count-up/index'
} }
......
...@@ -37,6 +37,13 @@ const str = '<p>随着人们生活质量的提高,净水器已经慢慢走入 ...@@ -37,6 +37,13 @@ const str = '<p>随着人们生活质量的提高,净水器已经慢慢走入
const gameModel: GameModel = { const gameModel: GameModel = {
questionList: [ questionList: [
{
contentText: '<p>下面式子最大能填几</p><p>2109>210<AnswerBlank index="0" /></p>',
questionType: '填空题',
answers: [
{ sort: 0, contentText: '8' },
]
},
{ {
questionItems: [ questionItems: [
{ sort: 0, contentText: '57' }, { sort: 0, contentText: '57' },
...@@ -146,9 +153,17 @@ const gameModel: GameModel = { ...@@ -146,9 +153,17 @@ const gameModel: GameModel = {
}), }),
clearUserAnswer: action((state) => { clearUserAnswer: action((state) => {
state.questionList[state.currentQuestionIndex]?.answers?.forEach(item => { const currentQuestion = state.questionList[state.currentQuestionIndex]
item.userAnswer = undefined if (currentQuestion && isSelectionQuestion(currentQuestion)) {
}) currentQuestion.options.forEach(item => {
item.userAnswer = false
})
} else {
state.questionList[state.currentQuestionIndex]?.answers?.forEach(item => {
item.userAnswer = undefined
})
}
state.currentInputIndex = 0
}), }),
currentQuestion: computed([ currentQuestion: computed([
......
...@@ -66,3 +66,20 @@ export type RandomQuestionItem = { ...@@ -66,3 +66,20 @@ export type RandomQuestionItem = {
contentText: '$input' | `${number}`; contentText: '$input' | `${number}`;
sort: number; sort: number;
} }
/**
*
*
填空: <AnswerBlank index="0" /> <AnswerBlank index="1" />...
比较: <AnswerBlank index="0" compare="1" />
=: <MathSymbol value="=" />
+:<MathSymbol value="+" />
-:<MathSymbol value="-" />
*:<MathSymbol value="*" />
/: <MathSymbol value="/" />
%: <MathSymbol value="%" />
>: <MathSymbol value=">" />
<: <MathSymbol value="<" />
比较里面的=: <MathSymbol value="=2" />
*/
import { Image } from '@tarojs/components' import { Image } from '@tarojs/components'
import { useEffect, useRef, useMemo } from 'react' import { useEffect, useRef, useMemo } from 'react'
import assets from '@/assets/oss/assets-round' import assets from '@/assets/oss/assets-round'
import { usePageScroll, createIntersectionObserver, getCurrentInstance, getMenuButtonBoundingClientRect, IntersectionObserver } from '@tarojs/taro' import { usePageScroll, createIntersectionObserver, getCurrentInstance, getMenuButtonBoundingClientRect, IntersectionObserver, nextTick } from '@tarojs/taro'
type RoundTagProps = { type RoundTagProps = {
url?: string; url?: string;
...@@ -24,60 +24,64 @@ const RoundTag = (props: RoundTagProps) => { ...@@ -24,60 +24,64 @@ const RoundTag = (props: RoundTagProps) => {
useEffect(() => { useEffect(() => {
let observer: IntersectionObserver | null = null let observer: IntersectionObserver | null = null
if (ready) { const fn = () => {
const navVal = nav.current if (ready) {
// @ts-ignore const navVal = nav.current
observer = createIntersectionObserver() // @ts-ignore
let isAnimated = false observer = createIntersectionObserver()
const animateBg = () => { let isAnimated = false
const page = getCurrentInstance().page const animateBg = () => {
page?.animate?.(`#${bgid}`, [ const page = getCurrentInstance().page
{ opacity: 1 }, page?.animate?.(`#${bgid}`, [
{ opacity: 0 }, { opacity: 1 },
], 700, () => { { opacity: 0 },
observer?.disconnect() ], 700, () => {
observer = null observer?.disconnect()
}) observer = null
}
let timer: NodeJS.Timeout | null = null
if (url) {
observer
.relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 })
.observe(`#${uid}`, ({ intersectionRatio }) => {
if (intersectionRatio > 0) {
if (isAnimated) return
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
isAnimated = true
getCurrentInstance().page?.animate?.(`#${uid}`, [
{ opacity: 0, translateY: 50, scale: [1, 1] },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.5 },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.75 },
{ opacity: 1, translateY: 0, scale: [1, 1] },
], 600, animateBg)
}, 500)
}
}) })
} else { }
observer let timer: NodeJS.Timeout | null = null
.relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 }) if (url) {
.observe(`#${bgid}`, ({ intersectionRatio }) => { observer
if (intersectionRatio > 0) { .relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 })
if (isAnimated) return .observe(`#${uid}`, ({ intersectionRatio }) => {
if (timer) { if (intersectionRatio > 0) {
clearTimeout(timer) if (isAnimated) return
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
isAnimated = true
getCurrentInstance().page?.animate?.(`#${uid}`, [
{ opacity: 0, translateY: 50, scale: [1, 1] },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.5 },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.75 },
{ opacity: 1, translateY: 0, scale: [1, 1] },
], 1000, animateBg)
}, 500)
} }
timer = setTimeout(() => { })
isAnimated = true } else {
animateBg() observer
}, 900) .relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 })
} .observe(`#${bgid}`, ({ intersectionRatio }) => {
}) if (intersectionRatio > 0) {
if (isAnimated) return
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
isAnimated = true
animateBg()
}, 900)
}
})
}
} }
} }
nextTick(fn)
return () => { return () => {
if (observer) { if (observer) {
observer.disconnect() observer.disconnect()
......
...@@ -2,6 +2,7 @@ import { View, Image } from '@tarojs/components' ...@@ -2,6 +2,7 @@ import { View, Image } from '@tarojs/components'
import assets from '@/assets/oss/assets-round' import assets from '@/assets/oss/assets-round'
import classNames from 'classnames' import classNames from 'classnames'
import { cs } from '@/styles' import { cs } from '@/styles'
import { navigateTo } from '@tarojs/taro'
import { RoundState, type Round, RoundType, type ImageSource, RoundScore, CurrentRoundId, SceneContext } from './constants' import { RoundState, type Round, RoundType, type ImageSource, RoundScore, CurrentRoundId, SceneContext } from './constants'
import RoundTag from './round-tag' import RoundTag from './round-tag'
...@@ -141,7 +142,12 @@ const RoundComp = (props: RoundProps) => { ...@@ -141,7 +142,12 @@ const RoundComp = (props: RoundProps) => {
return ( return (
<SceneContext.Consumer> <SceneContext.Consumer>
{({ ready }) => ( {({ ready }) => (
<View className={classNames(props.className, cs.bounce_btn)} hoverClass={cs.bounce_btn_hover} id={round.state === RoundState.UnLocked ? CurrentRoundId : undefined}> <View
className={classNames(props.className, cs.bounce_btn)}
hoverClass={cs.bounce_btn_hover}
id={round.state === RoundState.UnLocked ? CurrentRoundId : undefined}
onClick={() => navigateTo({ url: '/pages/game/play/index' })}
>
{renderRound(ready)} {renderRound(ready)}
<View className={styles.roundName}>{round.name}</View> <View className={styles.roundName}>{round.name}</View>
</View> </View>
......
.viewport {
min-height: 100vh;
}
.body { .body {
position: relative; position: relative;
......
...@@ -37,19 +37,19 @@ const MainPage = () => { ...@@ -37,19 +37,19 @@ const MainPage = () => {
}, [scrollToCurrent]) }, [scrollToCurrent])
return ( return (
<View className={styles.viewport}> <>
<MainHeader /> <MainHeader />
<View className={styles.body} style={{ paddingTop: `${nav.height + nav.top + 5}px` }}> <View className={styles.body} style={{ paddingTop: `${nav.height + nav.top + 5}px` }}>
<MainChapter /> <MainChapter />
<SceneContext.Provider value={{ ready: isReady }}> <SceneContext.Provider value={{ ready: isReady }}>
<MainScene /> <MainScene />
</SceneContext.Provider> </SceneContext.Provider>
{/* <View className={styles.gap}></View> */} <View className={styles.gap}></View>
</View> </View>
{isReady && ( {isReady && (
<MainShortCut onClick={() => scrollToCurrent()} /> <MainShortCut onClick={() => scrollToCurrent()} />
)} )}
</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