Commit 544a9de6 authored by hewenhao's avatar hewenhao

Merge branch 'feature/2023-06-12-v1.1' of…

Merge branch 'feature/2023-06-12-v1.1' of dev.jiuaoedu.com:hewenhao/GeekLearnMathWeapp into feature/2023-06-12-v1.1
parents ea4c273e 929d0da6
......@@ -45,19 +45,19 @@ export type PkRecord = {
recipientErrNum: number,
recipientName: string,
recipientResultTime: number,
result: string,
result: 'LOSE' | 'WIN',
stageName: string
}
export type PkRecords = {
export type PkSummary = {
records: PkRecord[]
} & Pick<PkDetails, 'allPkNum' | 'userRanks' | 'winPkNum'>
export function fetchUserRecords (data: PkParams) {
export function fetchUserSummary (data: PkParams) {
if (!data.stageId) {
delete data.stageId
}
return requestAfterSilentLogin<PkRecords, PkParams>((userInfo) => {
return requestAfterSilentLogin<PkSummary, PkParams>((userInfo) => {
data.userId = data.userId || userInfo?.userId
return {
method: 'GET',
......
......@@ -10,23 +10,20 @@ import { UserInfo, GameResultProps } from './game-result'
import styles from './battles-modal.module.scss'
import gameResultStyles from './game-result.module.scss'
import { rankTranslate } from '../utils'
const BattlesModal = () => {
const isVisible = useStoreState(state => state.battlesModel.modalIsVisible)
const setModalIsVisible = useStoreActions(actions => actions.battlesModel.setModalIsVisible)
const details = useStoreState((state) => state.battlesModel.details)
const records = useStoreState((state) => state.battlesModel.records)
const summary = useStoreState((state) => state.battlesModel.summary)
const fetchUserDetails = useStoreActions(
(actions) => actions.battlesModel.fetchUserDetails
)
const fetchUserRecords = useStoreActions(
(actions) => actions.battlesModel.fetchUserRecords
const fetchUserSummary = useStoreActions(
(actions) => actions.battlesModel.fetchUserSummary
)
useEffect(() => {
Promise.allSettled([fetchUserDetails({}), fetchUserRecords({})])
}, [fetchUserDetails, fetchUserRecords])
fetchUserSummary({})
}, [fetchUserSummary])
return (
<Modal
......@@ -56,7 +53,7 @@ const BattlesModal = () => {
/>
<View className={styles.detailsRight}>
<Text className={styles.badgeText}>
{details?.userRanks.level || '-'}
{rankTranslate(summary?.userRanks.level)}
</Text>
<View className={styles.badgeBar}>
{[...Array(3)].map((_, index) => (
......@@ -64,7 +61,7 @@ const BattlesModal = () => {
key={index}
className={classNames(
styles.badgeBarItem,
index < (details?.userRanks.star || 0) ? styles.active : null
index < (summary?.userRanks.star || 0) ? styles.active : null
)}
></Text>
))}
......@@ -73,8 +70,8 @@ const BattlesModal = () => {
</View>
<ScrollView className={styles.gameResult} scrollY>
{records.length > 0
? records.map((item) => <GameResult key={item.id} record={item} />)
{summary && summary?.records.length > 0
? summary?.records.map((item) => <GameResult key={item.id} record={item} />)
: <Text className={styles.emptyText}>暂无PK记录</Text>
}
</ScrollView>
......@@ -84,18 +81,19 @@ const BattlesModal = () => {
}
const GameResult = ({ record }: GameResultProps) => {
const wined = record.result === 'WIN'
return (
<View className={gameResultStyles.gameResult}>
<View
className={classNames(
gameResultStyles.levelInfo,
record.result ? gameResultStyles.win : gameResultStyles.lose
wined ? gameResultStyles.win : gameResultStyles.lose
)}
>
<Text className={gameResultStyles.levelName}>{record.stageName}</Text>
<Image
mode="widthFix"
src={record.result ? assets['win.png'].u : assets['lose.png'].u}
src={wined ? assets['win.png'].u : assets['lose.png'].u}
className={gameResultStyles.levelResult}
/>
<Text className={gameResultStyles.levelDate}>{convertDateTime(record.createTime)}</Text>
......@@ -103,11 +101,11 @@ const GameResult = ({ record }: GameResultProps) => {
<View className={styles.gameBody}>
<View className={styles.playerSection}>
<View className={classNames(styles.userInfo, record.result ? styles.win : styles.lose)}>
<View className={classNames(styles.userInfo, wined ? styles.win : styles.lose)}>
<UserInfo name={record.initiatorName} />
</View>
<Image className={gameResultStyles.vs} src={assets['vs.png'].u} />
<View className={classNames(styles.userInfo, !record.result ? styles.win : styles.lose)}>
<View className={classNames(styles.userInfo, !wined ? styles.win : styles.lose)}>
<UserInfo style={{ alignItems: 'flex-end' }} name={record.recipientName} />
</View>
</View>
......
......@@ -14,18 +14,19 @@ export interface GameResultProps {
}
const GameResult = ({ record }: GameResultProps) => {
const wined = record.result === 'WIN'
return (
<View className={styles.gameResult}>
<View
className={classNames(
styles.levelInfo,
record.result ? styles.win : styles.lose
wined ? styles.win : styles.lose
)}
>
<Text className={styles.levelName}>{record.stageName}</Text>
<Image
mode="widthFix"
src={assets[record.result ? 'win.png' : 'lose.png'].u}
src={assets[wined ? 'win.png' : 'lose.png'].u}
className={styles.levelResult}
/>
<Text className={styles.levelDate}>{convertDateTime(record.createTime)}</Text>
......@@ -41,7 +42,7 @@ const GameResult = ({ record }: GameResultProps) => {
/>
</View>
<GameStats
result={record.result}
result={wined}
initiator={{
err: record.initiatorErrNum,
time: record.initiatorResultTime,
......
......@@ -5,9 +5,10 @@ import assets from '@/assets/oss/assets-pk'
import styles from './player-details.module.scss'
import { badgeImages } from '../const'
import { rankTranslate } from '../utils'
const PlayerDetails = () => {
const details = useStoreState((state) => state.battlesModel.details)
const summary = useStoreState((state) => state.battlesModel.summary)
return (
<View className={styles.player}>
<View className={styles.playerHeader}>
......@@ -16,7 +17,7 @@ const PlayerDetails = () => {
className={styles.badgeIcon}
></Image>
<Text className={styles.badgeText}>
{details?.userRanks.level || '-'}
{rankTranslate(summary?.userRanks.level)}
</Text>
<View className={styles.badgeBar}>
{[...Array(3)].map((_, index) => (
......@@ -24,7 +25,7 @@ const PlayerDetails = () => {
key={index}
className={classNames(
styles.badgeBarItem,
index < (details?.userRanks.star || 0) ? styles.active : null
index < (summary?.userRanks.star || 0) ? styles.active : null
)}
></Text>
))}
......@@ -33,13 +34,13 @@ const PlayerDetails = () => {
<View className={styles.playerFooter}>
<View className={styles.stats}>
<View>
胜<Text className={styles.winText}>{details?.winPkNum || 0}</Text>
胜<Text className={styles.winText}>{summary?.winPkNum || 0}</Text>
</View>
<Image className={styles.icon} src={assets['stats.png'].u} />
<View>
负
<Text className={styles.loseText}>
{(details?.allPkNum || 0) - (details?.winPkNum || 0)}
{(summary?.allPkNum || 0) - (summary?.winPkNum || 0)}
</Text>
</View>
</View>
......
......@@ -12,17 +12,14 @@ import styles from './index.module.scss'
const Battles = () => {
const nav = useMemo(getMenuButtonBoundingClientRect, [])
const records = useStoreState((state) => state.battlesModel.records)
const summary = useStoreState((state) => state.battlesModel.summary)
const fetchUserDetails = useStoreActions(
(actions) => actions.battlesModel.fetchUserDetails
)
const fetchUserRecords = useStoreActions(
(actions) => actions.battlesModel.fetchUserRecords
const fetchUserSummary = useStoreActions(
(actions) => actions.battlesModel.fetchUserSummary
)
useDidShow(() => {
Promise.allSettled([fetchUserDetails({}), fetchUserRecords({})])
fetchUserSummary({})
})
return (
......@@ -49,8 +46,8 @@ const Battles = () => {
</View>
<View className={styles.gameResult}>
{records.length > 0
? records.map((item) => <GameResult key={item.id} record={item} />)
{summary && summary.records.length > 0
? summary.records.map((item) => <GameResult key={item.id} record={item} />)
: <Text className={styles.emptyText}>暂无PK记录</Text>
}
</View>
......
import { Action, Thunk, action, thunk } from 'easy-peasy'
import { fetchUserDetails, fetchUserRecords, type PkParams, type PkDetails, type PkRecord } from '@/api/pk'
import { fetchUserDetails, fetchUserSummary, type PkParams, type PkDetails, type PkSummary } from '@/api/pk'
interface BattlesModel {
details: PkDetails | null,
records: PkRecord[];
summary: PkSummary | null;
modalIsVisible: boolean;
setModalIsVisible: Action<BattlesModel, boolean>;
setUserDetails: Action<BattlesModel, PkDetails>;
setUserRecords: Action<BattlesModel, PkRecord[]>;
setUserSummary: Action<BattlesModel, PkSummary>;
fetchUserDetails: Thunk<BattlesModel, PkParams>;
fetchUserRecords: Thunk<BattlesModel, PkParams>;
fetchUserSummary: Thunk<BattlesModel, PkParams>;
}
const battlesModel: BattlesModel = {
details: null,
records: [],
summary: null,
modalIsVisible: true,
setModalIsVisible: action((state, payload) => {
......@@ -25,8 +25,8 @@ const battlesModel: BattlesModel = {
state.details = payload
}),
setUserRecords: action((state, payload) => {
state.records = payload
setUserSummary: action((state, payload) => {
state.summary = payload
}),
fetchUserDetails: thunk(async (actions, payload) => {
......@@ -37,10 +37,10 @@ const battlesModel: BattlesModel = {
}
}),
fetchUserRecords: thunk(async (actions, payload) => {
fetchUserSummary: thunk(async (actions, payload) => {
try {
const res = await fetchUserRecords(payload)
actions.setUserRecords(res.data.records)
const res = await fetchUserSummary(payload)
actions.setUserSummary(res.data)
} catch (err) {
}
}),
......
type Rank = 'BRONZE' | 'SILVER' | 'GOLD' | 'PLATINUM' | 'DIAMOND'
function toRomanNumeral (num: number): string {
const roman: { [key: number]: string } = {
1: 'I',
2: 'II',
3: 'III',
}
return roman[num]
}
export function rankTranslate (rankWithLevel: string | undefined): string {
if (!rankWithLevel) {
return '-'
}
const [rank, level] = rankWithLevel.split('_')
const rankName: { [key in Rank]?: string } = {
BRONZE: '青铜',
SILVER: '白银',
GOLD: '黄金',
PLATINUM: '铂金',
DIAMOND: '钻石',
}
return `${rankName[rank as Rank]} ${toRomanNumeral(Number(level))}`
}
......@@ -79,7 +79,7 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => {
})
.then(() => {
changeNickName(name).then(() => {
showToast({ title: '操作成功', icon: 'success' })
showToast({ title: '修改成功', icon: 'success' })
onCancel && onCancel()
})
})
......
import { View, Image, Text } from '@tarojs/components'
import { useMemo } from 'react'
import { navigateTo, getMenuButtonBoundingClientRect, navigateBack, getSystemInfoSync } from '@tarojs/taro'
import assets from '@/assets/oss/assets-main-next'
import { useStoreState } from '@/store/hooks'
import Scene3 from '../guide/complete/scene-3'
......@@ -42,7 +43,7 @@ export default ({ isFirstStage }: { isFirstStage: boolean }) => {
<Text>{point}</Text>
</Scene3>
<View className={styles.ph} onClick={goStore}>
<Image src={require('@/pages/main/assets/ph.png')} className={styles.icon} />
<Image src={assets['star.png'].u} className={styles.icon} />
<Text>{cardNum}</Text>
</View>
</View>
......
......@@ -179,22 +179,24 @@ const userModel: UserModel = {
const { data: list } = await accountExchange(payload)
const point = list.find(c => c.accountType === 'POINT')?.amount ?? 0
actions.updateState({ point })
hideLoading()
} catch (err) {
hideLoading()
showModal({
title: '提示',
content: err.message,
showCancel: false
})
throw err
} finally {
hideLoading()
}
}),
changeNickName: thunk(async (_, payload) => {
changeNickName: thunk(async (actions, payload) => {
try {
const { data } = await changeNickName(payload)
console.log(data)
const { code } = await changeNickName(payload)
if (code === 0) {
actions.updateUserInfo({ nickName: payload })
}
} catch (err) {
showModal({
title: '提示',
......
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