ranklist.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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">
  6. <script src="https://cdn.tailwindcss.com"></script>
  7. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
  8. <script>
  9. tailwind.config = {
  10. theme: {
  11. extend: {
  12. colors: {
  13. primary: '#3372ac',
  14. },
  15. animation: {
  16. marquee: 'marquee 25s linear infinite',
  17. },
  18. keyframes: {
  19. marquee: {
  20. '0%': { transform: 'translateX(100%)' },
  21. '100%': { transform: 'translateX(-100%)' },
  22. }
  23. }
  24. }
  25. }
  26. }
  27. </script>
  28. <style>
  29. @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;800&display=swap');
  30. body { font-family: 'Nunito', sans-serif; }
  31. .no-scrollbar::-webkit-scrollbar { display: none; }
  32. .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
  33. .snap-mandatory { scroll-behavior: smooth; }
  34. .fade-in-up { animation: fadeInUp 0.4s ease-out forwards; opacity: 0; transform: translateY(10px); }
  35. @keyframes fadeInUp { to { opacity: 1; transform: translateY(0); } }
  36. .dropdown-enter { opacity: 0; transform: translateY(-10px) scale(0.95); }
  37. .dropdown-enter-active { opacity: 1; transform: translateY(0) scale(1); transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
  38. </style>
  39. </head>
  40. <body class="bg-slate-50 relative pb-24" onclick="closeDropdownOnClickOutside(event)">
  41. <!-- 1. 顶部 Header -->
  42. <div class="relative w-full h-[260px]">
  43. <img src="https://orienteering.beswell.com/card/nanning/cardtop1122-2.jpg"
  44. class="w-full h-full object-cover shadow-md" alt="Header BG">
  45. <div class="absolute inset-0 bg-gradient-to-b from-primary/60 via-transparent to-black/30"></div>
  46. <div class="absolute top-0 w-full pt-10 px-5 flex justify-between items-center z-10 text-white">
  47. <button class="bg-black/20 backdrop-blur-sm p-2 rounded-full w-9 h-9 flex items-center justify-center active:scale-90 transition">
  48. <i class="fas fa-chevron-left"></i>
  49. </button>
  50. <h1 class="text-lg font-bold tracking-wider shadow-sm">实时赛况</h1>
  51. <button onclick="openInfoModal()" class="bg-black/20 backdrop-blur-sm px-3 py-1.5 rounded-full text-xs font-semibold flex items-center gap-1 active:scale-90 transition">
  52. <i class="fas fa-question-circle"></i> 说明
  53. </button>
  54. </div>
  55. <!-- 底部公告跑马灯 -->
  56. <div class="absolute bottom-[35px] w-full z-10 px-4">
  57. <div class="bg-black/40 backdrop-blur-md rounded-full py-1.5 px-3 flex items-center gap-2 overflow-hidden border border-white/10 shadow-lg">
  58. <i class="fas fa-bullhorn text-yellow-300 text-xs shrink-0"></i>
  59. <div class="flex-1 overflow-hidden relative h-4">
  60. <div id="marqueeTextContainer" class="absolute whitespace-nowrap text-[10px] text-white animate-marquee leading-4">
  61. 总里程: 5024km | 总打点数: 8900个 | 答题正确率: 1500道 | 距离比赛结束还有 1天 5小时 | 加油!冲鸭!
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <!-- 2. 个人信息卡 -->
  68. <div class="px-4 -mt-8 relative z-20">
  69. <div class="bg-white rounded-xl shadow-lg p-4 flex justify-between items-center border border-white/50">
  70. <div class="flex items-center gap-3">
  71. <div class="relative">
  72. <img src="https://i.pravatar.cc/100?img=12" class="w-12 h-12 rounded-full border-2 border-slate-100">
  73. <div class="absolute -bottom-1 -right-1 bg-primary text-white text-[8px] px-1.5 py-0.5 rounded-full border border-white">Lv.3</div>
  74. </div>
  75. <div>
  76. <!-- 昵称 & 编辑按钮 -->
  77. <h2 class="font-bold text-gray-800 text-sm flex items-center gap-1">
  78. <span id="profileName">奔跑的蜗牛</span>
  79. <button onclick="openEditModal()" class="text-xs text-primary/60 p-1 hover:text-primary transition-colors"><i class="fas fa-pen"></i></button>
  80. </h2>
  81. <!-- 战队 -->
  82. <p class="text-xs text-gray-500 mt-0.5 flex items-center gap-1">
  83. <i class="fas fa-user-friends text-blue-300 text-[10px]"></i>
  84. <span id="profileTeam">飞虎队</span>
  85. </p>
  86. </div>
  87. </div>
  88. <div class="text-center pl-4 border-l border-gray-100">
  89. <div id="currentScoreDisplay" class="text-2xl font-black text-primary font-mono leading-none">120</div>
  90. <div class="text-[10px] text-gray-400 mt-1">当前积分</div>
  91. </div>
  92. </div>
  93. </div>
  94. <!-- 3. 排行榜 Tabs -->
  95. <div class="mt-6 px-4">
  96. <!-- 主榜单切换:轻量化分段控制器风格 -->
  97. <div class="bg-slate-100 p-1 rounded-full flex gap-1 mb-4 relative shadow-inner">
  98. <button onclick="switchMainTab('team')" id="tab-team"
  99. class="flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 bg-white text-primary shadow-sm">
  100. 团队榜
  101. </button>
  102. <button onclick="switchMainTab('individual')" id="tab-ind"
  103. class="flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 text-gray-500 hover:text-gray-700">
  104. 个人榜
  105. </button>
  106. </div>
  107. <!-- 维度切换 -->
  108. <div class="flex gap-2 justify-center pt-4 overflow-x-auto no-scrollbar pb-2" id="metric-tabs">
  109. <button onclick="switchMetric('score')" id="metric-score" class="metric-btn bg-primary text-white px-3 py-1 rounded-full text-xs shadow-md shadow-blue-100 font-bold shrink-0 relative overflow-visible">
  110. 积分
  111. <span id="prize-badge" class="absolute -top-2 -right-2 bg-red-500 text-white text-[9px] px-1.5 py-0.5 rounded-full shadow-sm border border-white z-10 leading-none">奖</span>
  112. </button>
  113. <button onclick="switchMetric('mileage')" id="metric-mileage" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">里程</button>
  114. <button onclick="switchMetric('accuracy')" id="metric-accuracy" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">答题正确率</button>
  115. <button onclick="switchMetric('count')" id="metric-count" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">打点数</button>
  116. <button onclick="switchMetric('lap')" id="metric-lap" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">单圈用时</button>
  117. </div>
  118. </div>
  119. <!-- 4. 排行榜列表容器 -->
  120. <!-- 修改点:space-y-2 (间距变小), 内层渲染 logic 变 p-2 -->
  121. <div id="leaderboard-container" class="px-4 mt-1 space-y-2 mb-24 min-h-[300px]"></div>
  122. <!-- 5. 底部悬浮栏 -->
  123. <div class="fixed bottom-0 w-full bg-white border-t border-gray-100 shadow-[0_-5px_20px_rgba(0,0,0,0.05)] px-4 py-3 flex items-center z-40 safe-area-bottom">
  124. <button onclick="openDrawer()" class="w-full bg-gradient-to-r from-orange-500 to-red-600 text-white py-3 rounded-full font-bold shadow-lg shadow-orange-100 transform active:scale-[0.98] transition flex items-center justify-center gap-2 text-base">
  125. <i class="fas fa-flag-checkered animate-pulse"></i> 进入比赛
  126. </button>
  127. </div>
  128. <!-- ================= 模态框区域 ================= -->
  129. <!-- A. 编辑个人资料模态框 -->
  130. <div id="editProfileModal" class="fixed inset-0 z-[60] hidden flex items-center justify-center">
  131. <div class="absolute inset-0 bg-slate-900/60 backdrop-blur-sm" onclick="closeEditModal()"></div>
  132. <div class="bg-white w-[85%] rounded-2xl p-6 relative z-10 shadow-2xl animate-[fadeInUp_0.3s_ease-out]">
  133. <h3 class="font-bold text-lg mb-6 text-gray-800 text-center">修改报名信息</h3>
  134. <div class="space-y-5">
  135. <div>
  136. <label class="block text-sm font-bold text-gray-500 mb-2">我的昵称</label>
  137. <input type="text" id="editNameInput" value="奔跑的蜗牛"
  138. class="w-full bg-slate-50 border border-gray-200 rounded-lg px-4 py-2.5 text-sm font-bold text-gray-800 focus:outline-none focus:ring-1 focus:ring-primary focus:bg-white transition-colors">
  139. </div>
  140. <div>
  141. <label class="block text-sm font-bold text-gray-500 mb-2">所属战队</label>
  142. <div class="relative group">
  143. <button type="button" id="dropdownBtn" onclick="toggleDropdown(event)"
  144. class="w-full bg-slate-50 border border-gray-200 rounded-lg px-4 py-2.5 text-sm font-bold text-left flex items-center justify-between focus:outline-none focus:ring-1 focus:ring-primary transition-all">
  145. <span id="selectedTeamText" class="text-gray-800 flex items-center gap-2">
  146. <i class="fas fa-user-friends text-primary"></i> 飞虎队
  147. </span>
  148. <i class="fas fa-chevron-circle-down text-gray-400 transition-transform duration-300" id="dropdownArrow"></i>
  149. </button>
  150. <div id="dropdownMenu" class="hidden absolute top-[110%] left-0 w-full bg-white rounded-xl shadow-2xl border border-gray-100 overflow-hidden z-50 dropdown-enter max-h-48 overflow-y-auto">
  151. <ul class="text-sm text-gray-700">
  152. <li onclick="selectOption('飞虎队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between border-b border-gray-50"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 飞虎队</span></li>
  153. <li onclick="selectOption('火箭队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between border-b border-gray-50"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 火箭队</span></li>
  154. <li onclick="selectOption('摸鱼队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between border-b border-gray-50"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 摸鱼队</span></li>
  155. <li onclick="selectOption('汪汪队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 汪汪队</span></li>
  156. </ul>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="flex gap-3 mt-8">
  162. <button onclick="closeEditModal()" class="flex-1 py-2.5 rounded-full border border-gray-200 text-gray-500 font-bold text-sm">取消</button>
  163. <button onclick="saveProfile()" class="flex-1 py-2.5 rounded-full bg-primary text-white font-bold text-sm shadow-lg shadow-blue-200">保存修改</button>
  164. </div>
  165. </div>
  166. </div>
  167. <!-- B. 说明模态框 -->
  168. <div id="infoModal" class="fixed inset-0 z-50 hidden transition-opacity duration-300">
  169. <div class="absolute inset-0 bg-slate-900/70 backdrop-blur-sm" onclick="closeInfoModal()"></div>
  170. <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[90%] bg-white rounded-3xl p-6 shadow-2xl">
  171. <button onclick="closeInfoModal()" class="absolute -top-12 right-0 text-white/80 hover:text-white w-10 h-10 border border-white/30 rounded-full flex items-center justify-center">
  172. <i class="fas fa-times text-lg"></i>
  173. </button>
  174. <h3 class="text-center font-bold text-xl mb-4 text-primary border-b border-gray-100 pb-3">
  175. <i class="fas fa-book-open mr-2"></i>比赛规则说明
  176. </h3>
  177. <div id="modalSlider" class="overflow-x-auto flex snap-x snap-mandatory no-scrollbar space-x-4 pb-2" onscroll="updateDots()">
  178. <div class="snap-center shrink-0 w-full bg-blue-50 rounded-2xl p-5 text-center border border-blue-100">
  179. <div class="w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3"><i class="fas fa-map-marker-alt text-xl text-primary"></i></div>
  180. <h4 class="font-bold text-base text-gray-800 mb-1">1. 定向寻宝</h4>
  181. <p class="text-gray-600 text-xs leading-relaxed">比赛设置12个隐藏打卡点。</p>
  182. </div>
  183. <div class="snap-center shrink-0 w-full bg-blue-50 rounded-2xl p-5 text-center border border-blue-100">
  184. <div class="w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3"><i class="fas fa-mobile-alt text-xl text-primary"></i></div>
  185. <h4 class="font-bold text-base text-gray-800 mb-1">2. 扫码打卡</h4>
  186. <p class="text-gray-600 text-xs leading-relaxed">到达点位后,使用APP扫描二维码。</p>
  187. </div>
  188. <div class="snap-center shrink-0 w-full bg-blue-50 rounded-2xl p-5 text-center border border-blue-100">
  189. <div class="w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3"><i class="fas fa-medal text-xl text-primary"></i></div>
  190. <h4 class="font-bold text-base text-gray-800 mb-1">3. 完赛奖励</h4>
  191. <p class="text-gray-600 text-xs leading-relaxed">前50名有精美礼品!加油!</p>
  192. </div>
  193. </div>
  194. <div class="flex justify-center gap-2 mt-4" id="dotsContainer">
  195. <div class="dot w-6 h-1.5 rounded-full bg-primary transition-all duration-300"></div>
  196. <div class="dot w-1.5 h-1.5 rounded-full bg-gray-300 transition-all duration-300"></div>
  197. <div class="dot w-1.5 h-1.5 rounded-full bg-gray-300 transition-all duration-300"></div>
  198. </div>
  199. </div>
  200. </div>
  201. <!-- C. 上滑抽屉 -->
  202. <div id="drawer-backdrop" class="fixed inset-0 bg-black/50 z-50 hidden transition-opacity" onclick="closeDrawer()"></div>
  203. <div id="drawer" class="fixed bottom-0 left-0 w-full bg-white rounded-t-3xl p-6 z-50 transform translate-y-full transition-transform duration-300 ease-out safe-area-bottom">
  204. <div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-6"></div>
  205. <h3 class="font-bold text-lg mb-5 text-gray-800">前往比赛场地</h3>
  206. <div class="space-y-6">
  207. <div>
  208. <button onclick="triggerJump('兴隆山校区')" class="w-full border-2 border-primary bg-blue-50 text-primary py-4 rounded-xl font-bold text-sm flex items-center justify-between px-6 shadow-sm active:scale-[0.98] transition-transform">
  209. <div class="flex items-center gap-3">
  210. <i class="fas fa-map-marked-alt text-2xl"></i>
  211. <div class="text-left">
  212. <div class="text-base font-bold">兴隆山校区</div>
  213. <div class="text-[10px] opacity-70 font-normal">当前比赛区域</div>
  214. </div>
  215. </div>
  216. <i class="fas fa-chevron-right text-lg"></i>
  217. </button>
  218. </div>
  219. <div>
  220. <label class="text-xs text-gray-400 font-bold uppercase mb-2 block pl-1">选择导航</label>
  221. <div class="bg-gray-50 rounded-2xl p-2 flex flex-col gap-2 border border-gray-100">
  222. <button onclick="triggerJump('高德地图')" class="flex items-center gap-4 w-full bg-white p-3 rounded-xl border border-gray-100 shadow-sm active:bg-gray-50 active:scale-[0.99] transition-transform">
  223. <img src="./gd.png" class="w-8 h-8 object-contain">
  224. <div class="text-left">
  225. <div class="font-bold text-gray-800 text-sm">高德地图</div>
  226. <div class="text-[10px] text-gray-400">推荐路线</div>
  227. </div>
  228. <i class="fas fa-location-arrow ml-auto text-primary"></i>
  229. </button>
  230. <button onclick="triggerJump('百度地图')" class="flex items-center gap-4 w-full bg-white p-3 rounded-xl border border-gray-100 shadow-sm active:bg-gray-50 active:scale-[0.99] transition-transform">
  231. <img src="./bd.png" class="w-8 h-8 object-contain">
  232. <div class="text-left">
  233. <div class="font-bold text-gray-800 text-sm">百度地图</div>
  234. <div class="text-[10px] text-gray-400">备选方案</div>
  235. </div>
  236. <i class="fas fa-location-arrow ml-auto text-primary"></i>
  237. </button>
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. <script src="./bridge.js"></script>
  243. <script src="./api.js"></script>
  244. <script>
  245. // --- 核心状态 ---
  246. let currentTab = 'team';
  247. let currentMetric = 'score';
  248. // --- 全局数据存储 ---
  249. let API_DATA = {}; // 存储 API 返回的完整对象
  250. let CURRENT_RANK_LIST = []; // 当前显示的列表
  251. // --- 字段映射配置 (参考 rankList.vue) ---
  252. // 对应 dispArrStr: "teamCp,teamDistance,teamRightAnswerPer,teamTodayPace,regionCp,regionDistance,regionRightAnswerPer,regionTodayPace"
  253. const DATA_MAPPING = {
  254. team: {
  255. score: { key: 'teamCpRs', unit: '分', label: '积分' }, // 对应 rankList.vue tab1Current=0, index=0 (rankType=totalScore) -> teamCpRs
  256. mileage: { key: 'teamDistanceRs', unit: 'km', label: '里程' }, // index=2 (rankType=totalDistance) -> teamDistanceRs
  257. accuracy: { key: 'teamRightAnswerPerRs', unit: '%', label: '正确率' }, // index=3 -> teamRightAnswerPerRs
  258. count: { key: 'teamCpRs', unit: '个', label: '打点' }, // 暂复用 teamCpRs 或 teamTodayCpRs? 这里沿用 score 的源,但在 Vue 里是分开的 Tab
  259. lap: { key: 'teamTodayPaceRs', unit: '/km', label: '配速' } // index=4 -> teamTodayPaceRs
  260. },
  261. individual: {
  262. score: { key: 'regionCpRs', unit: '分', label: '积分' }, // tab1Current=1, index=0 -> regionCpRs
  263. mileage: { key: 'regionDistanceRs', unit: 'km', label: '里程' },
  264. accuracy: { key: 'regionRightAnswerPerRs', unit: '%', label: '正确率' },
  265. count: { key: 'regionCpRs', unit: '个', label: '打点' },
  266. lap: { key: 'regionTodayPaceRs', unit: '/km', label: '配速' }
  267. }
  268. };
  269. // --- 格式化工具 ---
  270. const Formatters = {
  271. distance: (val) => {
  272. if (!val) return '0';
  273. if (val < 10000) return (Math.round(val * 100 / 1000) / 100).toFixed(2);
  274. return Math.round(val / 1000).toString();
  275. },
  276. pace: (val) => {
  277. if (!val) return "--'--\"";
  278. const m = Math.floor(val / 60);
  279. const s = Math.floor(val % 60);
  280. return `${m}'${s < 10 ? '0' + s : s}"`;
  281. },
  282. default: (val) => val || '0'
  283. };
  284. // --- 渲染逻辑 ---
  285. function renderLeaderboard() {
  286. const container = document.getElementById('leaderboard-container');
  287. container.innerHTML = ''; // Clear existing
  288. // 1. 获取当前配置
  289. const config = DATA_MAPPING[currentTab][currentMetric];
  290. if (!config) return;
  291. // 2. 获取数据列表
  292. const rawList = API_DATA[config.key] || [];
  293. // 3. 转换数据结构
  294. // Vue 组件 item: { rankNum, isSelf, userName, inRankNum, headUrl, ... }
  295. const fullList = rawList.map(item => {
  296. let valDisplay = item.inRankNum;
  297. // 根据 Metric 类型进行格式化
  298. if (currentMetric === 'mileage') valDisplay = Formatters.distance(item.inRankNum);
  299. else if (currentMetric === 'lap') valDisplay = Formatters.pace(item.inRankNum);
  300. return {
  301. name: item.userName || item.teamName || '匿名', // 兼容不同字段
  302. sub: item.additionalName || '', // 副标题
  303. val: valDisplay,
  304. unit: config.unit,
  305. avatar: item.headUrl, // 个人头像
  306. rank: item.rankNum,
  307. isMe: item.isSelf === 1 || item.isSelf === true, // 兼容
  308. raw: item
  309. };
  310. });
  311. if (fullList.length === 0) {
  312. container.innerHTML = '<div class="text-center text-gray-400 py-10 text-sm">暂无排名数据</div>';
  313. return;
  314. }
  315. const renderItem = (item, visualIndex, isRealRank = false) => {
  316. const rank = (isRealRank && item.rank) ? item.rank : (item.rank || visualIndex + 1);
  317. const isTop3 = rank <= 3; // 使用真实排名判断样式
  318. // 图标
  319. let rankIconHtml = '';
  320. if (isTop3) {
  321. const colors = ['text-yellow-400', 'text-gray-400', 'text-orange-600'];
  322. const colorClass = colors[rank - 1] || 'text-gray-400'; // 安全回退
  323. const iconClass = currentTab === 'team' ? 'fa-trophy' : 'fa-medal';
  324. rankIconHtml = `<div class="w-8 flex justify-center shrink-0 mr-1"><i class="fas ${iconClass} ${colorClass} text-lg drop-shadow-sm"></i></div>`;
  325. } else {
  326. rankIconHtml = `<div class="w-8 text-center font-bold text-gray-400 text-sm mr-1">${rank}</div>`;
  327. }
  328. // “我”的特殊排位样式
  329. if (item.isMe) {
  330. rankIconHtml = `<div class="w-8 text-center font-black text-primary text-lg italic mr-1">${rank}</div>`;
  331. }
  332. // 头像
  333. let avatarHtml = '';
  334. if (currentTab === 'team') {
  335. avatarHtml = `<div class="w-9 h-9 bg-blue-50 rounded-full mr-3 flex items-center justify-center shrink-0 text-primary"><i class="fas fa-user-friends text-base"></i></div>`;
  336. } else {
  337. const avatarSrc = item.avatar || 'https://i.pravatar.cc/100?img=1'; // 默认头像
  338. avatarHtml = `<img src="${avatarSrc}" class="w-9 h-9 rounded-full mr-3 border-2 ${isTop3 ? 'border-yellow-400' : 'border-transparent'} shrink-0 object-cover">`;
  339. }
  340. // 容器样式
  341. let containerClass = "bg-white rounded-xl py-2 px-3 flex items-center shadow-sm border border-gray-100 relative fade-in-up";
  342. let nameClass = "font-bold text-gray-800 text-sm";
  343. let valClass = "font-bold text-gray-600 font-mono text-base";
  344. if (item.isMe) {
  345. containerClass = "bg-blue-50 rounded-xl py-2 px-3 flex items-center shadow-md border-2 border-primary/30 relative overflow-hidden transform scale-[1.02] fade-in-up z-10 my-2";
  346. nameClass = "font-bold text-primary text-sm";
  347. valClass = "font-bold text-primary font-mono text-lg";
  348. } else if (isTop3) {
  349. containerClass = "bg-white rounded-xl py-2 px-3 flex items-center shadow-sm border border-yellow-100 relative overflow-hidden fade-in-up";
  350. }
  351. const meBadge = item.isMe ? `<div class="absolute right-0 top-0 bg-primary text-white text-[8px] px-1.5 py-0.5 rounded-bl-lg">我</div>` : '';
  352. return
  353. `<div class="${containerClass}" style="animation-delay: ${visualIndex * 50}ms">
  354. ${meBadge}
  355. ${rankIconHtml}
  356. ${avatarHtml}
  357. <div class="flex-1 min-w-0">
  358. <h4 class="${nameClass} truncate">${item.name}</h4>
  359. <p class="text-[10px] text-gray-400 truncate">${item.sub}</p>
  360. </div>
  361. <div class="text-right">
  362. <div class="${valClass}">${item.val}</div>
  363. <div class="text-[10px] text-gray-400">${item.unit}</div>
  364. </div>
  365. </div>`;
  366. };
  367. let html = '';
  368. // 逻辑:前3名 + (如果我在后面则插队) + 剩余
  369. // 这里简化处理,直接渲染列表,如果 "我" 在列表中会自动高亮。
  370. // 如果 API 返回的数据没有包含 "我" (比如分页了),则需要单独处理 getUserCurrentRank 接口,这里暂且假设 rankRs 包含了 top N。
  371. fullList.forEach((item, index) => {
  372. html += renderItem(item, index);
  373. });
  374. container.innerHTML = html;
  375. }
  376. // --- 编辑模态框逻辑 ---
  377. const editModal = document.getElementById('editProfileModal');
  378. const editNameInput = document.getElementById('editNameInput');
  379. const selectedTeamText = document.getElementById('selectedTeamText');
  380. function openEditModal() {
  381. const currentName = document.getElementById('profileName').innerText;
  382. const currentTeam = document.getElementById('profileTeam').innerText;
  383. editNameInput.value = currentName;
  384. selectedTeamText.innerHTML = `<i class="fas fa-user-friends text-primary"></i> ${currentTeam}`;
  385. editModal.classList.remove('hidden');
  386. }
  387. function closeEditModal() {
  388. editModal.classList.add('hidden');
  389. closeDropdown();
  390. }
  391. function saveProfile() {
  392. const newName = editNameInput.value;
  393. // 这里的 teamName 逻辑仅仅是 UI 演示,实际修改需要调用 API (e.g., signUpOnline)
  394. // 目前仅更新 UI
  395. document.getElementById('profileName').innerText = newName;
  396. // TODO: Call API to update profile if needed
  397. closeEditModal();
  398. }
  399. // --- 下拉菜单 ---
  400. const dropdownMenu = document.getElementById('dropdownMenu');
  401. const dropdownArrow = document.getElementById('dropdownArrow');
  402. function toggleDropdown(event) {
  403. event.stopPropagation();
  404. if (dropdownMenu.classList.contains('hidden')) {
  405. dropdownMenu.classList.remove('hidden');
  406. setTimeout(() => dropdownMenu.classList.add('dropdown-enter-active'), 10);
  407. dropdownArrow.style.transform = 'rotate(180deg)';
  408. } else { closeDropdown(); }
  409. }
  410. function closeDropdown() {
  411. dropdownMenu.classList.remove('dropdown-enter-active');
  412. dropdownArrow.style.transform = 'rotate(0deg)';
  413. setTimeout(() => dropdownMenu.classList.add('hidden'), 200);
  414. }
  415. function selectOption(teamName) {
  416. selectedTeamText.innerHTML = `<i class="fas fa-user-friends text-primary"></i> ${teamName}`;
  417. closeDropdown();
  418. }
  419. function closeDropdownOnClickOutside(event) {
  420. if (!editModal.classList.contains('hidden')) {
  421. const btn = document.getElementById('dropdownBtn');
  422. if (!dropdownMenu.contains(event.target) && !btn.contains(event.target)) {
  423. closeDropdown();
  424. }
  425. }
  426. }
  427. // --- 切换 Tab ---
  428. function switchMainTab(type) {
  429. currentTab = type;
  430. const tTeam = document.getElementById('tab-team');
  431. const tInd = document.getElementById('tab-ind');
  432. const activeClass = "flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 bg-white text-primary shadow-sm";
  433. const inactiveClass = "flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 text-gray-500 hover:text-gray-700";
  434. if(type === 'team') {
  435. tTeam.className = activeClass;
  436. tInd.className = inactiveClass;
  437. } else {
  438. tInd.className = activeClass;
  439. tTeam.className = inactiveClass;
  440. }
  441. renderLeaderboard();
  442. }
  443. function switchMetric(metric) {
  444. currentMetric = metric;
  445. document.querySelectorAll('.metric-btn').forEach(btn => {
  446. if (btn.id === `metric-${metric}`) {
  447. btn.className = 'metric-btn bg-primary text-white px-3 py-1 rounded-full text-xs shadow-md shadow-blue-100 font-bold shrink-0 relative overflow-visible transition-colors';
  448. } else {
  449. btn.className = 'metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors';
  450. }
  451. });
  452. renderLeaderboard();
  453. }
  454. function openInfoModal() { document.getElementById('infoModal').classList.remove('hidden'); }
  455. function closeInfoModal() { document.getElementById('infoModal').classList.add('hidden'); }
  456. function openDrawer() { document.getElementById('drawer-backdrop').classList.remove('hidden'); document.getElementById('drawer').classList.remove('translate-y-full'); }
  457. function closeDrawer() { document.getElementById('drawer-backdrop').classList.add('hidden'); document.getElementById('drawer').classList.add('translate-y-full'); }
  458. function triggerJump(target) { alert("正在跳转至:" + target); closeDrawer(); }
  459. const slider = document.getElementById('modalSlider');
  460. const dots = document.querySelectorAll('.dot');
  461. function updateDots() {
  462. const index = Math.round(slider.scrollLeft / slider.offsetWidth);
  463. dots.forEach((dot, i) => {
  464. dot.className = (i === index) ? 'dot w-6 h-1.5 rounded-full bg-primary transition-all duration-300' : 'dot w-1.5 h-1.5 rounded-full bg-gray-300 transition-all duration-300';
  465. });
  466. }
  467. window.onload = function() {
  468. // Helper function to get URL query parameters (local to this script)
  469. function getQueryParam(name) {
  470. const params = new URLSearchParams(window.location.search);
  471. return params.get(name);
  472. }
  473. // Helper function to format remaining time (seconds timestamp)
  474. function formatRemainingTime(endSecond) {
  475. if (endSecond === undefined) return 'N/A';
  476. const now = Date.now() / 1000; // Current Unix timestamp in seconds
  477. const diffSeconds = endSecond - now;
  478. if (diffSeconds <= 0) {
  479. return '已结束';
  480. }
  481. const days = Math.floor(diffSeconds / (3600 * 24));
  482. const hours = Math.floor((diffSeconds % (3600 * 24)) / 3600);
  483. let timeStr = '';
  484. if (days > 0) {
  485. timeStr += `${days}天 `;
  486. }
  487. timeStr += `${hours}小时`;
  488. return timeStr.trim();
  489. }
  490. // Get external parameters
  491. const token = getQueryParam('token');
  492. let ecId = getQueryParam('id'); // Use 'id' from URL as ecId
  493. const env = getQueryParam('env');
  494. // Initialize Mock if needed
  495. if (env === 'mock' && window.API) {
  496. console.log('Initializing API in Mock mode...');
  497. window.API.init({ useMock: true });
  498. // Fallback ecId for mock mode if missing
  499. if (!ecId) {
  500. ecId = 'mock_default_id';
  501. console.warn('No "id" parameter found. Using default mock ID:', ecId);
  502. }
  503. }
  504. // State for Marquee Data
  505. let marqueeData = {
  506. totalCp: 'N/A',
  507. totalDistanceKm: 'N/A',
  508. totalAnswerNum: 'N/A',
  509. remainingTimeStr: 'N/A'
  510. };
  511. function updateMarquee() {
  512. const marqueeTextContainer = document.getElementById('marqueeTextContainer');
  513. if (marqueeTextContainer) {
  514. marqueeTextContainer.innerText =
  515. `总打点数: ${marqueeData.totalCp}个 | 总里程: ${marqueeData.totalDistanceKm}km | 答题数: ${marqueeData.totalAnswerNum}道 | 距离比赛结束还有 ${marqueeData.remainingTimeStr} | 加油!冲鸭!`;
  516. }
  517. }
  518. // Set token if available
  519. if (token && window.API && window.API.setToken) {
  520. window.API.setToken(token);
  521. console.log('API Token set:', token);
  522. } else {
  523. if (env !== 'mock') console.warn('Token not found in URL or API.setToken not available.');
  524. }
  525. // Call API with ecId
  526. if (window.API && ecId) {
  527. console.log('Starting Analysis-Based Sequence...');
  528. // 0. Global State for selections
  529. window.CURRENT_SELECTION = {
  530. mcId: 0,
  531. mcType: 0,
  532. ocaId: 0, // Current selected map ID (for individual)
  533. mapList: [] // Store map options
  534. };
  535. // 1. Match Details (Core)
  536. API.getMatchRsDetail(ecId).then(matchRes => {
  537. console.log('API Response (getMatchRsDetail):', matchRes);
  538. if (!matchRes) return;
  539. const mcId = matchRes.mcId;
  540. const mcType = matchRes.mcType;
  541. window.CURRENT_SELECTION.mcId = mcId;
  542. window.CURRENT_SELECTION.mcType = mcType;
  543. // Update UI Info
  544. if (matchRes.nickName) document.getElementById('profileName').innerText = matchRes.nickName;
  545. if (matchRes.totalSysPoint !== undefined) document.getElementById('currentScoreDisplay').innerText = matchRes.totalSysPoint;
  546. if (matchRes.endSecond !== undefined) {
  547. marqueeData.remainingTimeStr = formatRemainingTime(matchRes.endSecond);
  548. updateMarquee();
  549. }
  550. // 2. Parallel Calls: MapList & Statistics
  551. const p1 = API.getMapList(mcId).then(mapRes => {
  552. console.log('API Response (getMapList):', mapRes);
  553. if (mapRes && mapRes.length > 0) {
  554. window.CURRENT_SELECTION.mapList = mapRes;
  555. // Default ocaId to the first map
  556. window.CURRENT_SELECTION.ocaId = mapRes[0].ocaId;
  557. // Update Dropdown/Tab UI if needed (Simulated here)
  558. // In a real app, you'd populate the 'individual' tab dropdown here
  559. console.log('Default ocaId set to:', window.CURRENT_SELECTION.ocaId);
  560. }
  561. }).catch(e => console.error('MapList Error:', e));
  562. const p2 = API.getCompStatistic(mcId).then(compStatsRes => {
  563. if (compStatsRes) {
  564. if (compStatsRes.totalDistance !== undefined) marqueeData.totalDistanceKm = Math.round(compStatsRes.totalDistance / 1000);
  565. if (compStatsRes.totalAnswerNum !== undefined) marqueeData.totalAnswerNum = compStatsRes.totalAnswerNum;
  566. if (compStatsRes.totalCp !== undefined) marqueeData.totalCp = compStatsRes.totalCp;
  567. updateMarquee();
  568. }
  569. }).catch(e => console.warn('CompStat Error:', e));
  570. // 3. Initial Rank Load (Wait for MapList to ensure ocaId is ready for Individual tab if that's default,
  571. // but usually Team tab is default which might not need specific ocaId or uses global context)
  572. Promise.all([p1, p2]).then(() => {
  573. loadRankData();
  574. });
  575. }).catch(err => console.error('MatchRsDetail Error:', err));
  576. } else if (!ecId) {
  577. console.warn('URL parameter "id" (ecId) not found.');
  578. }
  579. // Internal function to load rank data based on current state
  580. window.loadRankData = function() {
  581. const { mcId, mcType, ocaId } = window.CURRENT_SELECTION;
  582. // Determine effective ocaId based on current tab
  583. // If Team tab, usually we query global or specific team-level data.
  584. // If Individual tab, we MUST use the selected ocaId (mapId).
  585. // Note: The Vue component sends 'ocaId' in apiCardRankDetailQuery.
  586. // When in Team mode (tab1Current=0), it might still pass the ocaId if the team rank is also segregated by map,
  587. // OR it might rely on the backend ignoring it for team ranks.
  588. // Based on analysis: "onSelectChange" updates ocaId and calls query.
  589. let effectiveOcaId = ocaId;
  590. // If needed: if (currentTab === 'team') effectiveOcaId = 0; // Uncomment if team rank is global
  591. const dispArrStr = "teamCp,teamTodayCp,teamDistance,teamRightAnswerPer,teamTodayPace,regionCp,regionTodayCp,regionDistance,regionRightAnswerPer,regionTodayPace";
  592. console.log(`Fetching Rank: mcId=${mcId}, type=${mcType}, ocaId=${effectiveOcaId}`);
  593. API.getRankDetail(mcId, mcType, effectiveOcaId, dispArrStr).then(rankRes => {
  594. console.log('API Response (getRankDetail):', rankRes);
  595. if (rankRes) {
  596. API_DATA = rankRes;
  597. renderLeaderboard();
  598. } else {
  599. document.getElementById('leaderboard-container').innerHTML = '<div class="text-center text-gray-400 py-10 text-sm">暂无排名数据</div>';
  600. }
  601. }).catch(e => console.error('RankDetail Error:', e));
  602. };
  603. // Hook into tab switching
  604. const originalSwitchMainTab = window.switchMainTab;
  605. window.switchMainTab = function(type) {
  606. originalSwitchMainTab(type); // Update UI state
  607. // Re-load data (ocaId stays same or logic inside loadRankData handles it)
  608. loadRankData();
  609. };
  610. };
  611. </script>
  612. </body>
  613. </html>