Commit 80507fe6 authored by raca's avatar raca

feat: update

parent 971a0708
...@@ -41,7 +41,10 @@ declare namespace JSX { ...@@ -41,7 +41,10 @@ declare namespace JSX {
>, >,
'pk-record': React.DetailedHTMLProps< 'pk-record': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & { React.HTMLAttributes<HTMLElement> & {
list: any[] list: any[],
userId:number,
winPoint: number,
losePoint: number
}, },
HTMLElement HTMLElement
>, >,
......
...@@ -9,15 +9,18 @@ const PageSize = 10 ...@@ -9,15 +9,18 @@ const PageSize = 10
// @ts-ignore // @ts-ignore
Component({ Component({
properties: { properties: {
userId: Number,
winPoint: Number,
losePoint: Number,
list: { list: {
type: Array, type: Array,
value: [], value: [],
}, },
}, },
observers: { observers: {
'list' (val) { list (val) {
this.reset() this.reset()
} },
}, },
data: { data: {
styles, styles,
...@@ -61,14 +64,51 @@ Component({ ...@@ -61,14 +64,51 @@ Component({
} }
const start = currentPage * PageSize const start = currentPage * PageSize
const newList = list.slice(start, max).map((item) => ({
...item, const determineStyle = (isPlayer: boolean, isWin: boolean) => {
wined: item.result === 'WIN', return (isWin && isPlayer) || (!isWin && !isPlayer)
initiatorLevel: rankTranslate(item.initiatorLevel), ? styles.statsWin
recipientLevel: rankTranslate(item.recipientLevel), : styles.statsLose
initiatorBadge: getImageForRank(item.initiatorLevel), }
recipientBadge: getImageForRank(item.recipientLevel),
})) const determinePoint = (isPlayer: boolean, isWin: boolean) => {
return (isWin && isPlayer) || (!isWin && !isPlayer)
? this.data.winPoint
: this.data.losePoint
}
const newList = list.slice(start, max).map((item) => {
const isInitiator = item.initiator === this.data.userId
const isRecipient = item.recipient === this.data.userId
const isWin =
(item.result === 'WIN' && isInitiator) ||
(item.result === 'LOSE' && isRecipient)
const initiatorStyle = determineStyle(isInitiator, isWin)
const recipientStyle = determineStyle(isRecipient, isWin)
const initiatorPoint = determinePoint(isInitiator, isWin)
const recipientPoint = determinePoint(isRecipient, isWin)
const initiatorLevel = rankTranslate(item.initiatorLevel)
const recipientLevel = rankTranslate(item.recipientLevel)
const initiatorBadge = getImageForRank(item.initiatorLevel)
const recipientBadge = getImageForRank(item.recipientLevel)
return {
...item,
isWin,
initiatorStyle,
initiatorPoint,
initiatorBadge,
initiatorLevel,
recipientPoint,
recipientStyle,
recipientLevel,
recipientBadge,
}
})
const opts = {} as any const opts = {} as any
newList.forEach((item, index) => { newList.forEach((item, index) => {
......
<template name="pkItem"> <template name="pkItem">
<view class="{{styles.gameResult}}"> <view class="{{styles.gameResult}}">
<!-- levelInfo --> <!-- levelInfo -->
<view class="{{styles.levelInfo}} {{item.wined ? styles.win : styles.lose}}"> <view class="{{styles.levelInfo}} {{item.isWin ? styles.win : styles.lose}}">
<text class="{{styles.levelName}}">{{item.stageName}}</text> <text class="{{styles.levelName}}">{{item.stageName}}</text>
<image mode="widthFix" src="{{assets[item.wined ? 'win.png' : 'lose.png'].u}}" class="{{styles.levelResult}}"></image> <image mode="widthFix" src="{{assets[item.isWin ? 'win.png' : 'lose.png'].u}}" class="{{styles.levelResult}}"></image>
<text class="{{styles.levelDate}}">{{item.createTime}}</text> <text class="{{styles.levelDate}}">{{item.createTime}}</text>
</view> </view>
<!-- gameBody --> <!-- gameBody -->
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<view class="{{styles.playerSection}}"> <view class="{{styles.playerSection}}">
<!-- userInfo --> <!-- userInfo -->
<view class="{{styles.userInfo}}"> <view class="{{styles.userInfo}}">
<text class="{{styles.userName}}">{{item.initiatorName}}</text> <text class="{{styles.userName}}">{{item.initiatorName || '-'}}</text>
<view class="{{styles.userBadge}}"> <view class="{{styles.userBadge}}">
<image <image
class="{{styles.userIcon}}" class="{{styles.userIcon}}"
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<image class="{{styles.vs}}" src="{{assets['vs.png'].u}}" /> <image class="{{styles.vs}}" src="{{assets['vs.png'].u}}" />
<!-- userInfo 2 --> <!-- userInfo 2 -->
<view class="{{styles.userInfo}}"> <view class="{{styles.userInfo}}">
<text class="{{styles.userName}}" style="text-align: right">{{item.recipientName}}</text> <text class="{{styles.userName}}" style="text-align: right">{{item.recipientName || '-'}}</text>
<view class="{{styles.userBadge}}"> <view class="{{styles.userBadge}}">
<image <image
class="{{styles.userIcon}}" class="{{styles.userIcon}}"
...@@ -36,12 +36,12 @@ ...@@ -36,12 +36,12 @@
</view> </view>
<!-- gameStats --> <!-- gameStats -->
<view class="{{styles.gameStats}}"> <view class="{{styles.gameStats}}">
<view class="{{styles.stats}} {{item.wined ? styles.statsWin : styles.statsLose}}"> <view class="{{styles.stats}} {{item.initiatorStyle}}">
<text class="{{styles.value}}">{{item.initiatorErrNum > 0 ? '错'+item.initiatorErrNum+'题' : '全对'}}</text> <text class="{{styles.value}}">{{item.initiatorErrNum > 0 ? '错'+item.initiatorErrNum+'题' : '全对'}}</text>
<text class="{{styles.value}}">{{item.initiatorResultTime}}s</text> <text class="{{styles.value}}">{{item.initiatorResultTime}}s</text>
<view class="{{styles.value}}"> <view class="{{styles.value}}">
<image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" /> <image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" />
<text>+10</text> <text>+{{item.initiatorPoint}}</text>
</view> </view>
</view> </view>
<!-- stats --> <!-- stats -->
...@@ -51,12 +51,12 @@ ...@@ -51,12 +51,12 @@
<text class="{{styles.value}}">PK奖励</text> <text class="{{styles.value}}">PK奖励</text>
</view> </view>
<!-- stats --> <!-- stats -->
<view class="{{styles.stats}} {{!item.wined ? styles.statsWin : styles.statsLose}}"> <view class="{{styles.stats}} {{item.recipientStyle}}">
<text class="{{styles.value}}">{{item.recipientErrNum > 0 ? '错'+item.recipientErrNum+'题' : '全对'}}</text> <text class="{{styles.value}}">{{item.recipientErrNum > 0 ? '错'+item.recipientErrNum+'题' : '全对'}}</text>
<text class="{{styles.value}}">{{item.recipientResultTime}}s</text> <text class="{{styles.value}}">{{item.recipientResultTime}}s</text>
<view class="{{styles.value}}"> <view class="{{styles.value}}">
<image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" /> <image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" />
<text>+15</text> <text>+{{item.recipientPoint}}</text>
</view> </view>
</view> </view>
</view> </view>
......
...@@ -65,8 +65,10 @@ ...@@ -65,8 +65,10 @@
background: #F4F6F8; background: #F4F6F8;
border-radius: 56px; border-radius: 56px;
} }
.inputName { .inputName {
flex: 1; flex: 1;
text-align: left;
font-size: 36px; font-size: 36px;
font-weight: 600; font-weight: 600;
color: #465164; color: #465164;
......
import { View, RootPortal, Image, Button, ButtonProps, CommonEventFunction } from '@tarojs/components' import { View, RootPortal, Image, Button, ButtonProps, CommonEventFunction, Input } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import { useCallback, useRef, useState } from 'react' import { useCallback, useRef, useState } from 'react'
import { EyeProtectionView } from '@/components' import { EyeProtectionView } from '@/components'
...@@ -98,7 +98,11 @@ const ModalName = ({ ...@@ -98,7 +98,11 @@ const ModalName = ({
请输入您的角色名(7字以内) 请输入您的角色名(7字以内)
</View> </View>
<View className={styles.input}> <View className={styles.input}>
<View className={styles.inputName}>{name}</View> <Input
className={styles.inputName}
value={name as string}
onInput={(e) => setName(e.detail.value)}
/>
<Image <Image
src={assetsGuide['touzi.png'].u} src={assetsGuide['touzi.png'].u}
className={classNames( className={classNames(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
.arrow { .arrow {
position: absolute; position: absolute;
z-index: 999;
left: 10PX; left: 10PX;
width: 30PX; width: 30PX;
height: 30PX; height: 30PX;
......
...@@ -81,7 +81,6 @@ ...@@ -81,7 +81,6 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
text-align: center; text-align: center;
gap: 16px;
max-height: 500px; max-height: 500px;
} }
......
...@@ -13,15 +13,23 @@ import gameResultStyles from './game-result.module.scss' ...@@ -13,15 +13,23 @@ import gameResultStyles from './game-result.module.scss'
import { rankTranslate, getImageForRank } from '../utils' import { rankTranslate, getImageForRank } from '../utils'
const BattlesModal = () => { const BattlesModal = () => {
const isVisible = useStoreState(state => state.battlesModel.modalIsVisible) const isVisible = useStoreState((state) => state.battlesModel.modalIsVisible)
const setModalIsVisible = useStoreActions(actions => actions.battlesModel.setModalIsVisible) const setModalIsVisible = useStoreActions(
const fetchAccount = useStoreActions(actions => actions.userModel.fetchAccount) (actions) => actions.battlesModel.setModalIsVisible
)
const fetchAccount = useStoreActions(
(actions) => actions.userModel.fetchAccount
)
const pkDetails = useStoreState((state) => state.userModel.pkDetails) const pkDetails = useStoreState((state) => state.userModel.pkDetails)
const pkGuideActive = useStoreState(state => state.guideModel.pkGuideActive) const pkGuideActive = useStoreState((state) => state.guideModel.pkGuideActive)
const groupGuideActive = useStoreState(state => state.guideModel.groupGuideActive) const groupGuideActive = useStoreState(
const mainGuideActive = useStoreState(state => state.guideModel.mainGuideActive) (state) => state.guideModel.groupGuideActive
const joinDeferred = useStoreState(state => state.userModel.joinDefered) )
const userInfo = useStoreState(state => state.userModel.userInfo) const mainGuideActive = useStoreState(
(state) => state.guideModel.mainGuideActive
)
const joinDeferred = useStoreState((state) => state.userModel.joinDefered)
const userInfo = useStoreState((state) => state.userModel.userInfo)
const [enable, setEnable] = useState(false) const [enable, setEnable] = useState(false)
...@@ -45,7 +53,10 @@ const BattlesModal = () => { ...@@ -45,7 +53,10 @@ const BattlesModal = () => {
} }
}, [pkDetails, setModalIsVisible]) }, [pkDetails, setModalIsVisible])
const hasAreaAndGrad = useMemo(() => !!userInfo.city && !!userInfo.grade, [userInfo]) const hasAreaAndGrad = useMemo(
() => !!userInfo.city && !!userInfo.grade,
[userInfo]
)
const onClose = useCallback(() => { const onClose = useCallback(() => {
receivePkPrize().finally(() => { receivePkPrize().finally(() => {
...@@ -61,7 +72,14 @@ const BattlesModal = () => { ...@@ -61,7 +72,14 @@ const BattlesModal = () => {
return ( return (
<Modal <Modal
maskClosable={false} maskClosable={false}
isVisible={hasAreaAndGrad && enable && !pkGuideActive && !groupGuideActive && !mainGuideActive && isVisible} isVisible={
hasAreaAndGrad &&
enable &&
!pkGuideActive &&
!groupGuideActive &&
!mainGuideActive &&
isVisible
}
wrapClassName={styles.modalWrap} wrapClassName={styles.modalWrap}
bodyClassName={styles.modalBody} bodyClassName={styles.modalBody}
onClose={onClose} onClose={onClose}
...@@ -81,10 +99,12 @@ const BattlesModal = () => { ...@@ -81,10 +99,12 @@ const BattlesModal = () => {
</View> </View>
<View className={styles.details}> <View className={styles.details}>
{getImageForBadge && <Image {getImageForBadge && (
src={assets[getImageForBadge.default].u} <Image
className={styles.badgeIcon} src={assets[getImageForBadge.default].u}
/>} className={styles.badgeIcon}
/>
)}
<View className={styles.detailsRight}> <View className={styles.detailsRight}>
<Text className={styles.badgeText}> <Text className={styles.badgeText}>
{rankTranslate(pkDetails?.userRanks.level)} {rankTranslate(pkDetails?.userRanks.level)}
...@@ -108,7 +128,11 @@ const BattlesModal = () => { ...@@ -108,7 +128,11 @@ const BattlesModal = () => {
<ScrollView className={styles.gameResult} scrollY> <ScrollView className={styles.gameResult} scrollY>
{pkDetails && pkDetails?.pkList.length > 0 ? ( {pkDetails && pkDetails?.pkList.length > 0 ? (
pkDetails?.pkList.map((item) => ( pkDetails?.pkList.map((item) => (
<GameResult key={item.id} record={item} /> <GameResult
userId={userInfo.userId!}
key={item.id}
record={item}
/>
)) ))
) : ( ) : (
<Text className={styles.emptyText}>暂无PK记录</Text> <Text className={styles.emptyText}>暂无PK记录</Text>
...@@ -119,20 +143,32 @@ const BattlesModal = () => { ...@@ -119,20 +143,32 @@ const BattlesModal = () => {
) )
} }
const GameResult = ({ record }: GameResultProps) => { const determineStyle = (isPlayer: boolean, isWin: boolean) => {
const wined = record.result === 'WIN' return (isWin && isPlayer) || (!isWin && !isPlayer) ? styles.win : styles.lose
}
const GameResult = ({
record,
userId,
}: GameResultProps & { userId: number }) => {
const isInitiator = record.initiator === userId
const isRecipient = record.recipient === userId
const isWin = (record.result === 'WIN' && isInitiator) || (record.result === 'LOSE' && isRecipient)
const initiatorStyle = determineStyle(isInitiator, isWin)
const recipientStyle = determineStyle(isRecipient, isWin)
return ( return (
<View className={gameResultStyles.gameResult}> <View className={gameResultStyles.gameResult} style={{ marginBottom: 12 }}>
<View <View
className={classNames( className={classNames(
gameResultStyles.levelInfo, gameResultStyles.levelInfo,
wined ? gameResultStyles.win : gameResultStyles.lose isWin ? gameResultStyles.win : gameResultStyles.lose
)} )}
> >
<Text className={gameResultStyles.levelName}>{record.stageName}</Text> <Text className={gameResultStyles.levelName}>{record.stageName}</Text>
<Image <Image
mode="widthFix" mode="widthFix"
src={wined ? assets['win.png'].u : assets['lose.png'].u} src={isWin ? assets['win.png'].u : assets['lose.png'].u}
className={gameResultStyles.levelResult} className={gameResultStyles.levelResult}
/> />
<Text className={gameResultStyles.levelDate}> <Text className={gameResultStyles.levelDate}>
...@@ -145,7 +181,7 @@ const GameResult = ({ record }: GameResultProps) => { ...@@ -145,7 +181,7 @@ const GameResult = ({ record }: GameResultProps) => {
<View <View
className={classNames( className={classNames(
styles.userInfo, styles.userInfo,
wined ? styles.win : styles.lose initiatorStyle
)} )}
> >
<UserInfo <UserInfo
...@@ -157,7 +193,7 @@ const GameResult = ({ record }: GameResultProps) => { ...@@ -157,7 +193,7 @@ const GameResult = ({ record }: GameResultProps) => {
<View <View
className={classNames( className={classNames(
styles.userInfo, styles.userInfo,
!wined ? styles.win : styles.lose recipientStyle
)} )}
> >
<UserInfo <UserInfo
......
...@@ -2,7 +2,8 @@ import { useMemo, useRef } from 'react' ...@@ -2,7 +2,8 @@ import { useMemo, useRef } from 'react'
import { import {
getCurrentInstance, getCurrentInstance,
getMenuButtonBoundingClientRect, getMenuButtonBoundingClientRect,
useDidShow, navigateBack, useDidShow,
navigateBack,
useReachBottom, useReachBottom,
} from '@tarojs/taro' } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
...@@ -17,7 +18,13 @@ import styles from './index.module.scss' ...@@ -17,7 +18,13 @@ import styles from './index.module.scss'
const Battles = () => { const Battles = () => {
const nav = useMemo(getMenuButtonBoundingClientRect, []) const nav = useMemo(getMenuButtonBoundingClientRect, [])
const summary = useStoreState((state) => state.battlesModel.summary) const summary = useStoreState((state) => state.battlesModel.summary)
const addPkGuideTimes = useStoreActions((state) => state.guideModel.addPkGuideTimes) const setting = useStoreState((state) => state.userModel.setting)
const userInfo = useStoreState((state) => state.userModel.userInfo)
const addPkGuideTimes = useStoreActions(
(state) => state.guideModel.addPkGuideTimes
)
const getSetting = useStoreActions((actions) => actions.userModel.getSetting)
const fetchUserSummary = useStoreActions( const fetchUserSummary = useStoreActions(
(actions) => actions.battlesModel.fetchUserSummary (actions) => actions.battlesModel.fetchUserSummary
...@@ -30,6 +37,7 @@ const Battles = () => { ...@@ -30,6 +37,7 @@ const Battles = () => {
useDidShow(() => { useDidShow(() => {
fetchUserSummary({}) fetchUserSummary({})
getSetting()
}) })
const page = useMemo(() => getCurrentInstance()?.page, []) const page = useMemo(() => getCurrentInstance()?.page, [])
...@@ -68,7 +76,13 @@ const Battles = () => { ...@@ -68,7 +76,13 @@ const Battles = () => {
</View> </View>
<View className={styles.gameResult}> <View className={styles.gameResult}>
<pk-record list={summary?.records || []} ref={pkRecords} /> <pk-record
userId={userInfo.userId!}
winPoint={setting.personalPkWinPoint || 0}
losePoint={setting.personalPkLosePoint || 0}
list={summary?.records || []}
ref={pkRecords}
/>
</View> </View>
</View> </View>
<View className={styles.bottom}> <View className={styles.bottom}>
......
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