木邻有你前端代码仓库
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.

352 lines
7.5 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="ranking-page">
  3. <view class="back-button" @click="goBack">
  4. <uv-icon name="arrow-left" color="#ffffff" size="20"></uv-icon>
  5. </view>
  6. <!-- 排行榜背景 -->
  7. <view class="ranking-background">
  8. <image src="/subPages/static/rank_bg.png" class="bg-image" mode="aspectFill"></image>
  9. <!-- 返回按钮 -->
  10. <!-- 前三名定位布局 -->
  11. <view class="top-three">
  12. <!-- 第二名 -->
  13. <view class="rank-item rank-second">
  14. <image src="/subPages/static/second.png" class="rank-badge"></image>
  15. <image :src="topThree[1].headImage" class="avatar"></image>
  16. <view class="name">{{ topThree[1].nickName }}</view>
  17. <view class="score">{{ topThree[1].score }}积分</view>
  18. </view>
  19. <!-- 第一名 -->
  20. <view class="rank-item rank-first">
  21. <image src="/subPages/static/first.png" class="rank-badge"></image>
  22. <image :src="topThree[0].headImage" class="avatar"></image>
  23. <view class="name">{{ topThree[0].nickName }}</view>
  24. <view class="score">{{ topThree[0].score }}积分</view>
  25. </view>
  26. <!-- 第三名 -->
  27. <view class="rank-item rank-third">
  28. <image src="/subPages/static/third.png" class="rank-badge"></image>
  29. <image :src="topThree[2].headImage" class="avatar"></image>
  30. <view class="name">{{ topThree[2].nickName }}</view>
  31. <view class="score">{{ topThree[2].score }}积分</view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 我的排名 -->
  36. <view class="my-ranking" v-if="myRanking.rank">
  37. <view class="my-rank-number">{{ myRanking.rank }}</view>
  38. <view class="my-rank-label">我的排名</view>
  39. <image :src="myRanking.headImage" class="my-avatar"></image>
  40. <view class="my-name">{{ myRanking.nickName }}</view>
  41. <view class="my-score">{{ myRanking.score }}积分</view>
  42. </view>
  43. <!-- 排行榜列表 -->
  44. <view class="ranking-list">
  45. <view class="list-item" v-for="(item, index) in rankingList" :key="index">
  46. <view class="rank-number">{{ item.rank }}</view>
  47. <image :src="item.headImage" class="list-avatar"></image>
  48. <view class="user-info">
  49. <view class="user-name">{{ item.nickName }}</view>
  50. </view>
  51. <view class="user-score">{{ item.score }}积分</view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. name: 'Ranking',
  59. data() {
  60. return {
  61. myRanking: {
  62. },
  63. rankingList: [
  64. ],
  65. topThree: [
  66. ],
  67. pageNo: 1,
  68. pageSize: 10
  69. }
  70. },
  71. async onShow() {
  72. this.initData()
  73. // 获取排行榜数据
  74. await this.getRankingData();
  75. },
  76. methods: {
  77. initData() {
  78. this.pageNo = 1,
  79. this.rankingList = [],
  80. this.topThree = []
  81. },
  82. async onPullDownRefresh() {
  83. this.initData()
  84. await this.getRankingData()
  85. uni.stopPullDownRefresh()
  86. },
  87. async onReachBottom() {
  88. await this.getRankingData()
  89. },
  90. goBack() {
  91. uni.navigateBack();
  92. },
  93. async getRankingData() {
  94. let params = {}
  95. // 有登录的情况下 才会显示我的排名
  96. if (uni.getStorageSync('token')) {
  97. params = {
  98. token: uni.getStorageSync('token')
  99. }
  100. }
  101. const res = await this.$api.score.queryScoreRank({
  102. pageNo: this.pageNo,
  103. pageSize: this.pageSize,
  104. ...params
  105. })
  106. if (res.result.scoreList.records.length) {
  107. this.rankingList.push(...res.result.scoreList.records.slice(3))
  108. this.topThree.push(...res.result.scoreList.records.slice(0, 3))
  109. this.myRanking = res.result.myScore
  110. this.pageNo++
  111. }else {
  112. uni.showToast({
  113. title: '暂无数据',
  114. icon: 'none'
  115. })
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. // @import '@/uni.scss';
  123. .ranking-page {
  124. min-height: 100vh;
  125. background-color: #f5f5f5;
  126. }
  127. .back-button {
  128. position: fixed;
  129. top: 70rpx;
  130. left: 40rpx;
  131. width: 70rpx;
  132. height: 70rpx;
  133. // background-color: rgba(0, 0, 0, 0.3);
  134. // border-radius: 50%;
  135. display: flex;
  136. align-items: center;
  137. justify-content: center;
  138. z-index: 10;
  139. &:active {
  140. background-color: rgba(0, 0, 0, 0.5);
  141. }
  142. }
  143. .ranking-background {
  144. position: relative;
  145. width: 100%;
  146. height: 600rpx;
  147. .bg-image {
  148. width: 100%;
  149. height: 100%;
  150. }
  151. .back-button {
  152. position: absolute;
  153. top: 60rpx;
  154. left: 30rpx;
  155. width: 60rpx;
  156. height: 60rpx;
  157. // background-color: rgba(0, 0, 0, 0.3);
  158. // border-radius: 50%;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. z-index: 10;
  163. &:active {
  164. background-color: rgba(0, 0, 0, 0.5);
  165. }
  166. }
  167. .top-three {
  168. position: absolute;
  169. top: 0;
  170. left: 0;
  171. width: 100%;
  172. height: 100%;
  173. display: flex;
  174. align-items: flex-end;
  175. justify-content: center;
  176. padding-bottom: 80rpx;
  177. .rank-item {
  178. position: relative;
  179. display: flex;
  180. flex-direction: column;
  181. align-items: center;
  182. margin: 0 40rpx;
  183. .rank-badge {
  184. width: 60rpx;
  185. height: 60rpx;
  186. margin-bottom: 10rpx;
  187. }
  188. .avatar {
  189. width: 80rpx;
  190. height: 80rpx;
  191. border-radius: 50%;
  192. margin-bottom: 10rpx;
  193. border: 4rpx solid #fff;
  194. }
  195. .name {
  196. font-size: 24rpx;
  197. color: #fff;
  198. margin-bottom: 5rpx;
  199. font-weight: bold;
  200. }
  201. .score {
  202. font-size: 20rpx;
  203. color: #fff;
  204. opacity: 0.9;
  205. }
  206. }
  207. .rank-first {
  208. transform: translateY(-40rpx);
  209. .avatar {
  210. width: 100rpx;
  211. height: 100rpx;
  212. }
  213. .rank-badge {
  214. width: 80rpx;
  215. height: 80rpx;
  216. }
  217. }
  218. .rank-second {
  219. order: -1;
  220. }
  221. .rank-third {
  222. order: 1;
  223. }
  224. }
  225. }
  226. .my-ranking {
  227. background: #e1f2ff;
  228. border-radius: 12rpx;
  229. margin: 20rpx 30rpx 20rpx 30rpx;
  230. padding: 30rpx;
  231. display: flex;
  232. align-items: center;
  233. // box-shadow: 0 4rpx 12rpx rgba(20, 136, 219, 0.3);
  234. position: relative;
  235. z-index: 5;
  236. .my-rank-number {
  237. font-size: 48rpx;
  238. font-weight: bold;
  239. color: #000;
  240. margin-right: 15rpx;
  241. }
  242. .my-rank-label {
  243. font-size: 24rpx;
  244. color: #1488DB;
  245. opacity: 0.9;
  246. margin-right: 20rpx;
  247. }
  248. .my-avatar {
  249. width: 60rpx;
  250. height: 60rpx;
  251. border-radius: 50%;
  252. // border: 3rpx solid #fff;
  253. margin-right: 15rpx;
  254. }
  255. .my-name {
  256. font-size: 28rpx;
  257. color: #000;
  258. font-weight: 500;
  259. margin-right: 20rpx;
  260. }
  261. .my-score {
  262. font-size: 28rpx;
  263. color: #1488DB;
  264. // font-weight: bold;
  265. }
  266. }
  267. .ranking-list {
  268. padding: 40rpx 30rpx;
  269. background-color: #fff;
  270. margin-top: -40rpx;
  271. border-radius: 40rpx 40rpx 0 0;
  272. .list-item {
  273. display: flex;
  274. align-items: center;
  275. padding: 30rpx 0;
  276. border-bottom: 1rpx solid #f0f0f0;
  277. &:last-child {
  278. border-bottom: none;
  279. }
  280. .rank-number {
  281. width: 60rpx;
  282. font-size: 32rpx;
  283. font-weight: bold;
  284. color: #333;
  285. text-align: center;
  286. }
  287. .list-avatar {
  288. width: 80rpx;
  289. height: 80rpx;
  290. border-radius: 50%;
  291. margin: 0 30rpx;
  292. }
  293. .user-info {
  294. flex: 1;
  295. .user-name {
  296. font-size: 28rpx;
  297. color: #333;
  298. font-weight: 500;
  299. }
  300. }
  301. .user-score {
  302. font-size: 28rpx;
  303. color: $uni-color-primary;
  304. // font-weight: bold;
  305. }
  306. }
  307. }
  308. </style>