Commit b5ddd076 authored by hewenhao's avatar hewenhao

feat: 答题页

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