Commit 14f990d9 authored by m's avatar m
parents fa581ec1 d3061f51
...@@ -37,6 +37,17 @@ export function getAccountInfo () { ...@@ -37,6 +37,17 @@ export function getAccountInfo () {
})) }))
} }
export function updateUserInfo (nickName: string) {
return requestAfterSilentLogin<void, { nickName: string; userId?: number; }>(userInfo => ({
method: 'POST',
url: '/service-idea/stage/user/updateUserInfo',
data: {
nickName,
userId: userInfo?.userId
}
}))
}
export function getSetting () { export function getSetting () {
return requestAfterSilentLogin<{pointToCard: number}, {}>(() => ({ return requestAfterSilentLogin<{pointToCard: number}, {}>(() => ({
method: 'GET', method: 'GET',
......
...@@ -104,6 +104,7 @@ export interface CompleteStageParam { ...@@ -104,6 +104,7 @@ export interface CompleteStageParam {
correctNum: number; correctNum: number;
level: StageLevel | null; level: StageLevel | null;
levelTime: number; levelTime: number;
isTimeout: boolean;
num: number; num: number;
questions: CompleteQuestion[]; questions: CompleteQuestion[];
resultTime: number; resultTime: number;
......
...@@ -16,7 +16,7 @@ export const createTribe = ({ groupNo }: Pick<CreateTribeParams, 'groupNo'>) => ...@@ -16,7 +16,7 @@ export const createTribe = ({ groupNo }: Pick<CreateTribeParams, 'groupNo'>) =>
data: { data: {
groupNo, groupNo,
bizType: 'RKLL', bizType: 'RKLL',
memberName: userInfo?.nickname || 'CTO', memberName: userInfo?.nickName || 'CTO',
memberId: userInfo?.userId, memberId: userInfo?.userId,
} }
})) }))
...@@ -42,7 +42,7 @@ export const joinTribe = ({ groupId }: { groupId: number }) => { ...@@ -42,7 +42,7 @@ export const joinTribe = ({ groupId }: { groupId: number }) => {
data: { data: {
groupId, groupId,
memberId: userInfo?.userId, memberId: userInfo?.userId,
memberName: userInfo?.nickname || '爹🐂' memberName: userInfo?.nickName || '爹🐂'
} }
})) }))
} }
......
...@@ -81,9 +81,8 @@ Component({ ...@@ -81,9 +81,8 @@ Component({
} }
} else { } else {
this._tick += 1 this._tick += 1
if (this._tick >= this.data.maxValue) { if (this._tick === this.data.maxValue) {
this.stop() this.triggerEvent('exceed')
this.triggerEvent('timeup')
} }
} }
const { minutes, seconds } = this.data const { minutes, seconds } = this.data
......
...@@ -122,7 +122,7 @@ const GameCompleteHead = () => { ...@@ -122,7 +122,7 @@ const GameCompleteHead = () => {
</View> </View>
<View className={styles.item}> <View className={styles.item}>
<Image src={require('../assets/time.png')} className={styles.icon}></Image> <Image src={require('../assets/time.png')} className={styles.icon}></Image>
<View className={classNames(styles.item_text, gameResult.errNum <= 0 && !gameResult.level && styles.err)}>{time.minutes}:{time.seconds}</View> <View className={classNames(styles.item_text, gameResult.isTimeout && styles.err)}>{time.minutes}:{time.seconds}</View>
</View> </View>
</View> </View>
</View> </View>
......
...@@ -42,14 +42,21 @@ ...@@ -42,14 +42,21 @@
} }
} }
.roleWrap {
position: absolute;
left: 0;
top: 0;
right: 0;
width: 100%;
transform: translateX(0px);
}
.role { .role {
position: absolute; position: absolute;
left: 0; left: 0;
top: -8px; top: -8px;
margin-left: -40px; margin-left: -40px;
transform: translateX(0px);
.tick { .tick {
width: 6px; width: 6px;
border-radius: 3px; border-radius: 3px;
......
import { View, Image } from '@tarojs/components' import { View, Image } from '@tarojs/components'
import { useState, useEffect, useCallback, useMemo } from 'react' import { useCallback, useMemo } from 'react'
import { createSelectorQuery } from '@tarojs/taro' import { useDidShow, nextTick } from '@tarojs/taro'
import classNames from 'classnames' import classNames from 'classnames'
import { useBoolean } from '@/hooks' import { useBoolean } from '@/hooks'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
...@@ -8,8 +8,6 @@ import { type StageDetail, StageType } from '@/api' ...@@ -8,8 +8,6 @@ import { type StageDetail, StageType } from '@/api'
import styles from './count-up.module.scss' import styles from './count-up.module.scss'
const id = '_process__'
type CountUpProps = { type CountUpProps = {
stageDetail: StageDetail stageDetail: StageDetail
} }
...@@ -21,24 +19,13 @@ const CountUp = (props: CountUpProps) => { ...@@ -21,24 +19,13 @@ const CountUp = (props: CountUpProps) => {
const questionList = useStoreState(state => state.gameModel.questionList) const questionList = useStoreState(state => state.gameModel.questionList)
const isSubmit = useStoreState(state => state.gameModel.isSubmit) const isSubmit = useStoreState(state => state.gameModel.isSubmit)
const submit = useStoreActions(actions => actions.gameModel.submit) const submit = useStoreActions(actions => actions.gameModel.submit)
const [width, setWidth] = useState(0)
const [isExceed, exceedActions] = useBoolean(false) const [isExceed, exceedActions] = useBoolean(false)
const [isStarted, startActions] = useBoolean(false)
const questionLength = useMemo(() => { const questionLength = useMemo(() => {
return questionList.length return questionList.length
}, [questionList]) }, [questionList])
useEffect(() => {
createSelectorQuery().select(`#${id}`)
.boundingClientRect()
.exec((res) => {
console.log(res)
if (res[0]) {
setWidth(res[0].width)
}
})
}, [])
const isOneStop = useMemo(() => { const isOneStop = useMemo(() => {
return stageDetail.type === StageType.OneStop return stageDetail.type === StageType.OneStop
}, [stageDetail]) }, [stageDetail])
...@@ -50,12 +37,24 @@ const CountUp = (props: CountUpProps) => { ...@@ -50,12 +37,24 @@ const CountUp = (props: CountUpProps) => {
return 0 return 0
}, [stageDetail]) }, [stageDetail])
useDidShow(() => {
nextTick(() => {
startActions.setTrue()
})
})
const roleStyle = useMemo(() => { const roleStyle = useMemo(() => {
if (isStarted) {
return {
transform: 'translateX(100%)',
transition: `transform ${stageDetail.bTime}s linear`,
}
}
return { return {
transform: `translateX(${width}px)`, transform: 'translateX(0)',
transition: `transform ${stageDetail.bTime}s linear`, transition: `transform ${stageDetail.bTime}s linear`,
} }
}, [width, stageDetail.bTime]) }, [stageDetail, isStarted])
const processInnerStyle = useMemo(() => { const processInnerStyle = useMemo(() => {
if (isSubmit) { if (isSubmit) {
...@@ -77,14 +76,16 @@ const CountUp = (props: CountUpProps) => { ...@@ -77,14 +76,16 @@ const CountUp = (props: CountUpProps) => {
return ( return (
<View className={classNames(styles.count, isOneStop && styles.is_stop)}> <View className={classNames(styles.count, isOneStop && styles.is_stop)}>
<View className={styles.process} id={id}> <View className={styles.process}>
<View className={styles.process_inner} style={processInnerStyle}></View> <View className={styles.process_inner} style={processInnerStyle}></View>
{!isOneStop && ( {!isOneStop && (
<View className={styles.role} style={roleStyle}> <View className={styles.roleWrap} style={roleStyle}>
<View className={styles.role}>
<View className={styles.tick}></View> <View className={styles.tick}></View>
<Image src={require('../assets/count-cat.png')} className={styles.cat}></Image> <Image src={require('../assets/count-cat.png')} className={styles.cat}></Image>
<View className={styles.tips}>通关要求</View> <View className={styles.tips}>通关要求</View>
</View> </View>
</View>
)} )}
</View> </View>
<View className={classNames(styles.time, isExceed && styles.red)}> <View className={classNames(styles.time, isExceed && styles.red)}>
...@@ -95,7 +96,7 @@ const CountUp = (props: CountUpProps) => { ...@@ -95,7 +96,7 @@ const CountUp = (props: CountUpProps) => {
<count-up-time <count-up-time
exceedTime={20} exceedTime={20}
onExceed={exceedActions.setTrue} onExceed={exceedActions.setTrue}
maxValue={60 * 60} maxValue={stageDetail.bTime}
startValue={startTick} startValue={startTick}
isDown={isOneStop} isDown={isOneStop}
onTimeup={handleTimeUp} onTimeup={handleTimeUp}
......
...@@ -5,16 +5,9 @@ import { useStoreState, useStoreActions } from '@/store/hooks' ...@@ -5,16 +5,9 @@ import { useStoreState, useStoreActions } from '@/store/hooks'
import styles from './modal-continue.module.scss' import styles from './modal-continue.module.scss'
type ModalContinueProps = {
closeOnClickModal: boolean;
onClose?: () => void;
}
const canGoNext = true const canGoNext = true
const ModalContinue = (props: ModalContinueProps) => { const ModalContinue = () => {
const { closeOnClickModal, onClose } = props
const modalContinueVisible = useStoreState(state => state.gameModel.modalContinueVisible) const modalContinueVisible = useStoreState(state => state.gameModel.modalContinueVisible)
const cardNum = useStoreState(state => state.userModel.cardNum) const cardNum = useStoreState(state => state.userModel.cardNum)
...@@ -22,12 +15,6 @@ const ModalContinue = (props: ModalContinueProps) => { ...@@ -22,12 +15,6 @@ const ModalContinue = (props: ModalContinueProps) => {
const submit = useStoreActions(actions => actions.gameModel.submit) const submit = useStoreActions(actions => actions.gameModel.submit)
const reborn = useStoreActions(actions => actions.gameModel.reborn) const reborn = useStoreActions(actions => actions.gameModel.reborn)
const handleClick = useCallback(() => {
if (closeOnClickModal) {
onClose?.()
}
}, [closeOnClickModal, onClose])
useEffect(() => { useEffect(() => {
if (modalContinueVisible) { if (modalContinueVisible) {
fetchAccount() fetchAccount()
...@@ -40,7 +27,7 @@ const ModalContinue = (props: ModalContinueProps) => { ...@@ -40,7 +27,7 @@ const ModalContinue = (props: ModalContinueProps) => {
return ( return (
<RootPortal> <RootPortal>
<View className={classNames(styles.mask, modalContinueVisible && styles.is_show)} onClick={handleClick}> <View className={classNames(styles.mask, modalContinueVisible && styles.is_show)}>
</View> </View>
<View className={classNames(styles.modal, modalContinueVisible && styles.is_show)}> <View className={classNames(styles.modal, modalContinueVisible && styles.is_show)}>
<View className={styles.title}>是否继续闯关?</View> <View className={styles.title}>是否继续闯关?</View>
......
...@@ -16,7 +16,6 @@ import styles from './index.module.scss' ...@@ -16,7 +16,6 @@ import styles from './index.module.scss'
const GamePlay = () => { const GamePlay = () => {
const currentQuestion = useStoreState(states => states.gameModel.currentQuestion) const currentQuestion = useStoreState(states => states.gameModel.currentQuestion)
const stageDetail = useStoreState(state => state.gameModel.stageDetail) const stageDetail = useStoreState(state => state.gameModel.stageDetail)
const [val, actions] = useBoolean(false)
return ( return (
<> <>
...@@ -41,7 +40,7 @@ const GamePlay = () => { ...@@ -41,7 +40,7 @@ const GamePlay = () => {
</> </>
)} )}
</View> </View>
<ModalContinue closeOnClickModal onClose={actions.setFalse} /> <ModalContinue />
</> </>
) )
} }
......
...@@ -13,6 +13,7 @@ import { buildCompleteStageParam, convertQuestion, determinQuestion } from './ut ...@@ -13,6 +13,7 @@ import { buildCompleteStageParam, convertQuestion, determinQuestion } from './ut
interface CompleteStageDetail extends CompleteStageOut { interface CompleteStageDetail extends CompleteStageOut {
errNum: number; errNum: number;
levelTime: number; levelTime: number;
isTimeout: boolean;
} }
const COUNTER_ID = 'z__countdown__' const COUNTER_ID = 'z__countdown__'
...@@ -277,6 +278,7 @@ const gameModel: GameModel = { ...@@ -277,6 +278,7 @@ const gameModel: GameModel = {
actions.updateState({ actions.updateState({
gameResult: { gameResult: {
...gameResult, ...gameResult,
isTimeout: params.isTimeout,
errNum: params.num - params.correctNum, errNum: params.num - params.correctNum,
levelTime: params.levelTime levelTime: params.levelTime
} }
......
...@@ -40,7 +40,7 @@ export function convertQuestion (question: QuestionType): QuestionType { ...@@ -40,7 +40,7 @@ export function convertQuestion (question: QuestionType): QuestionType {
} }
export function buildCompleteStageParam (questionList: QuestionType[], stageDetail: StageDetail, resultTime: number): CompleteStageParam { export function buildCompleteStageParam (questionList: QuestionType[], stageDetail: StageDetail, resultTime: number): CompleteStageParam {
const wrongList = questionList.map(c => !determinQuestion(c)).filter(Boolean) const wrongList = questionList.filter(c => !determinQuestion(c))
const wrongLength = wrongList.length const wrongLength = wrongList.length
if (wrongLength > 0) { if (wrongLength > 0) {
...@@ -55,6 +55,8 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta ...@@ -55,6 +55,8 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
const num = questionList.length const num = questionList.length
let levelTime: number = 0 let levelTime: number = 0
const isTimeout = resultTime > bTime
const correctNum = num - wrongLength const correctNum = num - wrongLength
if (correctNum === num) { if (correctNum === num) {
...@@ -73,6 +75,7 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta ...@@ -73,6 +75,7 @@ export function buildCompleteStageParam (questionList: QuestionType[], stageDeta
return { return {
correctNum, correctNum,
level, level,
isTimeout,
levelTime, levelTime,
stageId: stageDetail.id, stageId: stageDetail.id,
questions: questionList.map(convert), questions: questionList.map(convert),
......
...@@ -32,13 +32,15 @@ ...@@ -32,13 +32,15 @@
.avatar { .avatar {
flex: 1; flex: 1;
.icon { min-width: 0;
.name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 14PX;
font-weight: 500;
margin-left: 16PX; margin-left: 16PX;
width: 32PX; color: #FFFFFF;
height: 32PX;
margin-right: 4PX;
border-radius: 16PX;
background-color: #999;
} }
} }
......
...@@ -25,6 +25,7 @@ const MainHeader = () => { ...@@ -25,6 +25,7 @@ const MainHeader = () => {
const cardNum = useStoreState(state => state.userModel.cardNum) const cardNum = useStoreState(state => state.userModel.cardNum)
const point = useStoreState(state => state.userModel.point) const point = useStoreState(state => state.userModel.point)
const userInfo = useStoreState(state => state.userModel.userInfo)
return ( return (
<View className={styles.header}> <View className={styles.header}>
...@@ -38,7 +39,7 @@ const MainHeader = () => { ...@@ -38,7 +39,7 @@ const MainHeader = () => {
> >
<View className={styles.inner} style={innerStyle}> <View className={styles.inner} style={innerStyle}>
<View className={styles.avatar}> <View className={styles.avatar}>
<Image src="https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96" className={styles.icon}></Image> <Text className={styles.name}>{userInfo?.nickName ?? ''}</Text>
</View> </View>
<View className={classNames(styles.score, cs.bounce_btn)} onClick={goStore} hoverClass={cs.bounce_btn_hover}> <View className={classNames(styles.score, cs.bounce_btn)} onClick={goStore} hoverClass={cs.bounce_btn_hover}>
<Image src={require('../assets/score.png')} className={styles.icon} /> <Image src={require('../assets/score.png')} className={styles.icon} />
......
...@@ -4,6 +4,7 @@ import classNames from 'classnames' ...@@ -4,6 +4,7 @@ import classNames from 'classnames'
import { cs } from '@/styles' import { cs } from '@/styles'
import { navigateTo } from '@tarojs/taro' import { navigateTo } from '@tarojs/taro'
import type { ImageSource } from '@/types' import type { ImageSource } from '@/types'
import { useStoreActions } from '@/store/hooks'
import { type Stage, StageType, StageStatus, StageLevel, CurrentRoundId, SceneContext } from './constants' import { type Stage, StageType, StageStatus, StageLevel, CurrentRoundId, SceneContext } from './constants'
import StageTag from './stage-tag' import StageTag from './stage-tag'
...@@ -103,6 +104,7 @@ const getIconClassNames = (type?: StageType, extra: string[] = []) => { ...@@ -103,6 +104,7 @@ const getIconClassNames = (type?: StageType, extra: string[] = []) => {
const StageComp = (props: StageProps) => { const StageComp = (props: StageProps) => {
const { stage } = props const { stage } = props
const updateState = useStoreActions(actions => actions.gameModel.updateState)
const renderRound = (ready: boolean) => { const renderRound = (ready: boolean) => {
switch (stage.status) { switch (stage.status) {
...@@ -143,6 +145,8 @@ const StageComp = (props: StageProps) => { ...@@ -143,6 +145,8 @@ const StageComp = (props: StageProps) => {
const handleClick = () => { const handleClick = () => {
if (stage.status !== StageStatus.DISABLED) { if (stage.status !== StageStatus.DISABLED) {
/** 从首页进入更新状态 */
updateState({ isSubmit: false })
navigateTo({ url: `/pages/prepare/index?id=${stage.id}` }) navigateTo({ url: `/pages/prepare/index?id=${stage.id}` })
} }
} }
......
...@@ -24,6 +24,7 @@ const MainPage = () => { ...@@ -24,6 +24,7 @@ const MainPage = () => {
const fetchStage = useStoreActions(actions => actions.mainModel.fetchStage) const fetchStage = useStoreActions(actions => actions.mainModel.fetchStage)
const stageList = useStoreState(state => state.mainModel.stageList) const stageList = useStoreState(state => state.mainModel.stageList)
const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount) const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount)
const updateUserInfo = useStoreActions(actions => actions.userModel.updateUserInfo)
const fetchTribeInfo = useStoreActions(actions => actions.groupModel.fetchTribeInfo) const fetchTribeInfo = useStoreActions(actions => actions.groupModel.fetchTribeInfo)
const [nav] = useState(getMenuButtonBoundingClientRect()) const [nav] = useState(getMenuButtonBoundingClientRect())
const router = useRouter<{ groupId: string, inviteId: string }>() const router = useRouter<{ groupId: string, inviteId: string }>()
...@@ -40,6 +41,7 @@ const MainPage = () => { ...@@ -40,6 +41,7 @@ const MainPage = () => {
useDidShow(() => { useDidShow(() => {
fetchAccount() fetchAccount()
updateUserInfo('曾牛逼')
const tabbar = getTabBar<TabbarRef>(page) const tabbar = getTabBar<TabbarRef>(page)
tabbar?.setSelected(0) tabbar?.setSelected(0)
......
import { View, Text, Button } from '@tarojs/components'
import Modal from '@/components/Modal'
import { useBoolean } from '@/hooks/use-boolean'
// import { MarketModalProps } from '../types'
import CardMain from './card-main'
const AnswerSheet = ({ onConfirm, loading }) => {
const [isVisible, { setTrue, setFalse }] = useBoolean(false)
return (
<View className="card-body">
<CardMain
title="答题卡"
subtitle="答题卡是不断追求更高档位与排名的必备道具答题卡是不断追求更高档位与排名的必备道具"
extra={<Text className="card-stock">本月库存10</Text>}
onClick={setTrue}
/>
<Modal isVisible={isVisible} onClose={setFalse}>
<View>
<Text>兑换几张</Text>
<Button size="mini" loading={loading} onClick={() => onConfirm('CARD', setFalse)}>兑换</Button>
</View>
</Modal>
</View>
)
}
export default AnswerSheet
...@@ -28,8 +28,10 @@ const ExchangeItem = (props: ExchangeItemProps) => { ...@@ -28,8 +28,10 @@ const ExchangeItem = (props: ExchangeItemProps) => {
}, [val]) }, [val])
useEffect(() => { useEffect(() => {
if (visible) { if (!visible) {
setTimeout(() => {
setVal(0) setVal(0)
}, 1000)
} }
}, [visible]) }, [visible])
......
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import { useMemo, useState } from 'react' import { useMemo, useState, useEffect } from 'react'
import { useRouter, redirectTo, useDidShow, getMenuButtonBoundingClientRect, useShareAppMessage, navigateTo } from '@tarojs/taro' import { useRouter, redirectTo, useDidShow, getMenuButtonBoundingClientRect, useShareAppMessage, navigateTo } from '@tarojs/taro'
import classNames from 'classnames' import classNames from 'classnames'
...@@ -38,6 +38,8 @@ const Prepare = () => { ...@@ -38,6 +38,8 @@ const Prepare = () => {
const getStageDetail = useStoreActions(actions => actions.gameModel.getStageDetail) const getStageDetail = useStoreActions(actions => actions.gameModel.getStageDetail)
const getQuestionList = useStoreActions(actions => actions.gameModel.getQuestionList) const getQuestionList = useStoreActions(actions => actions.gameModel.getQuestionList)
const updateState = useStoreActions(actions => actions.gameModel.updateState) const updateState = useStoreActions(actions => actions.gameModel.updateState)
const getSetting = useStoreActions(actions => actions.userModel.getSetting)
const setting = useStoreState(state => state.userModel.setting)
const tabs: TabItem[] = [ const tabs: TabItem[] = [
{ {
...@@ -73,6 +75,12 @@ const Prepare = () => { ...@@ -73,6 +75,12 @@ const Prepare = () => {
} }
}, [nav.height, nav.top]) }, [nav.height, nav.top])
useEffect(() => {
if (cardNum < 1) {
getSetting()
}
}, [cardNum, getSetting])
useDidShow(() => { useDidShow(() => {
getStageDetail(+router.params.id || 1) getStageDetail(+router.params.id || 1)
}) })
...@@ -151,21 +159,21 @@ const Prepare = () => { ...@@ -151,21 +159,21 @@ const Prepare = () => {
</View> </View>
</ShareView>} </ShareView>}
{isSubmit ? renderFisrtActions() : renderAgainActions()} {!isSubmit ? renderFisrtActions() : renderAgainActions()}
</View> </View>
<AnswerCardModal isVisible={isVisible} onClose={setFalse}> <AnswerCardModal isVisible={isVisible} onClose={setFalse}>
<View <View
className={classNames(styles.buy_card, { className={classNames(styles.buy_card, {
[styles.buy_card_disabled]: point < 30, [styles.buy_card_disabled]: point < setting.pointToCard,
[styles.buy_card_loading]: loading, [styles.buy_card_loading]: loading,
})} })}
onClick={() => !loading && point >= 30 && exchange({ num: 1 })} onClick={() => !loading && point >= setting.pointToCard && exchange({ num: 1 })}
> >
<Loading size="small" className={styles.buy_card_spin} spinning={loading} /> <Loading size="small" className={styles.buy_card_spin} spinning={loading} />
<View className={styles.inner}> <View className={styles.inner}>
<Image className={styles.logo} src={point >= 30 ? assets['diamond.png'].u : assets['diamond-un.png'].u} mode="widthFix" /> <Image className={styles.logo} src={point >= setting.pointToCard ? assets['diamond.png'].u : assets['diamond-un.png'].u} mode="widthFix" />
<Text>-30</Text> <Text>-{setting.pointToCard}</Text>
<Text className={styles.buy}>购买</Text> <Text className={styles.buy}>购买</Text>
<Text className={styles.balance}>(当前剩余 {point})</Text> <Text className={styles.balance}>(当前剩余 {point})</Text>
</View> </View>
......
import { import {
action, Action, Thunk, thunk, State action, Action, Thunk, thunk, State
} from 'easy-peasy' } from 'easy-peasy'
import { getAccountInfo, getSetting } from '@/api' import { getAccountInfo, getSetting, updateUserInfo } from '@/api'
import type { UserInfo } from '@/types' import type { UserInfo } from '@/types'
import { pointToCard } from '@/api/account' import { pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro' import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
import { getStorage, StorageKeys } from '@/utils/storage' import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { AppStoreModel } from '../store-model' import { AppStoreModel } from '../store-model'
export interface UserModel { export interface UserModel {
...@@ -14,9 +14,9 @@ export interface UserModel { ...@@ -14,9 +14,9 @@ export interface UserModel {
point: number; point: number;
updateState: Action<UserModel, Partial<State<UserModel>>>; updateState: Action<UserModel, Partial<State<UserModel>>>;
fetchAccount: Thunk<UserModel, void, void, AppStoreModel>; fetchAccount: Thunk<UserModel, void, void, AppStoreModel>;
updateUserInfo: Action<UserModel, UserInfo>;
setting: { pointToCard: number }; setting: { pointToCard: number };
getSetting: Thunk<UserModel, void, void, AppStoreModel>; getSetting: Thunk<UserModel, void, void, AppStoreModel>;
updateUserInfo: Thunk<UserModel, string, void, AppStoreModel>;
exchangeItem: Thunk<UserModel, { name: string; num: number; }, void, AppStoreModel>; exchangeItem: Thunk<UserModel, { name: string; num: number; }, void, AppStoreModel>;
} }
...@@ -34,6 +34,19 @@ const userModel: UserModel = { ...@@ -34,6 +34,19 @@ const userModel: UserModel = {
actions.updateState({ setting: { pointToCard: Infinity } }) actions.updateState({ setting: { pointToCard: Infinity } })
} }
}), }),
updateUserInfo: thunk(async (actions, nickName, helpers) => {
try {
await updateUserInfo(nickName)
const { userInfo } = helpers.getState()
const current = { ...userInfo, nickName }
updateStorage(StorageKeys.userInfo, current)
actions.updateState({
userInfo: current
})
} catch (err) {
console.log(err)
}
}),
exchangeItem: thunk(async (actions, payload) => { exchangeItem: thunk(async (actions, payload) => {
try { try {
showLoading({ mask: true, title: '兑换中...' }) showLoading({ mask: true, title: '兑换中...' })
...@@ -52,9 +65,6 @@ const userModel: UserModel = { ...@@ -52,9 +65,6 @@ const userModel: UserModel = {
}) })
} }
}), }),
updateUserInfo: action((state, user) => {
state.userInfo = user
}),
updateState: action((state, payload) => { updateState: action((state, payload) => {
for (const key in payload) { for (const key in payload) {
state[key] = payload[key] state[key] = payload[key]
......
...@@ -4,7 +4,7 @@ export type UserInfo = { ...@@ -4,7 +4,7 @@ export type UserInfo = {
openId: string; openId: string;
userId?: number; userId?: number;
city?: string; city?: string;
nickname?: string | null; nickName?: string | null;
phone?: string | null; phone?: string | null;
} }
......
...@@ -28,7 +28,7 @@ async function silentLogin () { ...@@ -28,7 +28,7 @@ async function silentLogin () {
updateStorage(StorageKeys.openid, data.openId) updateStorage(StorageKeys.openid, data.openId)
updateStorage(StorageKeys.userInfo, data) updateStorage(StorageKeys.userInfo, data)
store.getActions().userModel.updateUserInfo(data) store.getActions().userModel.updateState({ userInfo: data })
setProfile(data.openId, `${data.userId}`) setProfile(data.openId, `${data.userId}`)
} catch (silentLoginError) { } catch (silentLoginError) {
......
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