Commit 09fc26af authored by raca's avatar raca

feat: 优化

parent 59847ac9
/// <reference types="@tarojs/taro" /> /// <reference types="@tarojs/taro" />
declare module '*.png'; declare module '*.png'
declare module '*.gif'; declare module '*.gif'
declare module '*.jpg'; declare module '*.jpg'
declare module '*.jpeg'; declare module '*.jpeg'
declare module '*.svg'; declare module '*.svg'
declare module '*.css'; declare module '*.css'
declare module '*.less'; declare module '*.less'
declare module '*.scss'; declare module '*.scss'
declare module '*.sass'; declare module '*.sass'
declare module '*.styl'; declare module '*.styl'
type CountUpTime = React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { type CountUpTime = React.DetailedHTMLProps<
'maxValue'?: number; React.HTMLAttributes<HTMLElement> & {
'isDown'?: boolean; maxValue?: number
'startValue': number; isDown?: boolean
exceedTime: number; startValue: number
onTimeup?: () => void; exceedTime: number
onExceed?: () => void; onTimeup?: () => void
}, HTMLElement> onExceed?: () => void
},
HTMLElement
>
declare namespace JSX{ declare namespace JSX {
interface IntrinsicElements { interface IntrinsicElements {
// 扩展 IntrinsicElements 否则无法识别自定义标签 // 扩展 IntrinsicElements 否则无法识别自定义标签
'count-up-time': CountUpTime; 'count-up-time': CountUpTime
'number-keyboard': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { 'number-keyboard': React.DetailedHTMLProps<
onType?: (a: { detail: string }) => void; React.HTMLAttributes<HTMLElement> & {
}, HTMLElement>; onType?: (a: { detail: string }) => void
'game-rank': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & { },
HTMLElement
>
'game-rank': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
list: any[] list: any[]
}, HTMLElement>; },
HTMLElement
>,
'pk-record': React.DetailedHTMLProps<
React.HTMLAttributes<HTMLElement> & {
list: any[]
},
HTMLElement
>,
} }
} }
declare namespace NodeJS { declare namespace NodeJS {
interface ProcessEnv { 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' { declare module 'html-parse-stringify' {
export interface TagNode { export interface TagNode {
type: 'tag'; type: 'tag'
name: string; name: string
voidElement: boolean; voidElement: boolean
attrs: Record<string, string | undefined>; attrs: Record<string, string | undefined>
children: Node[]; children: Node[]
} }
export interface TextNode { export interface TextNode {
type: 'text'; type: 'text'
content: string; content: string
} }
export interface ComponentNode { export interface ComponentNode {
type: 'component'; type: 'component'
name: string; name: string
attrs: Record<string, string | undefined>; attrs: Record<string, string | undefined>
voidElement: boolean; voidElement: boolean
children: []; children: []
} }
export type Node = TagNode | TextNode | ComponentNode; export type Node = TagNode | TextNode | ComponentNode
export interface ParseOptions { export interface ParseOptions {
components: Record<string, boolean>; components: Record<string, boolean>
} }
namespace HtmlParseStringify { namespace HtmlParseStringify {
function parse(html: string, options?: ParseOptions): Node[]; function parse(html: string, options?: ParseOptions): Node[]
function stringify(doc: Node[]): string; function stringify(doc: Node[]): string
} }
export default HtmlParseStringify export default HtmlParseStringify
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
export default { export default {
pages: [ pages: [
'pages/main/main', 'pages/main/main',
'pages/market/index',
'pages/accept-pk/index', 'pages/accept-pk/index',
'pages/battles/index', 'pages/battles/index',
'pages/market/index',
'pages/prepare/index', 'pages/prepare/index',
'pages/group/index', 'pages/group/index',
'pages/game/play/index', 'pages/game/play/index',
......
@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' ...@@ -6,11 +6,10 @@ import assetsPk from '@/assets/oss/assets-pk'
import assetsMainNext from '@/assets/oss/assets-main-next' import assetsMainNext from '@/assets/oss/assets-main-next'
import classNames from 'classnames' import classNames from 'classnames'
import { useRef, useMemo } from 'react' import { useRef, useMemo } from 'react'
import { badgeImages } from '../battles/const'
import styles from './index.module.scss' import styles from './index.module.scss'
import TopHeader from './components/top-header' import TopHeader from './components/top-header'
import ModalName from './components/modal-name' import ModalName from './components/modal-name'
import { rankTranslate } from '../battles/utils' import { getImageForRank, rankTranslate } from '../battles/utils'
const AcceptPk = () => { const AcceptPk = () => {
const [isVisible, { setTrue, setFalse }] = useBoolean(false) const [isVisible, { setTrue, setFalse }] = useBoolean(false)
...@@ -61,6 +60,10 @@ const AcceptPk = () => { ...@@ -61,6 +60,10 @@ const AcceptPk = () => {
return userInfo.userId !== details?.userId return userInfo.userId !== details?.userId
}, [userInfo, details]) }, [userInfo, details])
const getImageForBadge = useMemo(() => {
return getImageForRank(details?.userRanks.level)
}, [details?.userRanks.level])
return ( return (
<View className={styles.container}> <View className={styles.container}>
<TopHeader /> <TopHeader />
...@@ -108,10 +111,10 @@ const AcceptPk = () => { ...@@ -108,10 +111,10 @@ const AcceptPk = () => {
<View className={styles.record}> <View className={styles.record}>
<View className={styles.rank}> <View className={styles.rank}>
<Image {getImageForBadge && <Image
src={assetsPk[badgeImages.bronze.default].u} src={assetsPk[getImageForBadge.default].u}
className={styles.badgeIcon} className={styles.badgeIcon}
/> />}
<Text className={styles.rankText}> <Text className={styles.rankText}>
{rankTranslate(details?.userRanks.level)} {rankTranslate(details?.userRanks.level)}
</Text> </Text>
......
...@@ -6,12 +6,11 @@ import { useStoreState, useStoreActions } from '@/store/hooks' ...@@ -6,12 +6,11 @@ import { useStoreState, useStoreActions } from '@/store/hooks'
import { convertDateTime } from '@/utils/day' import { convertDateTime } from '@/utils/day'
import { receivePkPrize } from '@/api/pk' import { receivePkPrize } from '@/api/pk'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import { badgeImages } from '../const'
import { UserInfo, GameResultProps } from './game-result' import { UserInfo, GameResultProps } from './game-result'
import styles from './battles-modal.module.scss' import styles from './battles-modal.module.scss'
import gameResultStyles from './game-result.module.scss' import gameResultStyles from './game-result.module.scss'
import { rankTranslate } 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)
...@@ -55,6 +54,10 @@ const BattlesModal = () => { ...@@ -55,6 +54,10 @@ const BattlesModal = () => {
}) })
}, [setModalIsVisible]) }, [setModalIsVisible])
const getImageForBadge = useMemo(() => {
return getImageForRank(pkDetails?.userRanks.level)
}, [pkDetails?.userRanks.level])
return ( return (
<Modal <Modal
maskClosable={false} maskClosable={false}
...@@ -78,10 +81,10 @@ const BattlesModal = () => { ...@@ -78,10 +81,10 @@ const BattlesModal = () => {
</View> </View>
<View className={styles.details}> <View className={styles.details}>
<Image {getImageForBadge && <Image
src={assets[badgeImages.bronze.default].u} src={assets[getImageForBadge.default].u}
className={styles.badgeIcon} 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)}
......
...@@ -6,9 +6,8 @@ import assets from '@/assets/oss/assets-pk' ...@@ -6,9 +6,8 @@ import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare' import assets2 from '@/assets/oss/assets-prepare'
import { PkRecord } from '@/api/pk' import { PkRecord } from '@/api/pk'
import { badgeImages } from '../const'
import styles from './game-result.module.scss' import styles from './game-result.module.scss'
import { rankTranslate } from '../utils' import { getImageForRank, rankTranslate } from '../utils'
export interface GameResultProps { export interface GameResultProps {
record: PkRecord record: PkRecord
...@@ -71,7 +70,7 @@ export const UserInfo = (user: { ...@@ -71,7 +70,7 @@ export const UserInfo = (user: {
<View className={styles.userBadge}> <View className={styles.userBadge}>
<Image <Image
className={styles.userIcon} className={styles.userIcon}
src={assets[badgeImages.diamond.small].u} src={assets[getImageForRank(user.level).default].u}
/> />
<Text className={styles.userLevel}>{rankTranslate(user.level)}</Text> <Text className={styles.userLevel}>{rankTranslate(user.level)}</Text>
</View> </View>
......
import { useMemo } from 'react'
import { View, Image, Text } from '@tarojs/components' import { View, Image, Text } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import { useStoreState } from '@/store/hooks' import { useStoreState } from '@/store/hooks'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import styles from './player-details.module.scss' import styles from './player-details.module.scss'
import { badgeImages } from '../const' import { rankTranslate, getImageForRank } from '../utils'
import { rankTranslate } from '../utils'
const PlayerDetails = () => { const PlayerDetails = () => {
const summary = useStoreState((state) => state.battlesModel.summary) const summary = useStoreState((state) => state.battlesModel.summary)
const getImageForBadge = useMemo(() => {
return getImageForRank(summary?.userRanks.level)
}, [summary?.userRanks.level])
return ( return (
<View className={styles.player}> <View className={styles.player}>
<View className={styles.playerHeader}> <View className={styles.playerHeader}>
<Image {getImageForBadge && <Image
src={assets[badgeImages.bronze.default].u} src={assets[getImageForBadge.default].u}
className={styles.badgeIcon} className={styles.badgeIcon}
></Image> ></Image>}
<Text className={styles.badgeText}> <Text className={styles.badgeText}>
{rankTranslate(summary?.userRanks.level)} {rankTranslate(summary?.userRanks.level)}
</Text> </Text>
......
.header { .header {
position: fixed; position: fixed;
z-index: 2; z-index: 100;
left: 0; left: 0;
top: 0; top: 0;
right: 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({ ...@@ -3,4 +3,7 @@ export default definePageConfig({
navigationStyle: 'custom', navigationStyle: 'custom',
navigationBarTextStyle: 'white', navigationBarTextStyle: 'white',
enableShareAppMessage: true, enableShareAppMessage: true,
usingComponents: {
'pk-record': '@/native-components/pk-record/index'
}
}) })
import { useMemo } from 'react' import { useMemo, useRef } from 'react'
import { getMenuButtonBoundingClientRect, useDidShow } from '@tarojs/taro' import {
getCurrentInstance,
getMenuButtonBoundingClientRect,
useDidShow,
useReachBottom,
} from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import Button from '@/components/Button' import Button from '@/components/Button'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import TopHeader from './components/top-header' import TopHeader from './components/top-header'
import PlayerDetails from './components/player-details' import PlayerDetails from './components/player-details'
import GameResult from './components/game-result'
import styles from './index.module.scss' import styles from './index.module.scss'
...@@ -22,6 +26,18 @@ const Battles = () => { ...@@ -22,6 +26,18 @@ const Battles = () => {
fetchUserSummary({}) 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 ( return (
<View className={styles.wrapper}> <View className={styles.wrapper}>
<TopHeader /> <TopHeader />
...@@ -46,10 +62,7 @@ const Battles = () => { ...@@ -46,10 +62,7 @@ const Battles = () => {
</View> </View>
<View className={styles.gameResult}> <View className={styles.gameResult}>
{summary && summary.records.length > 0 <pk-record list={summary?.records || []} ref={pkRecords} />
? summary.records.map((item) => <GameResult key={item.id} record={item} />)
: <Text className={styles.emptyText}>暂无PK记录</Text>
}
</View> </View>
</View> </View>
<View className={styles.bottom}> <View className={styles.bottom}>
......
...@@ -25,3 +25,36 @@ export function rankTranslate (rankWithLevel: string | undefined): string { ...@@ -25,3 +25,36 @@ export function rankTranslate (rankWithLevel: string | undefined): string {
return `${rankName[rank as Rank]} ${toRomanNumeral(Number(level))}` 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()]
}
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