rank.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="sub-base-container">
  3. <view class="gradient-reflection" data-text="好友排行榜">好友排行榜</view>
  4. <view class="rank-card">
  5. <view class="tabs">
  6. <view :class="['tab-item',{active:active === item.speciesId}]" v-for="(item,index) in tabsList"
  7. :key="index" @click="handleTab(item)">{{item.name}}</view>
  8. </view>
  9. <scroll-view
  10. class="rank-list"
  11. v-if="rankList.length"
  12. scroll-y="true"
  13. @scrolltolower="loadMore"
  14. :style="{height: 'calc(100vh - 500rpx)'}"
  15. >
  16. <view :class="['rank-item',{bg:(index + 1) <=3}]" v-for="(item,index) in rankList" :key="index">
  17. <view class="rank-info">
  18. <text :class="['num',`num-${(index + 1)}`]">{{item.ranking}}</text>
  19. <up-image class="avatar" :fade="false" :src="item.icon" width="92rpx" height="92rpx"
  20. shape="circle"></up-image>
  21. <view class="info">
  22. <view class="name">
  23. <text>{{item.treeName || item.nickname.slice(0, 3) + "荔"}}</text>
  24. <view :class="['level',{levelBlue:item.level.id >3}]">
  25. V{{item.level.id}}.{{item.level.name}}</view>
  26. </view>
  27. <text class="nickname ellipsis-l1">昵称:{{item.nickname}}</text>
  28. </view>
  29. </view>
  30. <view class="button" @click="handlePage(item)">去看看</view>
  31. </view>
  32. <!-- 加载更多提示 -->
  33. <view class="loading-more" v-if="loading">
  34. <text>下拉加载数据</text>
  35. </view>
  36. <view class="no-more" v-if="!hasMore && rankList.length > 0">
  37. <text>没有更多数据了</text>
  38. </view>
  39. </scroll-view>
  40. <up-empty v-else mode="data" marginTop="50">
  41. </up-empty>
  42. </view>
  43. </view>
  44. </template>
  45. <script setup>
  46. import {
  47. ref
  48. } from "vue"
  49. import TREE from '@/api/tree.js'
  50. import {
  51. onLoad
  52. } from '@dcloudio/uni-app'
  53. onLoad(() => {
  54. getCategoryList()
  55. getRankingList()
  56. })
  57. const userInfo = uni.getStorageSync('userInfo')
  58. const handlePage = ({miniUserId,sampleId}) =>{
  59. if(miniUserId === userInfo.id){
  60. uni.navigateBack()
  61. }else{
  62. uni.navigateTo({
  63. url: `/pages/tabBar/tree/subPages/friendTree?sampleId=${sampleId}`
  64. });
  65. }
  66. }
  67. const active = ref(null)
  68. const tabsList = ref([])
  69. const handleTab = (item) => {
  70. active.value = item.speciesId
  71. // 切换tab时重置分页
  72. currentPage.value = 1
  73. rankList.value = []
  74. hasMore.value = true
  75. getRankingList()
  76. }
  77. const getCategoryList = () => {
  78. TREE.categoryList().then(res => {
  79. tabsList.value = res.data || []
  80. tabsList.value.unshift({
  81. name: '总榜',
  82. speciesId: null
  83. })
  84. })
  85. }
  86. const rankList = ref([])
  87. const currentPage = ref(1)
  88. const loading = ref(false)
  89. const hasMore = ref(true)
  90. const getRankingList = () => {
  91. if (loading.value || !hasMore.value) return
  92. loading.value = true
  93. const params = {
  94. speciesId: active.value,
  95. page: currentPage.value,
  96. limit: 10
  97. }
  98. TREE.rankingList(params).then(res => {
  99. const newData = res.data || []
  100. if (currentPage.value === 1) {
  101. rankList.value = newData
  102. } else {
  103. rankList.value = [...rankList.value, ...newData]
  104. }
  105. // 判断是否还有更多数据
  106. hasMore.value = newData.length === 10
  107. loading.value = false
  108. }).catch(() => {
  109. loading.value = false
  110. })
  111. }
  112. const loadMore = () => {
  113. if (hasMore.value && !loading.value) {
  114. currentPage.value++
  115. getRankingList()
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. @import "@/static/style/mixin.scss";
  121. .sub-base-container {
  122. @include ossBg("subTreePage/rank-bg.png");
  123. .gradient-reflection {
  124. width: 100%;
  125. position: relative;
  126. font-size: 86rpx;
  127. color: #fff;
  128. font-family: "PangMenZhengDao";
  129. text-align: center;
  130. }
  131. .gradient-reflection::after {
  132. content: attr(data-text);
  133. position: absolute;
  134. top: 75%;
  135. left: calc(50% - 430rpx / 2);
  136. transform: scaleY(-1);
  137. background: rgba(255, 255, 255, 0.5);
  138. -webkit-background-clip: text;
  139. background-clip: text;
  140. color: transparent;
  141. opacity: 0.5;
  142. }
  143. .rank-card {
  144. margin-top: 90rpx;
  145. background: rgba(255, 255, 255, 0.74);
  146. border-radius: 20rpx 20rpx 0 0;
  147. padding: 20rpx;
  148. .tabs {
  149. display: flex;
  150. .tab-item {
  151. flex: 1;
  152. text-align: center;
  153. color: rgba(0, 0, 0, 0.5);
  154. font-size: 28rpx;
  155. padding: 10rpx 0;
  156. &.active {
  157. border-radius: 50rpx;
  158. color: #000;
  159. background: #fff;
  160. }
  161. }
  162. }
  163. .rank-list {
  164. .rank-item {
  165. display: flex;
  166. align-items: center;
  167. justify-content: space-between;
  168. padding: 14rpx 20rpx;
  169. border-radius: 10rpx;
  170. margin-top: 20rpx;
  171. &.bg {
  172. background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.6), transparent);
  173. }
  174. .rank-info {
  175. display: flex;
  176. align-items: center;
  177. font-size: 24rpx;
  178. .num {
  179. margin-right: 28rpx;
  180. color: #724E02;
  181. font-family: 'SweiSpringCJKtc';
  182. &-1 {
  183. background: linear-gradient(to bottom, #724E02 0%, #F3C11D 100%);
  184. -webkit-background-clip: text;
  185. background-clip: text;
  186. color: transparent;
  187. font-size: 52rpx;
  188. font-family: 'SMILEYSANS';
  189. }
  190. &-2 {
  191. background: linear-gradient(to bottom, #898989 0%, #fff 100%);
  192. -webkit-background-clip: text;
  193. background-clip: text;
  194. color: transparent;
  195. font-size: 52rpx;
  196. font-family: 'SMILEYSANS';
  197. }
  198. &-3 {
  199. background: linear-gradient(to bottom, #F2BF16 0%, #FF8400 100%);
  200. -webkit-background-clip: text;
  201. background-clip: text;
  202. color: transparent;
  203. font-size: 52rpx;
  204. font-family: 'SMILEYSANS';
  205. }
  206. }
  207. .info {
  208. margin-left: 10rpx;
  209. .name {
  210. font-size: 28rpx;
  211. font-weight: 500;
  212. display: flex;
  213. align-items: center;
  214. margin-bottom: 4rpx;
  215. }
  216. .level {
  217. background: rgba(81, 81, 81, 0.1);
  218. color: #444444;
  219. border-radius: 4rpx;
  220. font-size: 24rpx;
  221. padding: 4rpx 10rpx;
  222. margin-left: 20rpx;
  223. &.levelBlue {
  224. background: #fff;
  225. color: #2199F8;
  226. }
  227. }
  228. .nickname {
  229. max-width: 320rpx;
  230. color: rgba(0, 0, 0, 0.5);
  231. }
  232. }
  233. }
  234. .button {
  235. font-size: 24rpx;
  236. padding: 10rpx 20rpx;
  237. border-radius: 50rpx;
  238. border: 2rpx solid rgba(0, 0, 0, 0.3);
  239. background: #fff;
  240. }
  241. }
  242. .loading-more, .no-more {
  243. text-align: center;
  244. padding: 20rpx 0;
  245. color: rgba(0, 0, 0, 0.5);
  246. font-size: 24rpx;
  247. }
  248. }
  249. }
  250. }
  251. </style>