木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

353 lines
7.5 KiB

<template>
<view class="ranking-page">
<view class="back-button" @click="goBack">
<uv-icon name="arrow-left" color="#ffffff" size="20"></uv-icon>
</view>
<!-- 排行榜背景 -->
<view class="ranking-background">
<image src="/subPages/static/rank_bg.png" class="bg-image" mode="aspectFill"></image>
<!-- 返回按钮 -->
<!-- 前三名定位布局 -->
<view class="top-three">
<!-- 第二名 -->
<view class="rank-item rank-second">
<image src="/subPages/static/second.png" class="rank-badge"></image>
<image :src="topThree[1].headImage" class="avatar"></image>
<view class="name">{{ topThree[1].nickName }}</view>
<view class="score">{{ topThree[1].score }}积分</view>
</view>
<!-- 第一名 -->
<view class="rank-item rank-first">
<image src="/subPages/static/first.png" class="rank-badge"></image>
<image :src="topThree[0].headImage" class="avatar"></image>
<view class="name">{{ topThree[0].nickName }}</view>
<view class="score">{{ topThree[0].score }}积分</view>
</view>
<!-- 第三名 -->
<view class="rank-item rank-third">
<image src="/subPages/static/third.png" class="rank-badge"></image>
<image :src="topThree[2].headImage" class="avatar"></image>
<view class="name">{{ topThree[2].nickName }}</view>
<view class="score">{{ topThree[2].score }}积分</view>
</view>
</view>
</view>
<!-- 我的排名 -->
<view class="my-ranking" v-if="myRanking.rank">
<view class="my-rank-number">{{ myRanking.rank }}</view>
<view class="my-rank-label">我的排名</view>
<image :src="myRanking.headImage" class="my-avatar"></image>
<view class="my-name">{{ myRanking.nickName }}</view>
<view class="my-score">{{ myRanking.score }}积分</view>
</view>
<!-- 排行榜列表 -->
<view class="ranking-list">
<view class="list-item" v-for="(item, index) in rankingList" :key="index">
<view class="rank-number">{{ item.rank }}</view>
<image :src="item.headImage" class="list-avatar"></image>
<view class="user-info">
<view class="user-name">{{ item.nickName }}</view>
</view>
<view class="user-score">{{ item.score }}积分</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'Ranking',
data() {
return {
myRanking: {
},
rankingList: [
],
topThree: [
],
pageNo: 1,
pageSize: 10
}
},
async onShow() {
this.initData()
// 获取排行榜数据
await this.getRankingData();
},
methods: {
initData() {
this.pageNo = 1,
this.rankingList = [],
this.topThree = []
},
async onPullDownRefresh() {
this.initData()
await this.getRankingData()
uni.stopPullDownRefresh()
},
async onReachBottom() {
await this.getRankingData()
},
goBack() {
uni.navigateBack();
},
async getRankingData() {
let params = {}
// 有登录的情况下 才会显示我的排名
if (uni.getStorageSync('token')) {
params = {
token: uni.getStorageSync('token')
}
}
const res = await this.$api.score.queryScoreRank({
pageNo: this.pageNo,
pageSize: this.pageSize,
...params
})
if (res.result.scoreList.records.length) {
this.rankingList.push(...res.result.scoreList.records.slice(3))
this.topThree.push(...res.result.scoreList.records.slice(0, 3))
this.myRanking = res.result.myScore
this.pageNo++
}else {
uni.showToast({
title: '暂无数据',
icon: 'none'
})
}
}
}
}
</script>
<style lang="scss" scoped>
// @import '@/uni.scss';
.ranking-page {
min-height: 100vh;
background-color: #f5f5f5;
}
.back-button {
position: fixed;
top: 70rpx;
left: 40rpx;
width: 70rpx;
height: 70rpx;
// background-color: rgba(0, 0, 0, 0.3);
// border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
&:active {
background-color: rgba(0, 0, 0, 0.5);
}
}
.ranking-background {
position: relative;
width: 100%;
height: 600rpx;
.bg-image {
width: 100%;
height: 100%;
}
.back-button {
position: absolute;
top: 60rpx;
left: 30rpx;
width: 60rpx;
height: 60rpx;
// background-color: rgba(0, 0, 0, 0.3);
// border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
&:active {
background-color: rgba(0, 0, 0, 0.5);
}
}
.top-three {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: flex-end;
justify-content: center;
padding-bottom: 80rpx;
.rank-item {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
margin: 0 40rpx;
.rank-badge {
width: 60rpx;
height: 60rpx;
margin-bottom: 10rpx;
}
.avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
margin-bottom: 10rpx;
border: 4rpx solid #fff;
}
.name {
font-size: 24rpx;
color: #fff;
margin-bottom: 5rpx;
font-weight: bold;
}
.score {
font-size: 20rpx;
color: #fff;
opacity: 0.9;
}
}
.rank-first {
transform: translateY(-40rpx);
.avatar {
width: 100rpx;
height: 100rpx;
}
.rank-badge {
width: 80rpx;
height: 80rpx;
}
}
.rank-second {
order: -1;
}
.rank-third {
order: 1;
}
}
}
.my-ranking {
background: #e1f2ff;
border-radius: 12rpx;
margin: 20rpx 30rpx 20rpx 30rpx;
padding: 30rpx;
display: flex;
align-items: center;
// box-shadow: 0 4rpx 12rpx rgba(20, 136, 219, 0.3);
position: relative;
z-index: 5;
.my-rank-number {
font-size: 48rpx;
font-weight: bold;
color: #000;
margin-right: 15rpx;
}
.my-rank-label {
font-size: 24rpx;
color: #1488DB;
opacity: 0.9;
margin-right: 20rpx;
}
.my-avatar {
width: 60rpx;
height: 60rpx;
border-radius: 50%;
// border: 3rpx solid #fff;
margin-right: 15rpx;
}
.my-name {
font-size: 28rpx;
color: #000;
font-weight: 500;
margin-right: 20rpx;
}
.my-score {
font-size: 28rpx;
color: #1488DB;
// font-weight: bold;
}
}
.ranking-list {
padding: 40rpx 30rpx;
background-color: #fff;
margin-top: -40rpx;
border-radius: 40rpx 40rpx 0 0;
.list-item {
display: flex;
align-items: center;
padding: 30rpx 0;
border-bottom: 1rpx solid #f0f0f0;
&:last-child {
border-bottom: none;
}
.rank-number {
width: 60rpx;
font-size: 32rpx;
font-weight: bold;
color: #333;
text-align: center;
}
.list-avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
margin: 0 30rpx;
}
.user-info {
flex: 1;
.user-name {
font-size: 28rpx;
color: #333;
font-weight: 500;
}
}
.user-score {
font-size: 28rpx;
color: $uni-color-primary;
// font-weight: bold;
}
}
}
</style>