Commit 4bd66770 authored by m's avatar m
parents b9057fa7 f04517f1
......@@ -69,6 +69,10 @@ const config = {
from: path.resolve(__dirname, '../src/assets/tabbar/'),
to: path.resolve(__dirname, `../${outputRoot}/assets/tabbar/`)
},
// {
// from: path.resolve(__dirname, '../src/native-components/'),
// to: path.resolve(__dirname, `../${outputRoot}/native-components/`)
// },
],
options: {
}
......
......@@ -11,6 +11,15 @@ declare module '*.scss';
declare module '*.sass';
declare module '*.styl';
type CountUptime = React.FC<{ maxNum }>
declare namespace JSX{
interface IntrinsicElements{
// 扩展 IntrinsicElements 否则无法识别自定义标签
'count-up-time': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { 'max-value'?: number, onTimeup?: () => void }, HTMLElement>
}
}
declare namespace NodeJS {
interface ProcessEnv {
TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
......
......@@ -18,13 +18,25 @@
"condition": false
},
"libVersion": "2.30.2",
"condition": {
"miniprogram": {
"list": [
{
"name": "",
"pathName": "pages/game/play/index",
"query": "",
"launchMode": "default",
"scene": null
}
]
}
},
"compileType": "miniprogram",
"srcMiniprogramRoot": "dist/",
"packOptions": {
"ignore": [],
"include": []
},
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
......
......@@ -49,4 +49,7 @@ export default {
desc: '你的位置信息将用于小程序位置接口的效果展示',
},
},
usingComponents: {
"custom-wrapper": "./custom-wrapper"
}
}
import { useState, useMemo } from 'react'
type UseBooleanRet = [
boolean,
{
toggle: () => void,
setTrue: () => void,
setFalse: () => void
}
]
function useBoolean (initValue: boolean): UseBooleanRet {
const [value, setVal] = useState(initValue)
const actions = useMemo(() => {
const toggle = () => setVal((v) => !v)
const setTrue = () => setVal(true)
const setFalse = () => setVal(false)
return { toggle, setFalse, setTrue }
}, [])
return [value, actions]
}
export { useBoolean }
import {
useState, useCallback, useRef, useEffect,
} from 'react'
export function useCountdown (
tick: number,
onTimeup: () => void,
{ duration = 1000, unit = 1 } = {},
): [
number,
(val?: number) => void,
() => void
] {
const [t, setT] = useState(tick)
const tRef = useRef(tick)
const timerRef = useRef<NodeJS.Timer | null>(null)
const stopTick = useCallback(() => {
if (timerRef.current) {
clearInterval(timerRef.current)
timerRef.current = null
}
}, [])
const updateTick = useCallback(() => {
const target = tRef.current - unit
if (target <= 0) {
onTimeup && onTimeup()
stopTick()
}
tRef.current = target
setT(target)
}, [onTimeup, stopTick, unit])
const startTick = useCallback((val?: number) => {
stopTick()
const target = val !== undefined ? val : tick
tRef.current = target
setT(target)
timerRef.current = setInterval(() => {
updateTick()
}, duration)
}, [stopTick, duration, updateTick, tick])
useEffect(() => () => {
if (timerRef.current) {
clearInterval(timerRef.current)
}
}, [])
return [t, startTick, stopTick]
}
import { useMemo } from 'react'
const pad = (val) => {
if (val < 0) return '00'
return `00${parseInt(val, 10)}`.slice(-2)
}
function getDay (tick) {
return Math.floor(tick / 24 / 60 / 60 / 1000)
}
function getHours (tick) {
return pad(Math.floor((tick % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)))
}
function getMinutes (tick) {
return pad(Math.floor((tick % (60 * 60 * 1000)) / (60 * 1000)))
}
function getSeconds (tick) {
return pad(Math.floor((tick % (60 * 1000)) / 1000))
}
const useFormatTick = (val: number) => useMemo(() => {
const _val = Number.isNaN(val) ? 0 : val
const day = getDay(_val)
const hours = getHours(_val)
const minutes = getMinutes(_val)
const seconds = getSeconds(_val)
return {
day, hours, minutes, seconds,
}
}, [val])
export { useFormatTick }
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
const pad = (val) => {
if (val < 0) return '00'
return `00${parseInt(val, 10)}`.slice(-2)
}
// function getDay (tick) {
// return Math.floor(tick / 24 / 60 / 60 / 1000)
// }
// function getHours (tick) {
// return pad(Math.floor((tick % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)))
// }
function getMinutes (tick) {
return pad(Math.floor((tick % (60 * 60 * 1000)) / (60 * 1000)))
}
function getSeconds (tick) {
return pad(Math.floor((tick % (60 * 1000)) / 1000))
}
Component({
properties: {
maxValue: {
type: Number,
value: 100 * 60 * 60
},
},
data: {
minutes: '00',
seconds: '00'
},
attached () {
this._tick = 0
this.startCount()
},
methods: {
stop () {
if (this._timer) {
clearInterval(this._timer)
}
},
startCount () {
this.stop()
this._timer = setInterval(() => {
this._tick += 1
if (this._tick >= this.data.maxValue) {
this.stop()
this.triggerEvent('timeup')
}
const { minutes, seconds } = this.data
const val = this._tick * 1000
const opts = {}
const nowM = getMinutes(val)
const nowS = getSeconds(val)
if (minutes !== nowM) {
opts.minutes = nowM
}
if (seconds !== nowS) {
opts.seconds = nowS
}
this.setData(opts)
}, 1000)
},
onMyButtonTap: function () {
this.setData({
// 更新属性和数据的方法与更新页面数据的方法类似
})
},
}
})
<text>{{minutes}}:{{seconds}}</text>
.blank {
text-decoration: underline;
display: inline-block;
width: 60PX;
height: 30PX;
margin: 0 8px;
border: 1px solid;
vertical-align: middle;
min-width: 112px;
height: 112px;
background: #F7F7F7;
border-radius: 32px;
border: 6px solid #E5E5E5;
font-size: 80px;
font-family: HelveticaNeue-Medium, HelveticaNeue;
font-weight: 500;
color: #465164;
line-height: 112px;
text-align: center;
&.has_answer {
border-color: rgba(23,134,247,0.5);
background-color: #F1F5FF;
}
&.is_active {
border-color: #FFC056;
background-color: #FFF5E3;
}
&.is_compare {
border-radius: 56px;
border-color: rgba(23,134,247,0.5);
background-color: #F1F5FF;
}
}
import { View } from '@tarojs/components'
import { View, CustomWrapper } from '@tarojs/components'
import { useMemo } from 'react'
import classNames from 'classnames'
import { useStoreActions, useStoreState } from '@/store/hooks'
import styles from './answer-blank.module.scss'
const AnswerBlank = () => {
type AnswerBlankProps = {
index: number;
isCompare?: boolean;
}
const AnswerBlank = (props: AnswerBlankProps) => {
const { index, isCompare } = props
const questionAnswers = useStoreState(state => state.gameModel.questionAnswers)
const currentInputIndex = useStoreState(state => state.gameModel.currentInputIndex)
const updateCurrentInputIndex = useStoreActions(actions => actions.gameModel.updateCurrentInputIndex)
const currentInput = useMemo(() => {
return questionAnswers?.[index]?.userAnswer ?? ''
}, [questionAnswers, index])
const isCurrent = useMemo(() => index === currentInputIndex, [index, currentInputIndex])
return (
<View className={styles.blank}></View>
<CustomWrapper>
<View
className={classNames(styles.blank, isCompare && styles.is_compare, currentInput && styles.has_answer, isCurrent && styles.is_active)}
onClick={() => updateCurrentInputIndex(index)}
>{currentInput}</View>
</CustomWrapper>
)
}
......
.count {
padding: 40px 32px 100px 32px;
display: flex;
align-items: center;
}
.process {
flex: 1;
background-color: #F0F2F9;
border-radius: 14px;
position: relative;
}
.process_inner {
height: 28px;
background-color: #1786F7;
border-radius: 14px;
transition: width .3s linear;
}
.time {
display: flex;
align-items: center;
margin-left: 32px;
font-size: 36px;
font-weight: 500;
color: #465164;
line-height: 46px;
.icon {
width: 32px;
height: 32px;
margin-right: 12px;
}
}
.role {
position: absolute;
left: 0;
top: -8px;
margin-left: -40px;
transform: translateX(0px);
.tick {
width: 6px;
border-radius: 3px;
height: 48px;
background-color: #FE9B45;
margin: 0 auto;
}
.tips {
position: absolute;
background: #FE9B45;
border-radius: 0px 12px 12px 0px;
color: #fff;
bottom: 20px;
left: 66px;
white-space: nowrap;
padding: 4px 8px 2px 12px;
z-index: 1;
font-size: 24px;
font-weight: 600;
line-height: 34px;
}
}
.cat {
width: 80px;
height: 80px;
position: relative;
z-index: 2;
display: block;
}
import { View, Image } from '@tarojs/components'
import { useState, useEffect, useCallback, useMemo } from 'react'
import { createSelectorQuery } from '@tarojs/taro'
import { useStoreState } from '@/store/hooks'
import styles from './count-up.module.scss'
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()
query.select(`#${id}`)
.boundingClientRect()
.exec((res) => {
console.log(res)
if (res[0]) {
setWidth(res[0].width)
}
})
}, [])
const roleStyle = useMemo(() => {
return {
transform: `translateX(${width}px)`,
transition: `transform ${questionLength * speed}s linear`,
}
}, [width, questionLength])
const processInnerStyle = useMemo(() => {
return {
width: `${currentQuestionIndex * 100 / questionLength}%`
}
}, [currentQuestionIndex, questionLength])
const handleTimeUp = useCallback(() => {
console.log('upd1')
}, [])
return (
<View className={styles.count}>
<View className={styles.process} id={id}>
<View className={styles.process_inner} style={processInnerStyle}></View>
<View className={styles.role} style={roleStyle}>
<View className={styles.tick}></View>
<Image src={require('../assets/count-cat.png')} className={styles.cat}></Image>
<View className={styles.tips}>通关要求</View>
</View>
</View>
<View className={styles.time}>
<Image src={require('../assets/count-time.png')} className={styles.icon}></Image>
<count-up-time max-value={60 * 60} onTimeup={handleTimeUp} />
</View>
</View>
)
}
export default CountUp
.symbol {
width: 40px;
height: 40px;
margin: 0 8PX;
&.is_remaind {
width: 92px;
}
&.is_pair {
width: 60px;
height: 60px;
}
}
/* eslint-disable import/no-commonjs */
import { Image } from '@tarojs/components'
import { useMemo, memo } from 'react'
import classNames from 'classnames'
import styles from './math-symbol.module.scss'
const SymbolMap = {
'+': require('../assets/math-symbol/add.png'),
'-': require('../assets/math-symbol/minus.png'),
'*': require('../assets/math-symbol/product.png'),
'/': require('../assets/math-symbol/divide.png'),
'%': require('../assets/math-symbol/remaind.png'),
'>': require('../assets/math-symbol/greater.png'),
'<': require('../assets/math-symbol/less.png'),
'=': require('../assets/math-symbol/equal.png'),
'=2': require('../assets/math-symbol/equal-2.png'),
} as const
type MathSymbolProps = {
value: '*' | '+' | '-' | '/' | '%' | '>' | '<' | '=' | '=2'
}
const MathSymbol = ({ value }: MathSymbolProps) => {
const url = useMemo(() => {
return SymbolMap[value]
}, [value])
const isPair = useMemo(() => {
return ['<', '>', '=2'].includes(value)
}, [value])
return (
<Image src={url} className={classNames(styles.symbol, value === '%' && styles.is_remaind, isPair && styles.is_pair)}></Image>
)
}
export default memo(MathSymbol)
.keyboard {
padding: 16px 34px 0 36px;
margin-bottom: -32px;
margin-right: -20px;
display: flex;
flex-wrap: wrap;
}
.keyboard_item {
width: 120px;
height: 120px;
margin-right: 20px;
margin-bottom: 32px;
display: flex;
align-items: center;
justify-content: center;
font-size: 52px;
font-weight: 500;
color: #465164;
background-image: url(../assets//keyboard.png);
background-size: 100% 100%;
&.is_active {
color: #ffffff;
background-image: url(../assets//keyboard-active.png);
}
}
import { View } from '@tarojs/components'
import { useStoreActions } from '@/store/hooks'
import { memo } from 'react'
import styles from './number-keyboard.module.scss'
const alphbet = '1234567890'.split('')
const NumberKeyboard = () => {
const updateUserAnswer = useStoreActions(actions => actions.gameModel.updateUserAnswer)
console.log('memo1')
return (
<View className={styles.keyboard}>
{alphbet.map(item => {
return (
<View key={item} className={styles.keyboard_item} hoverClass={styles.is_active} onClick={() => updateUserAnswer(item)}>{item}</View>
)
})}
</View>
)
}
export default memo(NumberKeyboard)
.footer {
background-color: #fff;
}
@supports (padding-bottom: constant(safe-area-inset-bottom)) or (padding-bottom: env(safe-area-inset-bottom)) {
.footer {
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom : env(safe-area-inset-bottom);
}
}
.footer_inner {
display: flex;
align-items: center;
padding: 32px 34px 32px 34px;
.btn_right {
flex: 1;
height: 112px;
background-image: url(../assets/btn-next.png);
background-size: 100% 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 40px;
font-weight: 500;
color: #FFFFFF;
line-height: 56px;
&.is_active {
background-image: url(../assets//btn-next-active.png);
}
&.disabled {
background-image: none;
background-color: #E2E6ED;
color: #C2C8D1;
border-radius: 32px;
}
}
.btn_left {
margin-right: 20px;
width: 260px;
height: 112px;
background-image: url(../assets/btn-clear.png);
background-size: 100% 100%;
font-size: 40px;
font-weight: 500;
color: #FFFFFF;
line-height: 56px;
display: flex;
align-items: center;
justify-content: center;
&.is_active {
background-image: url(../assets//btn-clear-active.png);
}
}
}
.icon {
width: 48px;
height: 48px;
margin-right: 12px;
}
import { View, Image, CustomWrapper } from '@tarojs/components'
import { useStoreState, useStoreActions } from '@/store/hooks'
import { useCallback, useMemo } from 'react'
import classNames from 'classnames'
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)
const handleGoNext = useCallback(() => {
if (!canGoNext) return
updateCurrentIndex(currentQuestionIndex + 1)
}, [canGoNext, updateCurrentIndex, currentQuestionIndex])
return (
<CustomWrapper>
<View className={styles.footer}>
<View className={styles.footer_inner}>
<View
className={styles.btn_left}
hoverClass={styles.is_active}
onClick={() => clearUserAnswer()}
>
<Image src={require('../assets/btn-clear-icon.png')} className={styles.icon}></Image>
清除
</View>
<View
className={classNames(styles.btn_right, !canGoNext && styles.disabled)}
hoverClass={canGoNext ? styles.is_active : null}
onClick={handleGoNext}
>{isLastQuestion ? '提交' : '下一题'}</View>
</View>
</View>
</CustomWrapper>
)
}
export default PageFooter
.header {
background-color: #ffffff;
}
.inner {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.arrow {
position: absolute;
left: 10PX;
width: 30PX;
height: 30PX;
}
import { View, Image, Text } from '@tarojs/components'
import { getMenuButtonBoundingClientRect } from '@tarojs/taro'
import { useState, memo } from 'react'
import { useStoreState } from '@/store/hooks'
import styles from './page-head.module.scss'
const PageHead = () => {
const [nav] = useState(getMenuButtonBoundingClientRect())
const questionList = useStoreState(states => states.gameModel.questionList)
const currentQuestionIndex = useStoreState(states => states.gameModel.currentQuestionIndex)
console.log('rr')
return (
<View className={styles.header}>
<View
style={{
height: `${nav.height + 10}px`,
paddingTop: `${nav.top - 5}px`
}}
>
<View className={styles.inner} style={{ height: `${nav.height + 10}px` }}>
<Image src={require('../assets/arrow.png')} className={styles.arrow}></Image>
<Text>{currentQuestionIndex + 1}/{questionList.length}</Text>
</View>
</View>
</View>
)
}
export default memo(PageHead)
import { View } from '@tarojs/components'
import QuestionBlank from './question-blank'
import QuestionSelection from './question-selection'
import QuestionVerticalDivision from './question-vertical-division'
import { type QuestionType, isBlankQuestion } from '../types'
import {
type QuestionType,
isBlankQuestion,
isSelectionQuestion,
isVerticalDivisionQuestion
} from '../../types'
type QuestionProps = {
question: QuestionType
......@@ -9,8 +16,23 @@ type QuestionProps = {
const Question = (props: QuestionProps) => {
const { question } = props
if (isBlankQuestion(question)) {
return <QuestionBlank question={question} />
return (
<QuestionBlank question={question} />
)
}
if (isSelectionQuestion(question)) {
return (
<QuestionSelection question={question} />
)
}
if (isVerticalDivisionQuestion(question)) {
return (
<QuestionVerticalDivision question={question} />
)
}
return (
......
.content {
font-weight: 500;
color: #465164;
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;
}
}
/** 填空题 */
import { View } from '@tarojs/components'
import { useMemo } from 'react'
import htmlParser from 'html-parse-stringify'
import classNames from 'classnames'
import type { BlankQuestion } from '../../types'
import { renderRichText } from './render-tichtext'
import styles from './question-blank.module.scss'
type QuestionBlankProps = {
question: BlankQuestion
}
const QuestionBlank = (props: QuestionBlankProps) => {
const { question } = props
const tree = useMemo(() => {
return htmlParser.parse(question.contentText)
}, [question.contentText])
return (
<View className={classNames(styles.content, styles.is_sample)}>
<View>
{tree.map(item => renderRichText(item))}
</View>
</View>
)
}
export default QuestionBlank
.content {
font-size: 32px;
font-weight: 500;
color: #465164;
line-height: 58px;
&.is_sample {
font-size: 80px;
font-weight: 500;
line-height: 98px;
padding-top: 96px;
display: flex;
align-items: center;
justify-content: center;
}
}
.option_wrap {
padding: 64px 32px 0 32px;
}
.option_item {
margin-bottom: 24px;
background: #F0F2F9;
border-radius: 24px;
display: flex;
align-items: center;
border: 6px solid transparent;
box-sizing: border-box;
&.is_active {
background: #FFF5E3;
border-color:#FFC056;
}
&:last-child {
margin-bottom: 0;
}
}
.is_active {
.option_index {
color: #FFC056;
&::after {
background: #FFC056;
}
}
.option_content {
color: #FFC056;
}
}
.option_index {
font-size: 40px;
font-weight: 500;
color: #465164;
line-height: 56px;
padding: 10px 12px 10px 28px;
position: relative;
width: 64px;
height: 64px;
text-align: center;
&::after {
content: " ";
position: absolute;
right: 0;
top: 50%;
width: 2px;
height: 28px;
background: rgba(70,81,100,0.3);
border-radius: 2px;
margin-top: -14px;
}
}
.option_content {
padding: 16px 28px 16px 24px;
font-size: 36px;
font-weight: 500;
color: #465164;
line-height: 50px;
}
/** 选择题 */
import { View } from '@tarojs/components'
import { useMemo } from 'react'
import htmlParser from 'html-parse-stringify'
import classNames from 'classnames'
import { useStoreActions } from '@/store/hooks'
import { renderRichText } from './render-tichtext'
import type { SelectionQuestion, QuestionOption } from '../../types'
import styles from './question-selection.module.scss'
type QuestionSelectionProps = {
question: SelectionQuestion
}
type QuestionOptionItemProps = {
option: QuestionOption,
index: number;
}
const QuestionOptionItem = (props: QuestionOptionItemProps) => {
const { option, index } = props
const tree = useMemo(() => {
return htmlParser.parse(option.contentText)
}, [option.contentText])
const updateSelectionAnswer = useStoreActions(actions => actions.gameModel.updateSelectionAnswer)
return (
<View className={classNames(styles.option_item, option.userAnswer && styles.is_active)} onClick={() => updateSelectionAnswer(index)}>
<View className={styles.option_index}>{option.index}</View>
<View className={styles.option_content}>
{tree.map(item => renderRichText(item))}
</View>
</View>
)
}
const QuestionSelection = (props: QuestionSelectionProps) => {
const { question } = props
const tree = useMemo(() => {
return htmlParser.parse(question.contentText)
}, [question.contentText])
return (
<>
<View className={classNames(styles.content, styles.is_sample)}>
{tree.map(item => renderRichText(item))}
</View>
<View className={styles.option_wrap}>
{question.options.map((item, index) => {
return (
<QuestionOptionItem option={item} key={item.index} index={index} />
)
})}
</View>
</>
)
}
export default QuestionSelection
.content {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 64px;
padding-right: 60px;
}
.top {
display: flex;
justify-content: flex-end;
padding-right: 30px;
padding-bottom: 12px;
width: 465px;
box-sizing: border-box;
}
.center {
font-size: 80px;
font-weight: 500;
color: #465164;
line-height: 98px;
display: flex;
align-items: center;
}
.divisor {
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 40px 0 60px;
box-sizing: border-box;
}
.num_item {
width: 112px;
height: 112px;
display: flex;
align-items: center;
justify-content: center;
}
.dividor {
width: 112px;
height: 112px;
display: flex;
align-items: center;
justify-content: center;
}
.bottom {
width: 324px;
display: flex;
justify-content: flex-end;
margin-left: 132px;
padding: 0 30px 24px 40px;
box-sizing: border-box;
position: relative;
&::after {
height: 8px;
background: rgba(23,134,247,0.9);
border-radius: 4px;
content: " ";
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
}
.footer {
display: flex;
justify-content: flex-end;
width: 456px;
padding-right: 30px;
padding-top: 12px;
box-sizing: border-box;
}
/** 填空题 */
import { View, Text } from '@tarojs/components'
import { useMemo } from 'react'
import classNames from 'classnames'
import { useStoreActions } from '@/store/hooks'
import type { VerticalDivisionQuestion } from '../../types'
import styles from './question-vertical-division.module.scss'
import AnswerBlank from '../answer-blank'
type QuestionSelectionProps = {
question: VerticalDivisionQuestion
}
const QuestionVerticalDivision = (props: QuestionSelectionProps) => {
const { question } = props
const numList = useMemo(() => {
return question.questionItems.find(c => c.sort === 0)?.contentText.split('') ?? []
}, [question.questionItems])
const B = useMemo(() => {
return question.questionItems.find(c => c.sort === 1)?.contentText
}, [question.questionItems])
return (
<View className={classNames(styles.content)}>
<View className={styles.top}>
<AnswerBlank index={0}></AnswerBlank>
</View>
<View className={styles.center}>
<View className={styles.dividor}>{B}</View>
<View className={styles.divisor}>
{numList.map((item, index) => (
<Text className={styles.num_item} key={index}>{item}</Text>
))}
</View>
</View>
<View className={styles.bottom}>
<AnswerBlank index={1}></AnswerBlank>
<AnswerBlank index={2}></AnswerBlank>
</View>
<View className={styles.footer}>
<AnswerBlank index={3}></AnswerBlank>
</View>
</View>
)
}
export default QuestionVerticalDivision
import { View, Text, Image } from '@tarojs/components'
import { useMemo } from 'react'
import htmlParser, { type Node } from 'html-parse-stringify'
import { type Node } from 'html-parse-stringify'
import cs from './rich-text.module.scss'
import AnswerBlank from './answer-blank'
import type { BlankQuestion } from '../types'
import AnswerBlank from '../answer-blank'
import MathSymbol from '../math-symbol'
type QuestionBlankProps = {
question: BlankQuestion
}
function renderNode (node: Node) {
export function renderRichText (node: Node) {
if (node.type === 'text') {
return (
<Text decode className={cs.plain}>{node.content}</Text>
......@@ -35,9 +30,9 @@ function renderNode (node: Node) {
const renderChildren = (filter?: string[]) => {
if (filter) {
return node.children?.filter(c => c.type === 'tag' && filter.includes(c.name)).map(renderNode)
return node.children?.filter(c => c.type === 'tag' && filter.includes(c.name)).map(renderRichText)
}
return node.children?.map(renderNode)
return node.children?.map(renderRichText)
}
if (!node.voidElement) {
......@@ -97,25 +92,18 @@ function renderNode (node: Node) {
}
if (node.name === 'AnswerBlank') {
const index = node.attrs.index ?? 0
const isCompare = node.attrs.compare === '1'
return (
<AnswerBlank />
<AnswerBlank index={+index} isCompare={isCompare} />
)
}
}
}
const QuestionBlank = (props: QuestionBlankProps) => {
const { question } = props
const tree = useMemo(() => {
return htmlParser.parse(question.contentText)
}, [question])
if (node.name === 'MathSymbol') {
const index = node.attrs.value as any
return (
<View>
{tree.map(item => renderNode(item))}
</View>
<MathSymbol value={index} />
)
}
}
}
export default QuestionBlank
......@@ -12,7 +12,7 @@
}
.plain {
line-height: 30px;
vertical-align: middle;
}
.table {
......
export default definePageConfig({
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom',
// renderer: 'skyline',
usingComponents: {
'count-up-time': '../../../native-components/count-up/index'
}
})
.viewport {
height: 100vh;
display: flex;
flex-direction: column;
}
.body {
flex: 1;
position: relative;
min-height: 0;
}
.body_inner {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
}
import { View } from '@tarojs/components'
import { useState } from 'react'
import { View, ScrollView } from '@tarojs/components'
import { useStoreState } from '@/store/hooks'
import htmlParser from 'html-parse-stringify'
import { QuestionContext } from './util'
import PageHead from './components/page-head'
import PageFooter from './components/page-footer'
import Question from './components/question'
import CountUp from './components/count-up'
import NumberKeyboard from './components/number-keyboard'
const str = '<p>随着人们生活质量的提高,净水器已经慢慢走入了普通百姓家庭,某电器公司销售每台进价分别为2000元、1700元的<i>A</i>、<i>B</i>两种型号的净水器,下表是近两周的销售情况:</p> \n<table border="1"> \n <thead> \n <tr class="header"> \n <th style="text-align: left;">销售时段</th> \n <th style="text-align: left;">销售数量</th> \n <th style="text-align: left;">销售收入</th> \n <th style="text-align: left;"></th> \n </tr> \n </thead> \n <tbody> \n <tr class="odd"> \n <td style="text-align: left;"></td> \n <td style="text-align: left;"><i>A</i>种型号</td> \n <td style="text-align: left;"><i>B</i>种型号</td> \n <td style="text-align: left;"></td> \n </tr> \n <tr class="even"> \n <td style="text-align: left;">第一周</td> \n <td style="text-align: left;">3台</td> \n <td style="text-align: left;">5台</td> \n <td style="text-align: left;">18000元</td> \n </tr> \n <tr class="odd"> \n <td style="text-align: left;">第二周</td> \n <td style="text-align: left;">4台</td> \n <td style="text-align: left;">10台</td> \n <td style="text-align: left;">31000元</td> \n </tr> \n </tbody> \n</table> \n<p>(1)求<i>A</i>,<i>B</i>两种型号的净水器的销售单价;</p> \n<p>(2)若电器公司准备用不多于54000元的金额在采购这两种型号的净水器共30台,求<i>A</i>种型号的净水器最多能采购多少台?</p> \n<p>(3)在(2)的条件下,公司销售完这30台净水器能否实现利润为12800元的目标?若能,请给出相应的采购方案;若不能,请说明理由.</p>'
console.log(htmlParser.parse(str))
const question = {
contentText: str,
questionType: '填空题',
answers: []
}
import styles from './index.module.scss'
const GamePlay = () => {
const [currentInputIndex, setCurrentInputIndex] = useState(0)
const currentQuestion = useStoreState(states => states.gameModel.currentQuestion)
return (
<View>
<QuestionContext.Provider value={{ current: currentInputIndex }}>
&nbsp;&nbsp;
<Question question={question} />
</QuestionContext.Provider>
<View className={styles.viewport}>
<PageHead />
<CountUp />
<ScrollView className={styles.body} scrollY>
{currentQuestion && (
<Question question={currentQuestion} />
)}
</ScrollView>
{currentQuestion?.questionType !== '选择题' && (
<NumberKeyboard />
)}
<PageFooter />
</View>
)
}
......
import {
action, Action, computed, Computed, Thunk, thunk
} from 'easy-peasy'
import { AppStoreModel } from '@/store/store-model'
import { QuestionType, QuestionAnswer, isSelectionQuestion, QuestionOption } from '../types'
export interface GameModel {
/** 题目列表 */
questionList: QuestionType[];
/** 当前题目 */
currentQuestion: Computed<GameModel, QuestionType | undefined>;
/** 当前题目下标 */
currentQuestionIndex: number;
/** 题目答案和用户答案 */
questionAnswers: Computed<GameModel, QuestionAnswer[] | undefined>;
/** 更新当前题目下标 */
updateCurrentIndex: Action<GameModel, number>;
/** 当前输入框下标 */
currentInputIndex: number;
/** 更新当前输入框下标 */
updateCurrentInputIndex: Action<GameModel, number>;
/** 更新用户输入 */
updateUserAnswer: Action<GameModel, string>;
/** 清空所有输入 */
clearUserAnswer: Action<GameModel, void>;
updateSelectionAnswer: Action<GameModel, number>;
/** 可以跳转下一题 */
canGoNext: Computed<GameModel, boolean>;
updateList: Action<GameModel, QuestionType[]>;
getQuestionList: Thunk<GameModel, number, void, AppStoreModel>;
}
const str = '<p>随着人们生活质量的提高,净水器已经慢慢走入了普通百姓家庭,某电器公司销售每台进价分别为2000元、1700元的<i>A</i>、<i>B</i>两种型号的净水器,下表是近两周的销售情况:</p> \n<table border="1"> \n <thead> \n <tr class="header"> \n <th style="text-align: left;">销售时段</th> \n <th style="text-align: left;"><AnswerBlank index="0" /></th> \n <th style="text-align: left;">销售收入</th> \n <th style="text-align: left;"></th> \n </tr> \n </thead> \n <tbody> \n <tr class="odd"> \n <td style="text-align: left;"><AnswerBlank index="1" /></td> \n <td style="text-align: left;"><i>A</i>种型号</td> \n <td style="text-align: left;"><i>B</i>种型号</td> \n <td style="text-align: left;"></td> \n </tr> \n <tr class="even"> \n <td style="text-align: left;">第一周</td> \n <td style="text-align: left;">3台</td> \n <td style="text-align: left;">5台</td> \n <td style="text-align: left;">18000元</td> \n </tr> \n <tr class="odd"> \n <td style="text-align: left;">第二周</td> \n <td style="text-align: left;">4台</td> \n <td style="text-align: left;">10台</td> \n <td style="text-align: left;">31000元</td> \n </tr> \n </tbody> \n</table> \n<p>(1)求<i>A</i>,<i>B</i>两种型号的净水器的销售单价;</p> \n<p>(2)若电器公司准备用不多于54000元的金额在采购这两种型号的净水器共30台,求<i>A</i>种型号的净水器最多能采购多少台?</p> \n<p>(3)在(2)的条件下,公司销售完这30台净水器能否实现利润为12800元的目标?若能,请给出相应的采购方案;若不能,请说明理由.</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' },
{ sort: 1, contentText: '8' }
],
questionType: '竖式除法',
answers: [
{ sort: 0, contentText: 'A' },
{ sort: 1, contentText: 'A' },
{ sort: 2, contentText: 'A' },
{ sort: 3, contentText: 'A' },
]
},
{
contentText: '7998<AnswerBlank index="0" compare="1" />7988',
questionType: '选择题',
answers: [
{ sort: 0, contentText: 'C' }
],
options: [
{
index: 'A',
contentText: '<b>&lt;</b>',
answer: false,
},
{
index: 'B',
contentText: '<b>=</b>',
answer: false,
},
{
index: 'C',
contentText: '<b>&gt;</b>',
answer: true,
},
]
},
{
contentText: '9<MathSymbol value="*" />9<MathSymbol value="=" /><AnswerBlank index="0" />',
questionType: '填空题',
answers: [
{ sort: 0, contentText: '4' }
]
},
{
contentText: '80<MathSymbol value="/" /><AnswerBlank index="0" /><MathSymbol value="=" /><AnswerBlank index="1" /><MathSymbol value="%" />8',
questionType: '填空题',
answers: [
{ sort: 0, contentText: '4' },
{ sort: 0, contentText: '6' },
]
},
{
contentText: str,
questionType: '填空题',
answers: [
{ sort: 0, contentText: '1' },
{ sort: 1, contentText: '2' },
]
},
],
currentInputIndex: 0,
currentQuestionIndex: 0,
updateCurrentInputIndex: action((state, num) => {
state.currentInputIndex = num
}),
questionAnswers: computed([
state => state.currentQuestion,
], (currentQuestion) => currentQuestion?.answers),
updateCurrentIndex: action((state, num) => {
state.currentQuestionIndex = num
state.currentInputIndex = 0
}),
canGoNext: computed((state) => {
const { questionList, currentQuestionIndex, questionAnswers } = state
const question = questionList[currentQuestionIndex]
if (question && isSelectionQuestion(question)) {
return question.options.some(c => c.userAnswer)
}
return questionAnswers?.every(c => !!c.userAnswer) ?? false
}),
updateSelectionAnswer: action((state, index) => {
const question = state.questionList[state.currentQuestionIndex]
if (isSelectionQuestion(question)) {
question.options = question.options.map((c, _index) => ({
...c,
userAnswer: _index === index
}))
}
}),
updateUserAnswer: action((state, char) => {
const index = state.currentInputIndex
const answers = state.questionList[state.currentQuestionIndex]?.answers
const val = answers?.[index]
if (answers && val) {
val.userAnswer = `${val.userAnswer || ''}${char}`
const maxLen = answers.length
state.questionList = state.questionList.slice()
if (answers.length > 1 && index < maxLen - 1) {
state.currentInputIndex += 1
}
}
}),
clearUserAnswer: action((state) => {
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([
state => state.questionList,
state => state.currentQuestionIndex,
], (list, index) => list[index]),
updateList: action((state, questionList) => {
state.questionList = questionList
}),
getQuestionList: thunk(async (actions, round, helpers) => {
try {
actions.updateList([])
} catch (err) {}
}),
}
export default gameModel
export type QuestionAnswer = {
contentText: string;
sort: number;
userAnswer?: string;
}
export interface QuestionItem {
questionType: string;
answers: { contentText: string; sort: number }[];
answers: QuestionAnswer[];
}
export interface BlankQuestion extends QuestionItem {
......@@ -26,7 +32,7 @@ export interface DivisionWithRemainderQuestion extends QuestionItem {
/** 竖式除法 */
export interface VerticalDivisionQuestion extends QuestionItem {
questionType: '竖式除法';
questionItems: [];
questionItems: [RandomQuestionItem, RandomQuestionItem];
}
/** 乘法 */
......@@ -41,13 +47,39 @@ export function isBlankQuestion (q: QuestionType): q is BlankQuestion {
return q?.questionType === '填空题'
}
export function isSelectionQuestion (q: QuestionType): q is SelectionQuestion {
return q?.questionType === '选择题'
}
export function isVerticalDivisionQuestion (q: QuestionType): q is VerticalDivisionQuestion {
return q?.questionType === '竖式除法'
}
export type QuestionOption = {
index: string;
contentText: string;
answer: boolean;
userAnswer?: boolean;
}
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 { createContext } from 'react'
export const QuestionContext = createContext({ current: 0 })
export const QuestionContext = createContext({
current: 0,
updateCurrent: (val: number) => {}
})
/** 乘法验证 */
export function validateMultiplication (multiplier: number, multiplicand: number, product: number) {
......
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,6 +24,7 @@ const RoundTag = (props: RoundTagProps) => {
useEffect(() => {
let observer: IntersectionObserver | null = null
const fn = () => {
if (ready) {
const navVal = nav.current
// @ts-ignore
......@@ -53,10 +54,10 @@ const RoundTag = (props: RoundTagProps) => {
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: -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)
], 1000, animateBg)
}, 500)
}
})
......@@ -77,6 +78,9 @@ const RoundTag = (props: RoundTagProps) => {
})
}
}
}
nextTick(fn)
return () => {
if (observer) {
......
......@@ -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>
</>
)
}
......
import gameModel from '@/pages/game/play/model'
import cartModel from './modules/cart'
import counterModel from './modules/counter'
import prepareModel from './modules/prepare'
......@@ -6,6 +7,7 @@ const appStoreModel = {
cartModel,
counterModel,
prepareModel,
gameModel,
}
export default appStoreModel
......
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