Commit 28824dd9 authored by hewenhao's avatar hewenhao

feat: update

parent 9a4fe75b
/// <reference types="@tarojs/taro" /> /// <reference types="@tarojs/taro" />
declare module '*.png'; declare module '*.png';
declare module '*.gif'; declare module '*.gif';
declare module '*.jpg'; declare module '*.jpg';
...@@ -10,8 +11,6 @@ declare module '*.scss'; ...@@ -10,8 +11,6 @@ declare module '*.scss';
declare module '*.sass'; declare module '*.sass';
declare module '*.styl'; declare module '*.styl';
type CountUptime = React.FC<{ maxNum }>
type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
'maxValue'?: number; 'maxValue'?: number;
'isDown'?: boolean; 'isDown'?: boolean;
...@@ -24,8 +23,12 @@ type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { ...@@ -24,8 +23,12 @@ type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
declare namespace JSX{ declare namespace JSX{
interface IntrinsicElements { interface IntrinsicElements {
// 扩展 IntrinsicElements 否则无法识别自定义标签 // 扩展 IntrinsicElements 否则无法识别自定义标签
'count-up-time': CountUpTime 'count-up-time': CountUpTime;
'number-keyboard': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
onType?: (a: { detail: string }) => void;
}, HTMLElement>
} }
} }
declare namespace NodeJS { declare namespace NodeJS {
......
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
import styles from './index.module.scss'
Component({
data: {
list: '1234567890'.split(''),
styles
},
methods: {
handleClick (event) {
this.triggerEvent('type', event.currentTarget.dataset.letter)
},
}
})
.keyboard {
padding: 16px 34px 0 36px;
margin: -16px -10px;
display: flex;
flex-wrap: wrap;
}
.keyboard_item_wrap {
padding: 16px 10px;
}
.keyboard_item {
width: 120px;
height: 120px;
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%;
}
.keyboard_item_wrap.is_active {
.keyboard_item {
background-image: url(./assets/keyboard-active.png);
color: #ffffff;
}
}
<view class="{{styles.keyboard}}">
<view wx:for="{{list}}" class="{{styles.keyboard_item_wrap}}" data-letter="{{item}}" wx:key="*this" hover-class="{{styles.is_active}}" catchtouchstart="handleClick">
<view class="{{styles.keyboard_item}}">{{item}}</view>
</view>
</view>
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
font-size: 52px; font-size: 52px;
font-weight: 500; font-weight: 500;
color: #465164; color: #465164;
background-image: url(../assets//keyboard.png); background-image: url(../assets/keyboard.png);
background-size: 100% 100%; background-size: 100% 100%;
&.is_active { &.is_active {
color: #ffffff; color: #ffffff;
background-image: url(../assets//keyboard-active.png); background-image: url(../assets/keyboard-active.png);
} }
} }
...@@ -3,6 +3,7 @@ export default definePageConfig({ ...@@ -3,6 +3,7 @@ export default definePageConfig({
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',
'number-keyboard': '../../../native-components/number-keyboard/index',
} }
}) })
...@@ -10,7 +10,7 @@ import PageHead from './components/page-head' ...@@ -10,7 +10,7 @@ import PageHead from './components/page-head'
import PageFooter from './components/page-footer' import PageFooter from './components/page-footer'
import Question from './components/question' import Question from './components/question'
import CountUp from './components/count-up' import CountUp from './components/count-up'
import NumberKeyboard from './components/number-keyboard' // import NumberKeyboard from './components/number-keyboard'
import styles from './index.module.scss' import styles from './index.module.scss'
...@@ -66,7 +66,7 @@ const GamePlay = () => { ...@@ -66,7 +66,7 @@ const GamePlay = () => {
{currentQuestion && ( {currentQuestion && (
<> <>
{currentQuestion?.questionType !== '选择题' && ( {currentQuestion?.questionType !== '选择题' && (
<NumberKeyboard onClick={updateUserAnswer} /> <number-keyboard onType={updateUserAnswer} />
)} )}
{rightIcon && ( {rightIcon && (
<Image src={rightIcon} className={styles.right_icon}></Image> <Image src={rightIcon} className={styles.right_icon}></Image>
......
...@@ -68,7 +68,7 @@ export interface GameModel extends GameModelState { ...@@ -68,7 +68,7 @@ export interface GameModel extends GameModelState {
/** 更新当前输入框下标 */ /** 更新当前输入框下标 */
updateCurrentInputIndex: Action<GameModel, number>; updateCurrentInputIndex: Action<GameModel, number>;
/** 更新用户输入 */ /** 更新用户输入 */
updateUserAnswer: Action<GameModel, string>; updateUserAnswer: Action<GameModel, { detail: string }>;
/** 清空所有输入 */ /** 清空所有输入 */
clearUserAnswer: Action<GameModel, void>; clearUserAnswer: Action<GameModel, void>;
updateSelectionAnswer: Action<GameModel, number>; updateSelectionAnswer: Action<GameModel, number>;
...@@ -142,7 +142,7 @@ const gameModel: GameModel = { ...@@ -142,7 +142,7 @@ const gameModel: GameModel = {
} }
}), }),
updateUserAnswer: action((state, char) => { updateUserAnswer: action((state, { detail }) => {
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
vibrateShort() vibrateShort()
} }
...@@ -150,7 +150,7 @@ const gameModel: GameModel = { ...@@ -150,7 +150,7 @@ const gameModel: GameModel = {
const answers = state.questionList[state.currentQuestionIndex]?.answers const answers = state.questionList[state.currentQuestionIndex]?.answers
const val = answers?.[index] const val = answers?.[index]
if (answers && val) { if (answers && val) {
val.userAnswer = `${val.userAnswer === '0' ? '' : (val.userAnswer || '')}${char}` val.userAnswer = `${val.userAnswer === '0' ? '' : (val.userAnswer || '')}${detail}`
const maxLen = answers.length const maxLen = answers.length
state.questionList = state.questionList.slice() state.questionList = state.questionList.slice()
if (answers.length > 1 && index < maxLen - 1) { if (answers.length > 1 && index < maxLen - 1) {
......
...@@ -4,7 +4,7 @@ import classNames from 'classnames' ...@@ -4,7 +4,7 @@ import classNames from 'classnames'
import { useMemo } from 'react' import { useMemo } from 'react'
import assets from '@/assets/oss/assets-guide' import assets from '@/assets/oss/assets-guide'
import { getCurrentInstance } from '@tarojs/taro' import { getCurrentInstance } from '@tarojs/taro'
import NumberKeyboard from '@/pages/game/play/components/number-keyboard' // import NumberKeyboard from '@/pages/game/play/components/number-keyboard'
import MathSymbol from '@/pages/game/play/components/math-symbol' import MathSymbol from '@/pages/game/play/components/math-symbol'
import PageFooter from '@/pages/game/play/components/page-footer' import PageFooter from '@/pages/game/play/components/page-footer'
import cs from './index.module.scss' import cs from './index.module.scss'
...@@ -24,7 +24,7 @@ type QuestionModel = { ...@@ -24,7 +24,7 @@ type QuestionModel = {
current: number; current: number;
isSubmit: boolean; isSubmit: boolean;
updateState: Action<QuestionModel, Partial<State<QuestionModel>>>; updateState: Action<QuestionModel, Partial<State<QuestionModel>>>;
updateAnswer: Action<QuestionModel, string>; updateAnswer: Action<QuestionModel, { detail: string }>;
goNext: Thunk<QuestionModel, ((val: number) => void) | void>; goNext: Thunk<QuestionModel, ((val: number) => void) | void>;
clearUserAnswers: Action<QuestionModel>; clearUserAnswers: Action<QuestionModel>;
updateWrong: Action<QuestionModel, boolean>; updateWrong: Action<QuestionModel, boolean>;
...@@ -53,9 +53,13 @@ const Scene3 = (props: Scene3Props) => { ...@@ -53,9 +53,13 @@ const Scene3 = (props: Scene3Props) => {
updateWrong: action((_state, p) => { updateWrong: action((_state, p) => {
_state.wrong = p _state.wrong = p
}), }),
updateAnswer: action((_state, str) => { updateAnswer: action((_state, { detail }) => {
const pre = _state.values[_state.current] const pre = _state.values[_state.current]
_state.values[_state.current] = pre + str if (pre === '0') {
_state.values[_state.current] = detail
} else {
_state.values[_state.current] = pre + detail
}
}), }),
goNext: thunk((_act, cb, helpers) => { goNext: thunk((_act, cb, helpers) => {
const { current, values } = helpers.getState() const { current, values } = helpers.getState()
...@@ -135,7 +139,7 @@ const Scene3 = (props: Scene3Props) => { ...@@ -135,7 +139,7 @@ const Scene3 = (props: Scene3Props) => {
</ScrollView> </ScrollView>
</View> </View>
<View> <View>
<NumberKeyboard onClick={actions.updateAnswer}></NumberKeyboard> <number-keyboard onType={actions.updateAnswer} />
<PageFooter <PageFooter
canGoNext={canGoNext} canGoNext={canGoNext}
confirmText="继续" confirmText="继续"
......
...@@ -4,6 +4,7 @@ export default definePageConfig({ ...@@ -4,6 +4,7 @@ export default definePageConfig({
navigationBarTextStyle: 'white', navigationBarTextStyle: 'white',
enableShareAppMessage: true, enableShareAppMessage: true,
usingComponents: { usingComponents: {
'count-up-time': '../../native-components/count-up/index' 'count-up-time': '../../native-components/count-up/index',
'number-keyboard': '../../native-components/number-keyboard/index'
} }
}) })
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