Commit 341d45f2 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 05d10e19 09fc26af
/// <reference types="@tarojs/taro" />
declare module '*.png';
declare module '*.gif';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.svg';
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.styl';
declare module '*.png'
declare module '*.gif'
declare module '*.jpg'
declare module '*.jpeg'
declare module '*.svg'
declare module '*.css'
declare module '*.less'
declare module '*.scss'
declare module '*.sass'
declare module '*.styl'
type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
'maxValue'?: number;
'isDown'?: boolean;
'startValue': number;
exceedTime: number;
onTimeup?: () => void;
onExceed?: () => void;
}, HTMLElement>
type CountUpTime = React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
maxValue?: number
isDown?: boolean
startValue: number
exceedTime: number
onTimeup?: () => void
onExceed?: () => void
},
HTMLElement
>
declare namespace JSX{
declare namespace JSX {
interface IntrinsicElements {
// 扩展 IntrinsicElements 否则无法识别自定义标签
'count-up-time': CountUpTime;
'number-keyboard': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
onType?: (a: { detail: string }) => void;
}, HTMLElement>;
'game-rank': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
// 扩展 IntrinsicElements 否则无法识别自定义标签
'count-up-time': CountUpTime
'number-keyboard': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
onType?: (a: { detail: string }) => void
},
HTMLElement
>
'game-rank': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
list: any[]
}, HTMLElement>;
},
HTMLElement
>,
'pk-record': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
list: any[]
},
HTMLElement
>,
}
}
declare namespace NodeJS {
interface ProcessEnv {
TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt' | 'quickapp' | 'qq' | 'jd'
TARO_ENV:
| 'weapp'
| 'swan'
| 'alipay'
| 'h5'
| 'rn'
| 'tt'
| 'quickapp'
| 'qq'
| 'jd'
}
}
declare module 'html-parse-stringify' {
export interface TagNode {
type: 'tag';
name: string;
voidElement: boolean;
attrs: Record<string, string | undefined>;
children: Node[];
type: 'tag'
name: string
voidElement: boolean
attrs: Record<string, string | undefined>
children: Node[]
}
export interface TextNode {
type: 'text';
content: string;
type: 'text'
content: string
}
export interface ComponentNode {
type: 'component';
name: string;
attrs: Record<string, string | undefined>;
voidElement: boolean;
children: [];
type: 'component'
name: string
attrs: Record<string, string | undefined>
voidElement: boolean
children: []
}
export type Node = TagNode | TextNode | ComponentNode;
export type Node = TagNode | TextNode | ComponentNode
export interface ParseOptions {
components: Record<string, boolean>;
components: Record<string, boolean>
}
namespace HtmlParseStringify {
function parse(html: string, options?: ParseOptions): Node[];
function stringify(doc: Node[]): string;
function parse(html: string, options?: ParseOptions): Node[]
function stringify(doc: Node[]): string
}
export default HtmlParseStringify
......
......@@ -7,9 +7,9 @@
export default {
pages: [
'pages/main/main',
'pages/market/index',
'pages/accept-pk/index',
'pages/battles/index',
'pages/market/index',
'pages/prepare/index',
'pages/group/index',
'pages/game/play/index',
......
......@@ -2,6 +2,7 @@ import { request, requestAfterSilentLogin } from '@/utils/request'
import { request as requesNative } from '@tarojs/taro'
import { getCurrentShareId } from '@/utils/share'
import type { UserInfo } from '@/types'
import { PkDetails, PkRecord } from './pk'
type LoginResult = UserInfo
......@@ -130,3 +131,19 @@ export function changeNickName (nickName: string) {
}
}))
}
export type AccountInfo = {
accounts: AccountOut[];
pkList: PkRecord[];
stars: number;
} & Pick<PkDetails, 'userRanks' | 'winPkNum'>
export const fetchAccountInfo = () => {
return requestAfterSilentLogin<AccountInfo, { userId?: number }>((userInfo) => ({
url: '/service-idea/home/index',
method: 'GET',
data: {
userId: userInfo?.userId,
},
}))
}
......@@ -34,9 +34,10 @@ export async function fetchUserDetails (data: { initiator?: string; stageId?: st
}
export type PkRecord = {
createTime: string;
createTime: string,
id: number,
initiator: number,
initiatorLevel: string,
initiatorAvatar: string,
initiatorErrNum: number,
initiatorName: string,
......@@ -47,6 +48,7 @@ export type PkRecord = {
recipientErrNum: number,
recipientName: string,
recipientResultTime: number,
recipientLevel: string,
result: 'LOSE' | 'WIN',
stageName: string
}
......@@ -116,3 +118,11 @@ export async function getPkResult (params: number) {
r.data.battleId = params
return r
}
export async function receivePkPrize () {
return requestAfterSilentLogin((userInfo) => ({
url: '/service-idea/pk/personal/receivePkPrize',
method: 'GET',
data: { userId: userInfo?.userId }
}))
}
@import '@/styles/mixins.scss';
.gameResult {
color: #fff;
margin-bottom: 24px;
}
.gameBody {
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
padding: 24px 30px;
background-color: #fff;
}
.win {
background-color: #009AFB;
}
.lose {
background-color: #FE4E52;
}
.levelInfo {
border-top-left-radius: 20px;
border-top-right-radius: 20px;
padding: 0 24px;
height: 72px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 24px;
position: relative;
}
.levelResult {
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 50px;
}
.playerSection {
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
}
.vs {
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 80px;
}
.userInfo {
display: flex;
flex-direction: column;
gap: 10px;
color: #465164;
}
.userName {
font-weight: 600;
max-width: 220px;
height: 44px;
line-height: 44px;
@include ellipsis();
}
.userBadge {
display: flex;
gap: 6px;
align-items: center;
}
.userIcon {
width: 60px;
height: 60px;
}
.userLevel {
font-size: 28px;
}
.gameStats {
display: flex;
margin-top: 20px;
}
.stats {
position: relative;
display: flex;
flex-direction: column;
flex: 1;
gap: 16px;
.value {
height: 46px;
line-height: 46px;
flex: 1;
font-weight: 500;
text-align: center;
font-size: 28px;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
&:nth-child(2) {
z-index: 2;
position: absolute;
left: 50%;
transform: translateX(-50%);
text-align: center;
width: 112px;
.value {
font-size: 24px;
color: #fff;
background: #93A0B7;
border-radius: 24px;
}
}
}
.statsWin .value {
color: #009AFB;
background-color: #E5F4FE;
}
.statsLose .value {
color: #FE4E52;
background-color: #FEEDED;
}
.diamond {
width: 30px;
height: 30px;
}
.emptyText {
margin-top: 48px;
text-align: center;
font-size: 14PX;
color: rgba(70, 81, 100, 0.50);
}
.spinWrap {
color: #9999;
padding: 12PX 0;
text-align: center;
}
.spin {
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.spinIcon {
border: 4px solid #1786F7;
border-top-color: inherit;
border-radius: 50%;
animation: spin 1s linear infinite;
width: 18PX;
height: 18PX;
}
.spinText {
font-size: 14PX;
margin-left: 12PX;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
\ No newline at end of file
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
import { rankTranslate, getImageForRank } from '@/pages/battles/utils'
import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare'
import styles from './index.module.scss'
const PageSize = 10
// @ts-ignore
Component({
properties: {
list: {
type: Array,
value: [],
},
},
data: {
styles,
assets,
assets2,
realList: [],
loading: false,
},
attached () {
this._hasNextPage = true
this._loading = false
this._currentPage = 0
this.loadMore()
},
methods: {
async loadMore () {
if (this._loading || !this._hasNextPage) return
this._loading = true
this.setData({ loading: true })
await new Promise((resolve) => setTimeout(resolve, 300))
const { list } = this.data
const currentPage = this._currentPage
const nextPage = currentPage + 1
let max = nextPage * PageSize
let hasNextPage = true
if (max >= list.length) {
max = list.length
hasNextPage = false
}
const start = currentPage * PageSize
const newList = list.slice(start, max).map((item) => ({
...item,
wined: item.result === 'WIN',
initiatorLevel: rankTranslate(item.initiatorLevel),
recipientLevel: rankTranslate(item.recipientLevel),
initiatorBadge: getImageForRank(item.initiatorLevel),
recipientBadge: getImageForRank(item.recipientLevel),
}))
const opts = {} as any
newList.forEach((item, index) => {
opts[`realList[${index + start}]`] = item
})
opts.loading = false
this.setData(opts, () => {
this._loading = false
this._currentPage = nextPage
this._hasNextPage = hasNextPage
})
},
},
})
<template name="pkItem">
<view class="{{styles.gameResult}}">
<!-- levelInfo -->
<view class="{{styles.levelInfo}} {{item.wined ? styles.win : styles.lose}}">
<text class="{{styles.levelName}}">{{item.stageName}}</text>
<image mode="widthFix" src="{{assets[item.wined ? 'win.png' : 'lose.png'].u}}" class="{{styles.levelResult}}"></image>
<text class="{{styles.levelDate}}">{{item.createTime}}</text>
</view>
<!-- gameBody -->
<view class="{{styles.gameBody}}">
<view class="{{styles.playerSection}}">
<!-- userInfo -->
<view class="{{styles.userInfo}}">
<text class="{{styles.userName}}">{{item.initiatorName}}</text>
<view class="{{styles.userBadge}}">
<image
class="{{styles.userIcon}}"
src="{{assets[item.initiatorBadge.small].u}}"
/>
<text class="{{styles.userLevel}}">{{item.initiatorLevel}}</text>
</view>
</view>
<!-- 战斗png -->
<image class="{{styles.vs}}" src="{{assets['vs.png'].u}}" />
<!-- userInfo 2 -->
<view class="{{styles.userInfo}}">
<text class="{{styles.userName}}" style="text-align: right">{{item.recipientName}}</text>
<view class="{{styles.userBadge}}">
<image
class="{{styles.userIcon}}"
src="{{assets[item.recipientBadge.small].u}}"
/>
<text class="{{styles.userLevel}}">{{item.recipientLevel}}</text>
</view>
</view>
</view>
<!-- gameStats -->
<view class="{{styles.gameStats}}">
<view class="{{styles.stats}} {{item.wined ? styles.statsWin : styles.statsLose}}">
<text class="{{styles.value}}">{{item.initiatorErrNum > 0 ? '错'+item.initiatorErrNum+'题' : '全对'}}</text>
<text class="{{styles.value}}">{{item.initiatorResultTime}}s</text>
<view class="{{styles.value}}">
<image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" />
<text>+10</text>
</view>
</view>
<!-- stats -->
<view class="{{styles.stats}}">
<text class="{{styles.value}}">答题对错</text>
<text class="{{styles.value}}">答题用时</text>
<text class="{{styles.value}}">PK奖励</text>
</view>
<!-- stats -->
<view class="{{styles.stats}} {{!item.wined ? styles.statsWin : styles.statsLose}}">
<text class="{{styles.value}}">{{item.recipientErrNum > 0 ? '错'+item.recipientErrNum+'题' : '全对'}}</text>
<text class="{{styles.value}}">{{item.recipientResultTime}}s</text>
<view class="{{styles.value}}">
<image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" />
<text>+15</text>
</view>
</view>
</view>
</view>
</view>
</template>
<block wx:for="{{ realList }}" wx:key="userId">
<template is="pkItem" data="{{ styles, item, assets, assets2, rankTranslate }}" />
</block>
<view class="{{styles.spinWrap}}" wx:if="{{loading}}">
<view class="{{styles.spin}}">
<view class="{{styles.spinIcon}}"></view>
<View class="{{styles.spinText}}">加载中</View>
</view>
</view>
<view class="{{styles.emptyText}}" wx:if="{{list.length < 1}}">暂无数据</view>
\ No newline at end of file
......@@ -6,11 +6,10 @@ import assetsPk from '@/assets/oss/assets-pk'
import assetsMainNext from '@/assets/oss/assets-main-next'
import classNames from 'classnames'
import { useRef, useMemo } from 'react'
import { badgeImages } from '../battles/const'
import styles from './index.module.scss'
import TopHeader from './components/top-header'
import ModalName from './components/modal-name'
import { rankTranslate } from '../battles/utils'
import { getImageForRank, rankTranslate } from '../battles/utils'
const AcceptPk = () => {
const [isVisible, { setTrue, setFalse }] = useBoolean(false)
......@@ -61,6 +60,10 @@ const AcceptPk = () => {
return userInfo.userId !== details?.userId
}, [userInfo, details])
const getImageForBadge = useMemo(() => {
return getImageForRank(details?.userRanks.level)
}, [details?.userRanks.level])
return (
<View className={styles.container}>
<TopHeader />
......@@ -108,10 +111,10 @@ const AcceptPk = () => {
<View className={styles.record}>
<View className={styles.rank}>
<Image
src={assetsPk[badgeImages.bronze.default].u}
{getImageForBadge && <Image
src={assetsPk[getImageForBadge.default].u}
className={styles.badgeIcon}
/>
/>}
<Text className={styles.rankText}>
{rankTranslate(details?.userRanks.level)}
</Text>
......
import { useEffect, useState, useMemo } from 'react'
import { useEffect, useState, useMemo, useCallback } from 'react'
import { View, Text, Image, ScrollView } from '@tarojs/components'
import classNames from 'classnames'
import Modal from '@/components/Modal'
import { useStoreState, useStoreActions } from '@/store/hooks'
import { convertDateTime } from '@/utils/day'
import { receivePkPrize } from '@/api/pk'
import assets from '@/assets/oss/assets-pk'
import { badgeImages } from '../const'
import { UserInfo, GameResultProps } from './game-result'
import styles from './battles-modal.module.scss'
import gameResultStyles from './game-result.module.scss'
import { rankTranslate } from '../utils'
import { rankTranslate, getImageForRank } from '../utils'
const BattlesModal = () => {
const isVisible = useStoreState(state => state.battlesModel.modalIsVisible)
const setModalIsVisible = useStoreActions(actions => actions.battlesModel.setModalIsVisible)
const summary = useStoreState((state) => state.battlesModel.summary)
const pkDetails = useStoreState((state) => state.userModel.pkDetails)
const pkGuideActive = useStoreState(state => state.guideModel.pkGuideActive)
const groupGuideActive = useStoreState(state => state.guideModel.groupGuideActive)
const mainGuideActive = useStoreState(state => state.guideModel.mainGuideActive)
......@@ -48,12 +48,23 @@ const BattlesModal = () => {
const hasAreaAndGrad = useMemo(() => !!userInfo.city && !!userInfo.grade, [userInfo])
const onClose = useCallback(() => {
receivePkPrize().finally(() => {
setModalIsVisible(false)
})
}, [setModalIsVisible])
const getImageForBadge = useMemo(() => {
return getImageForRank(pkDetails?.userRanks.level)
}, [pkDetails?.userRanks.level])
return (
<Modal
maskClosable={false}
isVisible={hasAreaAndGrad && enable && !pkGuideActive && !groupGuideActive && !mainGuideActive && isVisible}
wrapClassName={styles.modalWrap}
bodyClassName={styles.modalBody}
onClose={() => setModalIsVisible(false)}
onClose={onClose}
tilte={<Text style={{ marginLeft: 10 }}>· PK 战报</Text>}
>
<View className={styles.inner}>
......@@ -70,13 +81,13 @@ const BattlesModal = () => {
</View>
<View className={styles.details}>
<Image
src={assets[badgeImages.bronze.default].u}
{getImageForBadge && <Image
src={assets[getImageForBadge.default].u}
className={styles.badgeIcon}
/>
/>}
<View className={styles.detailsRight}>
<Text className={styles.badgeText}>
{rankTranslate(summary?.userRanks.level)}
{rankTranslate(pkDetails?.userRanks.level)}
</Text>
<View className={styles.badgeBar}>
{[...Array(3)].map((_, index) => (
......@@ -84,7 +95,9 @@ const BattlesModal = () => {
key={index}
className={classNames(
styles.badgeBarItem,
index < (summary?.userRanks.star || 0) ? styles.active : null
index < (pkDetails?.userRanks.star || 0)
? styles.active
: null
)}
></Text>
))}
......@@ -93,10 +106,13 @@ const BattlesModal = () => {
</View>
<ScrollView className={styles.gameResult} scrollY>
{summary && summary?.records.length > 0
? summary?.records.map((item) => <GameResult key={item.id} record={item} />)
: <Text className={styles.emptyText}>暂无PK记录</Text>
}
{pkDetails && pkDetails?.pkList.length > 0 ? (
pkDetails?.pkList.map((item) => (
<GameResult key={item.id} record={item} />
))
) : (
<Text className={styles.emptyText}>暂无PK记录</Text>
)}
</ScrollView>
</View>
</Modal>
......@@ -119,17 +135,36 @@ const GameResult = ({ record }: GameResultProps) => {
src={wined ? assets['win.png'].u : assets['lose.png'].u}
className={gameResultStyles.levelResult}
/>
<Text className={gameResultStyles.levelDate}>{convertDateTime(record.createTime)}</Text>
<Text className={gameResultStyles.levelDate}>
{convertDateTime(record.createTime)}
</Text>
</View>
<View className={styles.gameBody}>
<View className={styles.playerSection}>
<View className={classNames(styles.userInfo, wined ? styles.win : styles.lose)}>
<UserInfo name={record.initiatorName} />
<View
className={classNames(
styles.userInfo,
wined ? styles.win : styles.lose
)}
>
<UserInfo
level={record.initiatorLevel}
name={record.initiatorName}
/>
</View>
<Image className={gameResultStyles.vs} src={assets['vs.png'].u} />
<View className={classNames(styles.userInfo, !wined ? styles.win : styles.lose)}>
<UserInfo style={{ alignItems: 'flex-end' }} name={record.recipientName} />
<View
className={classNames(
styles.userInfo,
!wined ? styles.win : styles.lose
)}
>
<UserInfo
style={{ alignItems: 'flex-end' }}
level={record.recipientLevel}
name={record.recipientName}
/>
</View>
</View>
</View>
......
......@@ -64,6 +64,8 @@
.userName {
font-weight: 600;
max-width: 220px;
height: 44px;
line-height: 44px;
@include ellipsis();
}
......
......@@ -6,8 +6,8 @@ import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare'
import { PkRecord } from '@/api/pk'
import { badgeImages } from '../const'
import styles from './game-result.module.scss'
import { getImageForRank, rankTranslate } from '../utils'
export interface GameResultProps {
record: PkRecord
......@@ -29,15 +29,18 @@ const GameResult = ({ record }: GameResultProps) => {
src={assets[wined ? 'win.png' : 'lose.png'].u}
className={styles.levelResult}
/>
<Text className={styles.levelDate}>{convertDateTime(record.createTime)}</Text>
<Text className={styles.levelDate}>
{convertDateTime(record.createTime)}
</Text>
</View>
<View className={styles.gameBody}>
<View className={styles.playerSection}>
<UserInfo name={record.initiatorName} />
<UserInfo level={record.recipientLevel} name={record.initiatorName} />
<Image className={styles.vs} src={assets['vs.png'].u} />
<UserInfo
style={{ alignItems: 'flex-end' }}
level={record.recipientLevel}
name={record.recipientName}
/>
</View>
......@@ -57,15 +60,19 @@ const GameResult = ({ record }: GameResultProps) => {
)
}
export const UserInfo = (user: { name: string; style?: CSSProperties }) => (
export const UserInfo = (user: {
name: string
level: string
style?: CSSProperties
}) => (
<View style={user.style} className={styles.userInfo}>
<Text className={styles.userName}>{user.name}</Text>
<View className={styles.userBadge}>
<Image
className={styles.userIcon}
src={assets[badgeImages.diamond.small].u}
src={assets[getImageForRank(user.level).default].u}
/>
<Text className={styles.userLevel}>{user.name}</Text>
<Text className={styles.userLevel}>{rankTranslate(user.level)}</Text>
</View>
</View>
)
......
import { useMemo } from 'react'
import { View, Image, Text } from '@tarojs/components'
import classNames from 'classnames'
import { useStoreState } from '@/store/hooks'
import assets from '@/assets/oss/assets-pk'
import styles from './player-details.module.scss'
import { badgeImages } from '../const'
import { rankTranslate } from '../utils'
import { rankTranslate, getImageForRank } from '../utils'
const PlayerDetails = () => {
const summary = useStoreState((state) => state.battlesModel.summary)
const getImageForBadge = useMemo(() => {
return getImageForRank(summary?.userRanks.level)
}, [summary?.userRanks.level])
return (
<View className={styles.player}>
<View className={styles.playerHeader}>
<Image
src={assets[badgeImages.bronze.default].u}
{getImageForBadge && <Image
src={assets[getImageForBadge.default].u}
className={styles.badgeIcon}
></Image>
></Image>}
<Text className={styles.badgeText}>
{rankTranslate(summary?.userRanks.level)}
</Text>
......
.header {
position: fixed;
z-index: 2;
z-index: 100;
left: 0;
top: 0;
right: 0;
......
export const badgeImages = {
bronze: {
default: 'bronze.png',
small: 'bronze-small.png'
},
silver: {
default: 'silver.png',
small: 'silver-small.png'
},
gold: {
default: 'gold.png',
small: 'gold-small.png'
},
platinum: {
default: 'platinum.png',
small: 'platinum-small.png'
},
diamond: {
default: 'diamond.png',
small: 'diamond-small.png'
}
}
......@@ -3,4 +3,7 @@ export default definePageConfig({
navigationStyle: 'custom',
navigationBarTextStyle: 'white',
enableShareAppMessage: true,
usingComponents: {
'pk-record': '@/native-components/pk-record/index'
}
})
import { useMemo } from 'react'
import { getMenuButtonBoundingClientRect, useDidShow, navigateBack } from '@tarojs/taro'
import { useMemo, useRef } from 'react'
import {
getCurrentInstance,
getMenuButtonBoundingClientRect,
useDidShow, navigateBack,
useReachBottom,
} from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import Button from '@/components/Button'
import { useStoreState, useStoreActions } from '@/store/hooks'
import assets from '@/assets/oss/assets-pk'
import TopHeader from './components/top-header'
import PlayerDetails from './components/player-details'
import GameResult from './components/game-result'
import styles from './index.module.scss'
......@@ -28,6 +32,18 @@ const Battles = () => {
fetchUserSummary({})
})
const page = useMemo(() => getCurrentInstance()?.page, [])
const pkRecords = useRef(null)
useReachBottom(() => {
if (pkRecords.current) {
;(
page?.selectComponent?.(`#${(pkRecords.current as any).uid}`) as any
)?.loadMore()
}
})
return (
<View className={styles.wrapper}>
<TopHeader />
......@@ -52,10 +68,7 @@ const Battles = () => {
</View>
<View className={styles.gameResult}>
{summary && summary.records.length > 0
? summary.records.map((item) => <GameResult key={item.id} record={item} />)
: <Text className={styles.emptyText}>暂无PK记录</Text>
}
<pk-record list={summary?.records || []} ref={pkRecords} />
</View>
</View>
<View className={styles.bottom}>
......
......@@ -25,3 +25,36 @@ export function rankTranslate (rankWithLevel: string | undefined): string {
return `${rankName[rank as Rank]} ${toRomanNumeral(Number(level))}`
}
const badgeImages = {
bronze: {
default: 'bronze.png',
small: 'bronze-small.png',
},
silver: {
default: 'silver.png',
small: 'silver-small.png',
},
gold: {
default: 'gold.png',
small: 'gold-small.png',
},
platinum: {
default: 'platinum.png',
small: 'platinum-small.png',
},
diamond: {
default: 'diamond.png',
small: 'diamond-small.png',
},
}
export function getImageForRank (rankWithLevel: string | undefined) {
if (!rankWithLevel) {
return null
}
const [rank] = rankWithLevel.split('_')
return badgeImages[rank.toLowerCase()]
}
......@@ -27,7 +27,7 @@ const MainHeader = () => {
}
}, [sys, nav])
const cardNum = useStoreState(state => state.userModel.cardNum)
const pkDetails = useStoreState(state => state.userModel.pkDetails)
const point = useStoreState(state => state.userModel.point)
const userInfo = useStoreState(state => state.userModel.userInfo)
......@@ -51,7 +51,7 @@ const MainHeader = () => {
</View>
<View className={classNames(styles.ph, cs.bounce_btn)} onClick={goStore} hoverClass={cs.bounce_btn_hover} id="main_header_ph">
<Image src={assets['star.png'].u} className={styles.icon} />
<Text>{cardNum}</Text>
<Text>{pkDetails?.stars}</Text>
</View>
</View>
</View>
......
......@@ -15,7 +15,7 @@ const goStore = () => {
export default ({ isFirstStage }: { isFirstStage: boolean }) => {
const nav = useMemo(getMenuButtonBoundingClientRect, [])
const cardNum = useStoreState(state => state.userModel.cardNum)
const pkDetails = useStoreState(state => state.userModel.pkDetails)
const point = useStoreState(state => state.userModel.point)
const sys = useMemo(getSystemInfoSync, [])
......@@ -44,7 +44,7 @@ export default ({ isFirstStage }: { isFirstStage: boolean }) => {
</Scene3>
<View className={styles.ph} onClick={goStore}>
<Image src={assets['star.png'].u} className={styles.icon} />
<Text>{cardNum}</Text>
<Text>{pkDetails?.stars}</Text>
</View>
</View>
<View style={rightStyle} className={styles.right}></View>
......
import {
action, Action, Thunk, thunk, State
} from 'easy-peasy'
import { getAccountInfo, getSetting, type SettintType, updateUserInfo, type UpdateUserInfoIn, updateUserPhone, changeNickName } from '@/api'
import { fetchAccountInfo, getSetting, type SettintType, updateUserInfo, type UpdateUserInfoIn, updateUserPhone, changeNickName, AccountInfo } from '@/api'
import type { UserInfo } from '@/types'
import { ExchangeParams, accountExchange, pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
import { showModal, showLoading, hideLoading } from '@tarojs/taro'
import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { Deferred } from '@/utils/deferred'
import { AppStoreModel } from '../store-model'
......@@ -13,6 +13,7 @@ export interface UserModel {
/** 加入部落 */
joinDefered: Deferred | null;
userInfo: UserInfo;
pkDetails: Omit<AccountInfo, 'accounts'> | null;
cardNum: number;
point: number;
updating: boolean;
......@@ -33,6 +34,7 @@ export interface UserModel {
const userModel: UserModel = {
joinDefered: null,
pkDetails: null,
userInfo: getStorage(StorageKeys.userInfo)!,
isEyeProtectionMode: false,
cardNum: 0,
......@@ -162,11 +164,15 @@ const userModel: UserModel = {
fetchAccount: thunk(async (actions) => {
try {
const { data: list } = await getAccountInfo()
const cardNum = list.find(c => c.accountType === 'CARD')?.amount ?? 0
const point = list.find(c => c.accountType === 'POINT')?.amount ?? 0
actions.updateState({ cardNum, point })
return point
const { data, code } = await fetchAccountInfo()
if (code === 0) {
const { accounts, ...pkDetails } = data
const cardNum = accounts.find(c => c.accountType === 'CARD')?.amount ?? 0
const point = accounts.find(c => c.accountType === 'POINT')?.amount ?? 0
actions.updateState({ cardNum, point, pkDetails })
return point
}
return 0
} catch (err) {
actions.updateState({ cardNum: 0, point: 0 })
return 0
......
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