Commit 4c0fa8b5 authored by hewenhao's avatar hewenhao

feat: 性能优化

parent 82432df1
......@@ -4,9 +4,10 @@
BUILD_MODE=development
# 微信小程序appid
WEAPP_ID=wx693fe3460124d84b
WEAPP_ID=wx8f25def587982a19
# 服务器接口地址
SERVER_ENDPOINT=http://172.10.62.80
SERVER_ENDPOINT=https://geek.jkwljy.com
# 腾讯地图接口 api key
TARO_TECENT_LBS_KEY=X3OBZ-OKM3D-I2A4L-P3LQY-7C7ZZ-3KBFG
......
......@@ -26,7 +26,10 @@ declare namespace JSX{
'count-up-time': CountUpTime;
'number-keyboard': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
onType?: (a: { detail: string }) => void;
}, HTMLElement>
}, HTMLElement>;
'game-rank': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement> & {
list: any[]
}, HTMLElement>;
}
}
......
@import '@/styles/mixins.scss';
.thead {
height: 40PX;
background: #F7F9FC;
display: flex;
align-items: center;
font-size: 12PX;
padding: 0 32px;
color: rgba(70,81,100,0.5);
&_index {
width: 80px;
text-align: center;
padding-left: 3PX;
margin-right: 23PX;
}
&_username {
flex: 1;
}
&_result {
display: flex;
align-items: center;
font-size: 12PX;
font-weight: 400;
gap: 6PX;
color: rgba(70,81,100,0.7);
&_best {
font-size: 32px;
font-weight: 600;
color: #FE9B45;
}
}
}
.empty {
color: #9999;
font-size: 14PX;
margin: 24PX 0;
text-align: center;
}
.spinWrap {
color: #9999;
padding: 12PX 0;
text-align: center;
}
.item {
display: flex;
padding: 30px 32px;
align-items: center;
&.active {
background-color: #E4F1FF;
}
&_rank {
margin-right: 20px;
@include flexLayout(row, center);
&_icon {
width: 80px;
height: 80px;
margin: -17px 0;
display: block;
}
&_index {
display: block;
text-align: center;
width: 80px;
font-size: 36px;
font-weight: 500;
color: rgba(70,81,100,0.5);
}
}
&_username {
display: flex;
flex: 1;
align-items: center;
padding-right: 4PX;
&_text {
font-size: 14PX;
font-weight: 600;
color: #465164;
}
&_crown {
width: 36px;
height: 36px;
position: relative;
top: -1PX;
}
}
&_result {
@include flexLayout(row, center, center);
font-size: 12PX;
font-weight: 400;
gap: 6PX;
color: rgba(70,81,100,0.7);
&_best {
font-size: 32px;
font-weight: 600;
color: #FE9B45;
}
}
}
.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);
}
}
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
import assets from '@/assets/oss/assets-group'
import styles from './index.module.scss'
const PageSize = 10
// @ts-ignore
Component({
properties: {
list: {
type: Array,
value: []
}
},
data: {
styles,
assets,
realList: [],
me: null,
loading: false
},
attached () {
this._hasNextPage = true
this._loading = false
this._currentPage = 0
this.loadMore()
const me = this.data.list?.find(c => c.me)
if (me && me.no > 3) {
this.setData({
me
})
}
},
methods: {
async loadMore () {
if (this._loading || !this._hasNextPage) return
this._loading = true
this.setData({ loading: true })
await new Promise(resolve => setTimeout(resolve, 1000))
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)
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
console.log(11111111, this._loading, hasNextPage)
this._hasNextPage = hasNextPage
})
}
}
})
<template name="rankItem">
<view class="{{styles.item}} {{ item.me ? styles.active : '' }}">
<view class="{{styles.item_rank}}">
<image
wx:if="{{item.no === 1}}"
class="{{styles.item_rank_icon}}"
src="{{assets['rank-1.png'].u}}"
/>
<image
wx:elif="{{item.no === 2}}"
class="{{styles.item_rank_icon}}"
src="{{assets['rank-2.png'].u}}"
/>
<image
wx:elif="{{item.no === 3}}"
class="{{styles.item_rank_icon}}"
src="{{assets['rank-3.png'].u}}"
/>
<text wx:else class="{{styles.item_rank_index}}">{{item.no}}</text>
</view>
<view class="{{styles.item_username}}">
<view class="{{styles.item_username_text}}">
{{item.nickName || '-'}} <text wx:if="{{item.me}}">(你)</text>
</view>
<image
wx:if="{{item.identity === 'LEADER'}}"
class="{{styles.item_username_crown}}"
src="{{assets['crown-small.png'].u}}"
/>
</view>
<view class="{{styles.item_result}}">
<text class="{{styles.item_result_first}}">{{utils.format(item.firstResultTime)}}秒</text>
<text>|</text>
<text class="{{styles.item_result_best}}">{{utils.format(item.bestResultTime)}}秒</text>
</view>
</view>
</template>
<view class="{{styles.thead}}">
<text class="{{styles.thead_index}}">名次</text>
<text class="{{styles.thead_username}}">用户名</text>
<view class="{{styles.thead_result}}">
<text class="{{styles.thead_result_first}}">首次</text>
<text>|</text>
<text class="{{styles.thead_result_best}}">最佳</text>
</view>
</view>
<template is="rankItem" wx:if="{{me}}" data="{{ styles, item: me, assets }}"/>
<block wx:for="{{ realList }}" wx:key="userId">
<template is="rankItem" data="{{ styles, item, assets }}"/>
</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.empty}}" wx:if="{{list.length < 1}}">暂无数据</view>
<wxs module="utils">
module.exports = {
format : function (val) {
if (typeof val === 'number') {
return val.toFixed(1)
}
return '-'
},
}
</wxs>
export default definePageConfig({
enableShareAppMessage: true,
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom'
navigationStyle: 'custom',
usingComponents: {
'game-rank': '@/native-components/rank/index'
}
})
......@@ -21,7 +21,7 @@ import Tabs, { type TabItem } from './components/tabs'
import TopBar from './components/top-bar'
import MainHeader from './components/main-header'
import AnswerCardModal from './components/answer-card-modal'
import { renderList, renderTribePage } from './render'
import { renderTribePage, RankList } from './render'
import styles from './index.module.scss'
......@@ -51,7 +51,9 @@ const Prepare = () => {
const tabs: TabItem[] = [
{
label: `${userInfo.city === '其他' ? '' : (userInfo.city ?? '')}排行榜`,
children: renderList(stageDetail?.ranks || [])
children: (
<RankList list={stageDetail?.ranks ?? []} />
)
},
{
label: '学习部落排行榜',
......
import { View, Text, Image } from '@tarojs/components'
import { switchTab } from '@tarojs/taro'
import classNames from 'classnames'
import { NextStep, type StageRank } from '@/api/game'
import { switchTab, useReachBottom, getCurrentInstance } from '@tarojs/taro'
import { useRef, useMemo } from 'react'
import { type StageRank } from '@/api/game'
import assets from '@/assets/oss/assets-prepare'
import assetsGroup from '@/assets/oss/assets-group'
import Thead from './components/thead'
import styles from './index.module.scss'
import { formatNextStep } from './format'
export const renderList = (list: StageRank[]) => {
const isEmpty = list.length < 1
const user = list.find(item => item.me)
return (
<>
<Thead />
{user && user.no > 3 && renderItem(user)}
{list.map(renderItem)}
{isEmpty && <View className={styles.empty}>暂无数据</View>}
</>
)
type RankListProps = {
list: StageRank[]
}
export const renderItem = (item: StageRank) => {
return (
<View key={item.userId} className={classNames(styles.item, { [styles.active]: item.me })}>
<View className={styles.item_rank}>
{[1, 2, 3].includes(item.no)
? <Image className={styles.item_rank_icon} src={assetsGroup[`rank-${item.no}.png`].u} />
: <Text className={styles.item_rank_index}>{item.no}</Text>
export function RankList (props: RankListProps) {
const { list } = props
const page = useMemo(() => getCurrentInstance()?.page, [])
const gameRank = useRef(null)
useReachBottom(() => {
if (gameRank.current) {
(page?.selectComponent?.(`#${(gameRank.current as any).uid}`) as any)?.loadMore()
}
</View>
<View className={styles.item_username}>
<Text className={styles.item_username_text}>
{item.nickName || '-'}
{item.me && <Text>(你)</Text>}
</Text>
{item.identity === 'LEADER' && <Image className={styles.item_username_crown} src={assetsGroup['crown-small.png'].u} />}
</View>
<View className={styles.item_result}>
<Text className={styles.item_result_first}>{item.firstResultTime?.toFixed(1) || '-'}秒</Text>
<Text>|</Text>
<Text className={styles.item_result_best}>{item.bestResultTime?.toFixed(1) || '-'}秒</Text>
</View>
</View>
})
return (
<game-rank list={list} ref={gameRank} />
)
}
......@@ -61,7 +40,7 @@ const renderTribeList = (list: StageRank[], groupNo?: string) => {
return (
<View style={{ paddingBottom: 70 }}>
<Text className={styles.tribe_title}>{groupNo}部落</Text>
{renderList(list)}
<RankList list={list} />
</View>
)
}
......
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