leaderboard.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <view class="container">
  3. <!-- 标题区域 -->
  4. <view class="header">
  5. <text class="header-title">推广排行榜</text>
  6. <text class="header-sub">本周</text>
  7. </view>
  8. <!-- 加载状态 -->
  9. <view class="loading-state" v-if="loading && topList.length === 0">
  10. <text>加载中...</text>
  11. </view>
  12. <!-- 空状态 -->
  13. <view class="empty-state" v-if="!loading && topList.length === 0">
  14. <text class="empty-icon">🏆</text>
  15. <text class="empty-text">本周还没有推广达人</text>
  16. </view>
  17. <!-- Top 3 领奖台 -->
  18. <view class="podium-section" v-if="topList.length > 0">
  19. <!-- #2 左侧 -->
  20. <view class="podium-item podium-silver" v-if="topList.length >= 2">
  21. <view class="podium-rank-badge silver-badge">2</view>
  22. <view class="podium-avatar-wrap silver-border">
  23. <image v-if="topList[1] && topList[1].avatarUrl" class="podium-avatar" :src="topList[1].avatarUrl" mode="aspectFill"></image>
  24. <text v-else class="podium-avatar-icon">👤</text>
  25. </view>
  26. <text class="podium-name">{{ topList[1] && topList[1].nickname ? topList[1].nickname : '微信用户' }}</text>
  27. <text class="podium-count">{{ topList[1] && topList[1].referralCount ? topList[1].referralCount : 0 }}人</text>
  28. </view>
  29. <!-- #1 中间(最大) -->
  30. <view class="podium-item podium-gold">
  31. <view class="crown-wrap">
  32. <text class="crown-icon">👑</text>
  33. </view>
  34. <view class="podium-rank-badge gold-badge">1</view>
  35. <view class="podium-avatar-wrap gold-border gold-size">
  36. <image v-if="topList[0] && topList[0].avatarUrl" class="podium-avatar" :src="topList[0].avatarUrl" mode="aspectFill"></image>
  37. <text v-else class="podium-avatar-icon">👤</text>
  38. </view>
  39. <text class="podium-name gold-name">{{ topList[0] && topList[0].nickname ? topList[0].nickname : '微信用户' }}</text>
  40. <text class="podium-count gold-count">{{ topList[0] && topList[0].referralCount ? topList[0].referralCount : 0 }}人</text>
  41. </view>
  42. <!-- #3 右侧 -->
  43. <view class="podium-item podium-bronze" v-if="topList.length >= 3">
  44. <view class="podium-rank-badge bronze-badge">3</view>
  45. <view class="podium-avatar-wrap bronze-border">
  46. <image v-if="topList[2] && topList[2].avatarUrl" class="podium-avatar" :src="topList[2].avatarUrl" mode="aspectFill"></image>
  47. <text v-else class="podium-avatar-icon">👤</text>
  48. </view>
  49. <text class="podium-name">{{ topList[2] && topList[2].nickname ? topList[2].nickname : '微信用户' }}</text>
  50. <text class="podium-count">{{ topList[2] && topList[2].referralCount ? topList[2].referralCount : 0 }}人</text>
  51. </view>
  52. </view>
  53. <!-- 排名列表 #4-#20 -->
  54. <view class="rank-list" v-if="topList.length > 3">
  55. <view class="rank-item" v-for="item in restList" :key="item.rank">
  56. <view class="rank-num-wrap">
  57. <text class="rank-num">{{ item.rank }}</text>
  58. </view>
  59. <view class="rank-avatar-wrap">
  60. <image v-if="item.avatarUrl" class="rank-avatar" :src="item.avatarUrl" mode="aspectFill"></image>
  61. <text v-else class="rank-avatar-icon">👤</text>
  62. </view>
  63. <text class="rank-name">{{ item.nickname || '微信用户' }}</text>
  64. <text class="rank-count">{{ item.referralCount || 0 }}人</text>
  65. </view>
  66. </view>
  67. <!-- 我的排名(底部吸底) -->
  68. <view class="my-rank-card" v-if="!loading">
  69. <view class="my-rank-inner" v-if="myRank && myRank.rank">
  70. <view class="my-rank-left">
  71. <text class="my-rank-label">我的排名</text>
  72. <text class="my-rank-pos">#{{ myRank.rank }}</text>
  73. </view>
  74. <view class="my-rank-right">
  75. <text class="my-rank-count">{{ myRank.referralCount || 0 }}人</text>
  76. </view>
  77. </view>
  78. <view class="my-rank-inner" v-else>
  79. <view class="my-rank-left">
  80. <text class="my-rank-label">我的排名</text>
  81. <text class="my-rank-pos unranked">未上榜</text>
  82. </view>
  83. <view class="my-rank-right">
  84. <text class="my-rank-hint">继续加油推广吧</text>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import { getLeaderboardTop, getLeaderboardMyRank } from '../../utils/api.js'
  92. export default {
  93. data() {
  94. return {
  95. topList: [],
  96. myRank: null,
  97. loading: false
  98. }
  99. },
  100. computed: {
  101. restList() {
  102. if (this.topList.length <= 3) return []
  103. return this.topList.slice(3)
  104. }
  105. },
  106. onLoad() {
  107. this.loadTop()
  108. this.loadMyRank()
  109. },
  110. onPullDownRefresh() {
  111. this.loadTop()
  112. this.loadMyRank()
  113. uni.stopPullDownRefresh()
  114. },
  115. methods: {
  116. async loadTop() {
  117. this.loading = true
  118. try {
  119. var res = await getLeaderboardTop()
  120. if (res.data) {
  121. this.topList = res.data || []
  122. }
  123. } catch (e) {
  124. console.error('获取排行榜失败', e)
  125. uni.showToast({ title: '获取排行榜失败', icon: 'none' })
  126. }
  127. this.loading = false
  128. },
  129. async loadMyRank() {
  130. try {
  131. var res = await getLeaderboardMyRank()
  132. if (res.data) {
  133. this.myRank = res.data
  134. }
  135. } catch (e) {
  136. console.error('获取我的排名失败', e)
  137. }
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped>
  143. .container {
  144. padding: 30rpx;
  145. min-height: 100vh;
  146. background: #FFF7ED;
  147. padding-bottom: 160rpx;
  148. }
  149. /* ===== 标题区域 ===== */
  150. .header {
  151. text-align: center;
  152. padding: 20rpx 0 30rpx;
  153. }
  154. .header-title {
  155. font-size: 36rpx;
  156. font-weight: bold;
  157. color: #1E293B;
  158. display: block;
  159. }
  160. .header-sub {
  161. font-size: 24rpx;
  162. color: #F97316;
  163. margin-top: 8rpx;
  164. display: block;
  165. }
  166. /* ===== 领奖台 Top 3 ===== */
  167. .podium-section {
  168. display: flex;
  169. align-items: flex-end;
  170. justify-content: center;
  171. padding: 30rpx 0 40rpx;
  172. }
  173. .podium-item {
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. width: 200rpx;
  178. position: relative;
  179. }
  180. .podium-gold {
  181. width: 240rpx;
  182. }
  183. .crown-wrap {
  184. margin-bottom: 4rpx;
  185. }
  186. .crown-icon {
  187. font-size: 48rpx;
  188. }
  189. .podium-rank-badge {
  190. width: 40rpx;
  191. height: 40rpx;
  192. border-radius: 50%;
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. font-size: 22rpx;
  197. font-weight: bold;
  198. color: #fff;
  199. margin-bottom: 12rpx;
  200. }
  201. .gold-badge {
  202. background: #FFD700;
  203. }
  204. .silver-badge {
  205. background: #C0C0C0;
  206. }
  207. .bronze-badge {
  208. background: #CD7F32;
  209. }
  210. .podium-avatar-wrap {
  211. width: 100rpx;
  212. height: 100rpx;
  213. border-radius: 50%;
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. overflow: hidden;
  218. margin-bottom: 12rpx;
  219. background: #FEF3C7;
  220. }
  221. .gold-size {
  222. width: 120rpx;
  223. height: 120rpx;
  224. }
  225. .gold-border {
  226. border: 4rpx solid #FFD700;
  227. box-shadow: 0 0 20rpx rgba(255, 215, 0, 0.4);
  228. }
  229. .silver-border {
  230. border: 4rpx solid #C0C0C0;
  231. box-shadow: 0 0 16rpx rgba(192, 192, 192, 0.3);
  232. }
  233. .bronze-border {
  234. border: 4rpx solid #CD7F32;
  235. box-shadow: 0 0 16rpx rgba(205, 127, 50, 0.3);
  236. }
  237. .podium-avatar {
  238. width: 100%;
  239. height: 100%;
  240. border-radius: 50%;
  241. }
  242. .podium-avatar-icon {
  243. font-size: 48rpx;
  244. }
  245. .podium-name {
  246. font-size: 24rpx;
  247. color: #1E293B;
  248. font-weight: 500;
  249. max-width: 180rpx;
  250. overflow: hidden;
  251. text-overflow: ellipsis;
  252. white-space: nowrap;
  253. text-align: center;
  254. display: block;
  255. }
  256. .gold-name {
  257. font-size: 28rpx;
  258. font-weight: bold;
  259. max-width: 220rpx;
  260. }
  261. .podium-count {
  262. font-size: 22rpx;
  263. color: #94A3B8;
  264. margin-top: 4rpx;
  265. display: block;
  266. }
  267. .gold-count {
  268. color: #F97316;
  269. font-weight: bold;
  270. font-size: 26rpx;
  271. }
  272. /* ===== 排名列表 #4-#20 ===== */
  273. .rank-list {
  274. background: #fff;
  275. border-radius: 20rpx;
  276. padding: 24rpx 30rpx;
  277. box-shadow: 0 2rpx 12rpx rgba(249, 115, 22, 0.08);
  278. }
  279. .rank-item {
  280. display: flex;
  281. align-items: center;
  282. padding: 20rpx 0;
  283. border-bottom: 1rpx solid #FED7AA;
  284. }
  285. .rank-item:last-child {
  286. border-bottom: none;
  287. }
  288. .rank-num-wrap {
  289. width: 48rpx;
  290. height: 48rpx;
  291. border-radius: 50%;
  292. background: #FFF7ED;
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. margin-right: 20rpx;
  297. flex-shrink: 0;
  298. }
  299. .rank-num {
  300. font-size: 24rpx;
  301. font-weight: bold;
  302. color: #F97316;
  303. }
  304. .rank-avatar-wrap {
  305. width: 64rpx;
  306. height: 64rpx;
  307. border-radius: 50%;
  308. background: #FEF3C7;
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. margin-right: 20rpx;
  313. overflow: hidden;
  314. flex-shrink: 0;
  315. }
  316. .rank-avatar {
  317. width: 64rpx;
  318. height: 64rpx;
  319. border-radius: 50%;
  320. }
  321. .rank-avatar-icon {
  322. font-size: 32rpx;
  323. }
  324. .rank-name {
  325. flex: 1;
  326. font-size: 28rpx;
  327. color: #1E293B;
  328. overflow: hidden;
  329. text-overflow: ellipsis;
  330. white-space: nowrap;
  331. min-width: 0;
  332. }
  333. .rank-count {
  334. font-size: 28rpx;
  335. font-weight: bold;
  336. color: #F97316;
  337. flex-shrink: 0;
  338. margin-left: 16rpx;
  339. }
  340. /* ===== 我的排名(吸底) ===== */
  341. .my-rank-card {
  342. position: fixed;
  343. bottom: 0;
  344. left: 0;
  345. right: 0;
  346. padding: 20rpx 30rpx;
  347. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  348. background: rgba(255, 247, 237, 0.95);
  349. backdrop-filter: blur(10px);
  350. z-index: 100;
  351. }
  352. .my-rank-inner {
  353. display: flex;
  354. align-items: center;
  355. justify-content: space-between;
  356. background: #fff;
  357. border-radius: 16rpx;
  358. padding: 24rpx 32rpx;
  359. box-shadow: 0 4rpx 20rpx rgba(249, 115, 22, 0.15);
  360. border: 2rpx solid #FED7AA;
  361. }
  362. .my-rank-left {
  363. display: flex;
  364. align-items: center;
  365. }
  366. .my-rank-label {
  367. font-size: 28rpx;
  368. color: #64748B;
  369. margin-right: 16rpx;
  370. }
  371. .my-rank-pos {
  372. font-size: 32rpx;
  373. font-weight: bold;
  374. color: #F97316;
  375. }
  376. .my-rank-pos.unranked {
  377. color: #94A3B8;
  378. font-size: 28rpx;
  379. font-weight: 500;
  380. }
  381. .my-rank-right {
  382. text-align: right;
  383. }
  384. .my-rank-count {
  385. font-size: 32rpx;
  386. font-weight: bold;
  387. color: #F97316;
  388. }
  389. .my-rank-hint {
  390. font-size: 24rpx;
  391. color: #94A3B8;
  392. }
  393. /* ===== 空状态 / 加载状态 ===== */
  394. .empty-state {
  395. text-align: center;
  396. padding: 120rpx 0;
  397. }
  398. .empty-icon {
  399. font-size: 80rpx;
  400. display: block;
  401. margin-bottom: 20rpx;
  402. }
  403. .empty-text {
  404. font-size: 28rpx;
  405. color: #94A3B8;
  406. display: block;
  407. }
  408. .loading-state {
  409. text-align: center;
  410. padding: 120rpx 0;
  411. color: #94A3B8;
  412. font-size: 28rpx;
  413. }
  414. </style>