rank.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  6. <title>排行榜</title>
  7. <style>
  8. body { margin: 0; padding: 0; font-family: -apple-system, sans-serif; background-color: #f7f8fa; }
  9. .header { background: linear-gradient(135deg, #FF9500, #FFCC00); color: white; padding: 20px; padding-top: 40px; text-align: center; }
  10. .my-rank-box { background: rgba(255,255,255,0.2); padding: 15px; border-radius: 10px; margin-top: 20px; display: flex; justify-content: space-between; align-items: center; }
  11. .list-container { padding: 15px; margin-top: -20px; }
  12. .rank-item { background: white; border-radius: 12px; padding: 15px; margin-bottom: 10px; display: flex; align-items: center; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
  13. .rank-num { width: 30px; font-size: 18px; font-weight: bold; color: #999; text-align: center; margin-right: 10px; }
  14. .rank-num.top3 { color: #FF9500; font-size: 22px; }
  15. .avatar { width: 40px; height: 40px; border-radius: 50%; background: #eee; margin-right: 15px; object-fit: cover; }
  16. .info { flex: 1; }
  17. .name { font-weight: bold; font-size: 16px; color: #333; }
  18. .score { font-weight: bold; color: #FF9500; font-size: 18px; }
  19. .unit { font-size: 12px; color: #999; margin-left: 4px; }
  20. .loading { text-align: center; padding: 20px; color: #999; }
  21. .back-btn { position: absolute; top: 20px; left: 20px; color: white; font-size: 24px; cursor: pointer; }
  22. </style>
  23. <script src="./mock_flutter.js"></script>
  24. <script src="./bridge.js"></script>
  25. <script src="./api.js"></script>
  26. </head>
  27. <body>
  28. <div class="header">
  29. <div class="back-btn" onclick="Bridge.back()">←</div>
  30. <h2>实时排行榜</h2>
  31. <div class="my-rank-box">
  32. <div>我的排名</div>
  33. <div style="font-size: 24px; font-weight: bold;" id="myRankNum">--</div>
  34. </div>
  35. </div>
  36. <div class="list-container" id="list">
  37. <div class="loading">正在加载排名数据...</div>
  38. </div>
  39. <script>
  40. var TOKEN = '96ba3c924394934f7d30fa869a94ce0d';
  41. // 模拟参数
  42. var MC_ID = '1001'; // 假设的赛事ID
  43. var MC_TYPE = 1;
  44. // 检测是否本地开发环境
  45. var isLocal = window.location.protocol === 'file:' ||
  46. window.location.hostname === 'localhost' ||
  47. window.location.hostname === '127.0.0.1';
  48. API.init({
  49. token: TOKEN,
  50. useMock: isLocal // 本地开发自动开启 Mock
  51. });
  52. // 1. 并行请求:我的排名 + 总榜单
  53. Promise.all([
  54. API.getUserCurrentRank(0), // ecId=0 示例
  55. API.getRankDetail(MC_ID, MC_TYPE, 'total') // 获取总榜
  56. ]).then(function(results) {
  57. var myRankData = results[0];
  58. var rankListData = results[1];
  59. // 渲染我的排名
  60. document.getElementById('myRankNum').innerText = myRankData.rankNum > 0 ? myRankData.rankNum : '未上榜';
  61. // 渲染列表
  62. // 注意:这里假设后端返回的 structure 是 { totalRankRs: [...] }
  63. // 根据之前的分析,API 返回的数据结构可能需要适配
  64. var list = rankListData.totalRankRs || [];
  65. renderList(list);
  66. }).catch(function(err) {
  67. console.error(err);
  68. document.getElementById('list').innerHTML = '<div class="loading">加载失败,请重试<br>' + err.message + '</div>';
  69. });
  70. function renderList(list) {
  71. if (!list || list.length === 0) {
  72. // 如果没有真实数据,为了演示效果,生成假数据
  73. list = generateMockData();
  74. }
  75. var html = '';
  76. list.forEach(function(item, index) {
  77. var rank = index + 1;
  78. var isTop3 = rank <= 3 ? 'top3' : '';
  79. var avatarUrl = item.headUrl || 'https://via.placeholder.com/40?text=' + item.nickName.charAt(0);
  80. html += `
  81. <div class="rank-item">
  82. <div class="rank-num ${isTop3}">${rank}</div>
  83. <img src="${avatarUrl}" class="avatar">
  84. <div class="info">
  85. <div class="name">${item.nickName}</div>
  86. </div>
  87. <div class="score">${item.score}<span class="unit">分</span></div>
  88. </div>`;
  89. });
  90. document.getElementById('list').innerHTML = html;
  91. }
  92. // 生成模拟数据 (仅当 API 无数据时使用)
  93. function generateMockData() {
  94. return [
  95. { nickName: '张三', score: 9800, headUrl: '' },
  96. { nickName: '李四', score: 9500, headUrl: '' },
  97. { nickName: '王五', score: 8900, headUrl: '' },
  98. { nickName: '赵六', score: 8200, headUrl: '' },
  99. { nickName: '运动小达人', score: 7800, headUrl: '' },
  100. ];
  101. }
  102. </script>
  103. </body>
  104. </html>