Commit c6523e1b authored by raca's avatar raca

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

Merge branch 'feature/2023-06-12-v1.1' of https://118.24.71.244/hewenhao/GeekLearnMathWeapp into feature/2023-06-12-v1.1
parents 80507fe6 a5e4db02
......@@ -41,10 +41,8 @@ declare namespace JSX {
>,
'pk-record': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
list: any[],
userId:number,
winPoint: number,
losePoint: number
list: any[];
config: any;
},
HTMLElement
>,
......
......@@ -72,6 +72,9 @@ export interface Stage {
/** 星星限制数量 */
limitStar: number;
/** 拥有星星数量 */
holdStar: number;
/** pk负 */
pkLoseNum: number | null;
/** pk胜场 */
......
......@@ -64,7 +64,7 @@
.userName {
font-weight: 600;
max-width: 220px;
max-width: 240px;
height: 44px;
line-height: 44px;
@include ellipsis();
......
......@@ -3,22 +3,29 @@
import { rankTranslate, getImageForRank } from '@/pages/battles/utils'
import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare'
import { getStorage, StorageKeys } from '@/utils/storage'
import styles from './index.module.scss'
const PageSize = 10
const determineStyle = (isPlayer: boolean, isWin: boolean) => {
return (isWin && isPlayer) || (!isWin && !isPlayer) ? styles.statsWin : styles.statsLose
}
// @ts-ignore
Component({
properties: {
userId: Number,
winPoint: Number,
losePoint: Number,
list: {
type: Array,
value: [],
},
config: {
type: Object,
value: {}
}
},
observers: {
list (val) {
'list' () {
this.reset()
},
},
......@@ -34,6 +41,7 @@ Component({
this._loading = false
this._currentPage = 0
this.loadMore()
this._userInfo = getStorage(StorageKeys.userInfo)
},
methods: {
reset () {
......@@ -63,50 +71,31 @@ Component({
hasNextPage = false
}
const start = currentPage * PageSize
const userInfo = this._userInfo
const determineStyle = (isPlayer: boolean, isWin: boolean) => {
return (isWin && isPlayer) || (!isWin && !isPlayer)
? styles.statsWin
: styles.statsLose
const isWin = item => {
if (item.initiator === userInfo?.userId) {
return item.result === 'WIN'
}
const determinePoint = (isPlayer: boolean, isWin: boolean) => {
return (isWin && isPlayer) || (!isWin && !isPlayer)
? this.data.winPoint
: this.data.losePoint
return item.result === 'LOSE'
}
const start = currentPage * PageSize
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)
const isInitiator = item.initiator === userInfo?.userId
const isRecipient = item.recipient === userInfo?.userId
const initiatorStyle = determineStyle(isInitiator, isWin(item))
const recipientStyle = determineStyle(isRecipient, isWin(item))
return {
...item,
isWin,
wined: isWin(item),
initiatorStyle,
initiatorPoint,
initiatorBadge,
initiatorLevel,
recipientPoint,
recipientStyle,
recipientLevel,
recipientBadge,
initiatorLevel: rankTranslate(item.initiatorLevel),
recipientLevel: rankTranslate(item.recipientLevel),
initiatorBadge: getImageForRank(item.initiatorLevel),
recipientBadge: getImageForRank(item.recipientLevel),
}
})
const opts = {} as any
......
<template name="pkItem">
<view class="{{styles.gameResult}}">
<!-- levelInfo -->
<view class="{{styles.levelInfo}} {{item.isWin ? styles.win : styles.lose}}">
<view class="{{styles.levelInfo}} {{item.wined ? styles.win : styles.lose}}">
<text class="{{styles.levelName}}">{{item.stageName}}</text>
<image mode="widthFix" src="{{assets[item.isWin ? 'win.png' : 'lose.png'].u}}" class="{{styles.levelResult}}"></image>
<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 -->
......@@ -11,7 +11,7 @@
<view class="{{styles.playerSection}}">
<!-- userInfo -->
<view class="{{styles.userInfo}}">
<text class="{{styles.userName}}">{{item.initiatorName || '-'}}</text>
<text class="{{styles.userName}}">{{item.initiatorName}}</text>
<view class="{{styles.userBadge}}">
<image
class="{{styles.userIcon}}"
......@@ -24,7 +24,7 @@
<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>
<text class="{{styles.userName}}" style="text-align: right">{{item.recipientName}}</text>
<view class="{{styles.userBadge}}">
<image
class="{{styles.userIcon}}"
......@@ -41,7 +41,7 @@
<text class="{{styles.value}}">{{item.initiatorResultTime}}s</text>
<view class="{{styles.value}}">
<image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" />
<text>+{{item.initiatorPoint}}</text>
<text>+{{ item.result === 'WIN' ? config.personalPkWinPoint : config.personalPkLosePoint }}</text>
</view>
</view>
<!-- stats -->
......@@ -56,7 +56,7 @@
<text class="{{styles.value}}">{{item.recipientResultTime}}s</text>
<view class="{{styles.value}}">
<image class="{{styles.diamond}}" src="{{assets2['diamond.png'].u}}" />
<text>+{{item.recipientPoint}}</text>
<text>+{{ item.result === 'WIN' ? config.personalPkLosePoint : config.personalPkWinPoint }}</text>
</view>
</view>
</view>
......@@ -64,7 +64,7 @@
</view>
</template>
<block wx:for="{{ realList }}" wx:key="userId">
<template is="pkItem" data="{{ styles, item, assets, assets2, rankTranslate }}" />
<template is="pkItem" data="{{ styles, item, assets, assets2, rankTranslate, config }}" />
</block>
<view class="{{styles.spinWrap}}" wx:if="{{loading}}">
<view class="{{styles.spin}}">
......
......@@ -18,13 +18,9 @@ import styles from './index.module.scss'
const Battles = () => {
const nav = useMemo(getMenuButtonBoundingClientRect, [])
const summary = useStoreState((state) => state.battlesModel.summary)
const addPkGuideTimes = useStoreActions((state) => state.guideModel.addPkGuideTimes)
const getSetting = useStoreActions((state) => state.userModel.getSetting)
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(
(actions) => actions.battlesModel.fetchUserSummary
......@@ -76,13 +72,7 @@ const Battles = () => {
</View>
<View className={styles.gameResult}>
<pk-record
userId={userInfo.userId!}
winPoint={setting.personalPkWinPoint || 0}
losePoint={setting.personalPkLosePoint || 0}
list={summary?.records || []}
ref={pkRecords}
/>
<pk-record list={summary?.records || []} config={setting} ref={pkRecords} />
</View>
</View>
<View className={styles.bottom}>
......
......@@ -19,6 +19,7 @@ const BattleComplete = ({ pkResult }: BattleCompleteProps) => {
const updateState = useStoreActions(actions => actions.mainModel.updateState)
const setting = useStoreState(state => state.userModel.setting)
const getSetting = useStoreActions(actions => actions.userModel.getSetting)
const userInfo = useStoreState(state => state.userModel.userInfo)
const upSelf = () => {
updateState({ isCreatePkShow: false, currentPkStage: null })
......@@ -35,11 +36,23 @@ const BattleComplete = ({ pkResult }: BattleCompleteProps) => {
return getUserRank(pkResult?.recipientLevel ?? '')
}, [pkResult])
const isWin = useMemo(() => {
/** 从发起者角度算 */
const isMySelf = useMemo(() => {
return userInfo.userId && userInfo.userId === pkResult?.initiator
}, [userInfo, pkResult])
/** 发起者输了 */
const isInitiatorFail = useMemo(() => {
return pkResult?.result === 'LOSE'
}, [pkResult])
const headerWin = useMemo(() => {
if (isMySelf) {
return pkResult?.result === 'WIN'
}
/** 从发起者角度算 */
return isInitiatorFail
}, [pkResult, isMySelf, isInitiatorFail])
useEffect(() => {
if (pkResult) {
getSetting()
......@@ -47,11 +60,11 @@ const BattleComplete = ({ pkResult }: BattleCompleteProps) => {
}, [getSetting, pkResult])
const score = useMemo(() => {
if (isWin) {
if (headerWin) {
return setting?.personalPkWinPoint ?? 0
}
return setting?.personalPkLosePoint ?? 0
}, [setting, isWin])
}, [setting, headerWin])
if (!pkResult) {
return null
......@@ -60,14 +73,14 @@ const BattleComplete = ({ pkResult }: BattleCompleteProps) => {
return (
<View className={styles.wrap}>
<View className={styles.gap_1}></View>
<Image src={isWin ? assetsGame['pk-success.png'].u : assetsGame['pk-fail.png'].u} className={styles.pk_result} mode="heightFix"></Image>
<Image src={headerWin ? assetsGame['pk-success.png'].u : assetsGame['pk-fail.png'].u} className={styles.pk_result} mode="heightFix"></Image>
<View className={styles.game_bonus}>
<Image src={assetsPrepare['diamond.png'].u} className={styles.diamond}></Image>
水晶 +{score}
</View>
<View className={styles.game_role}>
<View className={classNames(styles.game_role_left, !isWin && styles.is_fail)}>
<View className={classNames(styles.game_role_left, !isInitiatorFail && styles.is_fail)}>
<View className={styles.user_name}>{pkResult.recipientName}</View>
<View className={styles.user_level}>
<Image src={getUserLevelIcon(recipientLevel.level)} className={styles.level_icon} />
......@@ -79,7 +92,7 @@ const BattleComplete = ({ pkResult }: BattleCompleteProps) => {
<View className={classNames(styles.info, styles.is_info_2)}>答题用时:{pkResult.recipientResultTime}s</View>
</View>
<View className={classNames(styles.game_role_right, isWin && styles.is_fail)}>
<View className={classNames(styles.game_role_right, isInitiatorFail && styles.is_fail)}>
<View className={styles.user_name}>{pkResult.initiatorName}</View>
<View className={styles.user_level}>
<Image src={getUserLevelIcon(initiatorLevel.level)} className={styles.level_icon} />
......
......@@ -18,7 +18,7 @@ const Scene = () => {
}
return (
<View className={styles.wrap}>
<View className={styles.wrap} catchMove>
<Image src={assetsGuide['cat-2.png'].u} className={styles.cat} />
<View className={styles.dialog}>
<View>
......
......@@ -91,13 +91,13 @@ const CreatePk = (props: CreatePkProps) => {
return (
<>
{visible && (<PkGuide />)}
<View className={classNames(styles.close_wrap, visible && styles.is_show)} style={closeStyle}>
<View className={classNames(styles.close_wrap, visible && styles.is_show)} style={closeStyle} catchMove>
<View className={styles.close} onTouchStart={closeModal} data-name="关闭发起PK">
<Image src={assetsMainNext['pk-close.png'].u} className={styles.close_icon}></Image>
</View>
</View>
<View className={classNames(styles.top, visible && styles.is_show)}>
<View className={classNames(styles.top, visible && styles.is_show)} catchMove>
<Image src={assetsMainNext['pk-top.png'].u} className={styles.bg_top} mode="widthFix"></Image>
<View className={styles.top_content}>
<View className={styles.pk_history} style={historyStyle} onClick={() => navigateTo({ url: '/pages/battles/index' })}>
......@@ -115,7 +115,7 @@ const CreatePk = (props: CreatePkProps) => {
</View>
</View>
<View className={classNames(styles.bottom, visible && styles.is_show)}>
<View className={classNames(styles.bottom, visible && styles.is_show)} catchMove>
<Image src={assetsMainNext['pk-slogen.png'].u} className={styles.pk_slogan}></Image>
<Image src={assetsMainNext['pk-bottom.png'].u} className={styles.bg_bottom} mode="widthFix"></Image>
<View className={styles.bottom_content}>
......
......@@ -18,7 +18,7 @@ const Scene = () => {
}
return (
<View className={styles.wrap}>
<View className={styles.wrap} catchMove>
<Image src={assetsGuide['cat-2.png'].u} className={styles.cat} />
<View className={styles.dialog}>
<View>
......
......@@ -60,7 +60,7 @@ function stageToStageNext (stageList: Stage[]): {nextList: StageNext[]; showList
/** 设置pk历史页面返回后引导 */
if (currentIndex !== -1) {
let current = currentIndex
while (current) {
while (current >= 0) {
const currentItem = showList[current]
if (currentItem && currentItem.status === StageStatus.PASSED && currentItem.type !== StageType.Special) {
currentItem.$lastPassedStage = true
......
......@@ -153,7 +153,6 @@ const StageComp = (props: StageProps) => {
const nextPkGuide = useStoreActions(state => state.guideModel.nextPkGuide)
const showPkGuideFromHis = useStoreState(state => state.guideModel.showPkGuideFromHis)
const updateGuideState = useStoreActions(state => state.guideModel.updateState)
const pkDetails = useStoreState(state => state.userModel.pkDetails)
const isSpecialRound = useMemo(() => {
return stage.type === StageType.Special
......@@ -174,7 +173,7 @@ const StageComp = (props: StageProps) => {
const handleClick = () => {
if (stage.status !== StageStatus.DISABLED || !isProduction) {
if (isSpecialRound) {
if ((pkDetails?.stars ?? 0) < stage.limitStar) {
if ((stage.holdStar ?? 0) < stage.limitStar) {
showToast({ title: '星星数量不够,快去收集吧~', icon: 'none' })
return
}
......@@ -218,7 +217,7 @@ const StageComp = (props: StageProps) => {
}
case StageStatus.CURRENT: {
if (isSpecialRound && (pkDetails?.stars ?? 0) < stage.limitStar) {
if (isSpecialRound && (stage.holdStar ?? 0) < stage.limitStar) {
return (
<Image src={getLockedIcon(stage.type).u} className={getIconClassNames(stage.type)} />
)
......@@ -301,7 +300,7 @@ const StageComp = (props: StageProps) => {
{isSpecialRound ? (
<View className={styles.special_name}>
<Image src={assetsMainNext['star.png'].u} className={styles.special_star} />
星星 {pkDetails?.stars ?? 0}/{stage.limitStar}
星星 {stage.holdStar ?? 0}/{stage.limitStar}
</View>
) : (
<View>{!isProduction ? `${stage.id}.` : ''}{stage.name}</View>
......
......@@ -83,11 +83,12 @@ const guideModel: GuideModel = {
addPkGuideTimes: action((state) => {
let next
if (state.pkGuideTimes !== null) {
if (state.pkGuideTimes) {
/** 只显示3次pk历史pk引导 */
if (state.pkGuideTimes >= 3) {
return
}
next = state.pkGuideTimes + 1
next = (+state.pkGuideTimes) + 1
} else {
next = 1
}
......
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