leaderboard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  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" lazy-load></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" lazy-load></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" lazy-load></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" lazy-load></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. import fontScaleMixin from '@/mixins/font-scale.js'
  93. export default {
  94. mixins: [fontScaleMixin],
  95. data() {
  96. return {
  97. topList: [],
  98. myRank: null,
  99. loading: false
  100. }
  101. },
  102. computed: {
  103. restList() {
  104. if (this.topList.length <= 3) return []
  105. return this.topList.slice(3)
  106. }
  107. },
  108. onLoad() {
  109. this.loadTop()
  110. this.loadMyRank()
  111. },
  112. onPullDownRefresh() {
  113. this.loadTop()
  114. this.loadMyRank()
  115. uni.stopPullDownRefresh()
  116. },
  117. methods: {
  118. async loadTop() {
  119. this.loading = true
  120. try {
  121. var res = await getLeaderboardTop()
  122. if (res.data) {
  123. this.topList = res.data || []
  124. }
  125. } catch (e) {
  126. console.error('获取排行榜失败', e)
  127. uni.showToast({ title: '获取排行榜失败', icon: 'none' })
  128. }
  129. this.loading = false
  130. },
  131. async loadMyRank() {
  132. try {
  133. var res = await getLeaderboardMyRank()
  134. if (res.data) {
  135. this.myRank = res.data
  136. }
  137. } catch (e) {
  138. console.error('获取我的排名失败', e)
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .container {
  146. padding: $uni-space-page;
  147. min-height: 100vh;
  148. background: $uni-primary-pale;
  149. padding-bottom: 160rpx;
  150. }
  151. /* ===== 标题区域 ===== */
  152. .header {
  153. text-align: center;
  154. padding: 20rpx 0 $uni-space-lg;
  155. }
  156. .header-title {
  157. font-size: calc(36rpx * var(--font-scale, 1));
  158. font-weight: bold;
  159. color: $uni-text-color;
  160. display: block;
  161. }
  162. .header-sub {
  163. font-size: calc(24rpx * var(--font-scale, 1));
  164. color: $brand-primary;
  165. margin-top: 8rpx;
  166. display: block;
  167. }
  168. /* ===== 领奖台 Top 3 ===== */
  169. .podium-section {
  170. display: flex;
  171. align-items: flex-end;
  172. justify-content: center;
  173. padding: $uni-space-lg 0 40rpx;
  174. }
  175. .podium-item {
  176. display: flex;
  177. flex-direction: column;
  178. align-items: center;
  179. width: 200rpx;
  180. position: relative;
  181. }
  182. .podium-gold {
  183. width: 240rpx;
  184. }
  185. .crown-wrap {
  186. margin-bottom: 4rpx;
  187. }
  188. .crown-icon {
  189. font-size: calc(48rpx * var(--font-scale, 1));
  190. }
  191. .podium-rank-badge {
  192. width: 40rpx;
  193. height: 40rpx;
  194. border-radius: 50%;
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. font-size: calc(22rpx * var(--font-scale, 1));
  199. font-weight: bold;
  200. color: $app-surface;
  201. margin-bottom: 12rpx;
  202. }
  203. .gold-badge {
  204. background: $accent-gold;
  205. }
  206. .silver-badge {
  207. background: #C0C0C0;
  208. }
  209. .bronze-badge {
  210. background: #CD7F32;
  211. }
  212. .podium-avatar-wrap {
  213. width: 100rpx;
  214. height: 100rpx;
  215. border-radius: 50%;
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. overflow: hidden;
  220. margin-bottom: 12rpx;
  221. background: $status-warning-soft;
  222. }
  223. .gold-size {
  224. width: 120rpx;
  225. height: 120rpx;
  226. }
  227. .gold-border {
  228. border: 4rpx solid $accent-gold;
  229. box-shadow: 0 0 20rpx rgba(255, 215, 0, 0.4);
  230. }
  231. .silver-border {
  232. border: 4rpx solid #C0C0C0;
  233. box-shadow: 0 0 16rpx rgba(192, 192, 192, 0.3);
  234. }
  235. .bronze-border {
  236. border: 4rpx solid #CD7F32;
  237. box-shadow: 0 0 16rpx rgba(205, 127, 50, 0.3);
  238. }
  239. .podium-avatar {
  240. width: 100%;
  241. height: 100%;
  242. border-radius: 50%;
  243. }
  244. .podium-avatar-icon {
  245. font-size: calc(48rpx * var(--font-scale, 1));
  246. }
  247. .podium-name {
  248. font-size: calc(24rpx * var(--font-scale, 1));
  249. color: $uni-text-color;
  250. font-weight: 500;
  251. max-width: 180rpx;
  252. overflow: hidden;
  253. text-overflow: ellipsis;
  254. white-space: nowrap;
  255. text-align: center;
  256. display: block;
  257. }
  258. .gold-name {
  259. font-size: calc(28rpx * var(--font-scale, 1));
  260. font-weight: bold;
  261. max-width: 220rpx;
  262. }
  263. .podium-count {
  264. font-size: calc(22rpx * var(--font-scale, 1));
  265. color: $app-text-subtle;
  266. margin-top: 4rpx;
  267. display: block;
  268. }
  269. .gold-count {
  270. color: $brand-primary;
  271. font-weight: bold;
  272. font-size: calc(26rpx * var(--font-scale, 1));
  273. }
  274. /* ===== 排名列表 #4-#20 ===== */
  275. .rank-list {
  276. background: $app-surface;
  277. border-radius: 24rpx;
  278. padding: 24rpx $uni-space-page;
  279. box-shadow: 0 2rpx 12rpx rgba(249, 115, 22, 0.08);
  280. }
  281. .rank-item {
  282. display: flex;
  283. align-items: center;
  284. padding: 20rpx 0;
  285. border-bottom: 1rpx solid $brand-primary-light-2;
  286. }
  287. .rank-item:last-child {
  288. border-bottom: none;
  289. }
  290. .rank-num-wrap {
  291. width: 48rpx;
  292. height: 48rpx;
  293. border-radius: 50%;
  294. background: $uni-primary-pale;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. margin-right: 20rpx;
  299. flex-shrink: 0;
  300. }
  301. .rank-num {
  302. font-size: calc(24rpx * var(--font-scale, 1));
  303. font-weight: bold;
  304. color: $brand-primary;
  305. }
  306. .rank-avatar-wrap {
  307. width: 64rpx;
  308. height: 64rpx;
  309. border-radius: 50%;
  310. background: $status-warning-soft;
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. margin-right: 20rpx;
  315. overflow: hidden;
  316. flex-shrink: 0;
  317. }
  318. .rank-avatar {
  319. width: 64rpx;
  320. height: 64rpx;
  321. border-radius: 50%;
  322. }
  323. .rank-avatar-icon {
  324. font-size: calc(32rpx * var(--font-scale, 1));
  325. }
  326. .rank-name {
  327. flex: 1;
  328. font-size: calc(28rpx * var(--font-scale, 1));
  329. color: $uni-text-color;
  330. overflow: hidden;
  331. text-overflow: ellipsis;
  332. white-space: nowrap;
  333. min-width: 0;
  334. }
  335. .rank-count {
  336. font-size: calc(28rpx * var(--font-scale, 1));
  337. font-weight: bold;
  338. color: $brand-primary;
  339. flex-shrink: 0;
  340. margin-left: 16rpx;
  341. }
  342. /* ===== 我的排名(吸底) ===== */
  343. .my-rank-card {
  344. position: fixed;
  345. bottom: 0;
  346. left: 0;
  347. right: 0;
  348. padding: 20rpx $uni-space-page;
  349. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  350. background: rgba(255, 247, 237, 0.95);
  351. backdrop-filter: blur(10px);
  352. z-index: 100;
  353. }
  354. .my-rank-inner {
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. background: $app-surface;
  359. border-radius: 16rpx;
  360. padding: 24rpx 32rpx;
  361. box-shadow: 0 4rpx 20rpx rgba(249, 115, 22, 0.15);
  362. border: 2rpx solid $brand-primary-light-2;
  363. }
  364. .my-rank-left {
  365. display: flex;
  366. align-items: center;
  367. }
  368. .my-rank-label {
  369. font-size: calc(28rpx * var(--font-scale, 1));
  370. color: $uni-text-color-secondary;
  371. margin-right: 16rpx;
  372. }
  373. .my-rank-pos {
  374. font-size: calc(32rpx * var(--font-scale, 1));
  375. font-weight: bold;
  376. color: $brand-primary;
  377. }
  378. .my-rank-pos.unranked {
  379. color: $app-text-subtle;
  380. font-size: calc(28rpx * var(--font-scale, 1));
  381. font-weight: 500;
  382. }
  383. .my-rank-right {
  384. text-align: right;
  385. }
  386. .my-rank-count {
  387. font-size: calc(32rpx * var(--font-scale, 1));
  388. font-weight: bold;
  389. color: $brand-primary;
  390. }
  391. .my-rank-hint {
  392. font-size: calc(24rpx * var(--font-scale, 1));
  393. color: $app-text-subtle;
  394. }
  395. /* ===== 空状态 / 加载状态 ===== */
  396. .empty-state {
  397. text-align: center;
  398. padding: 120rpx 0;
  399. }
  400. .empty-icon {
  401. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  402. display: block;
  403. margin-bottom: 20rpx;
  404. }
  405. .empty-text {
  406. font-size: calc(28rpx * var(--font-scale, 1));
  407. color: $app-text-subtle;
  408. display: block;
  409. }
  410. .loading-state {
  411. text-align: center;
  412. padding: 120rpx 0;
  413. color: $app-text-subtle;
  414. font-size: calc(28rpx * var(--font-scale, 1));
  415. }
  416. </style>