index.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <title>11月挑战赛</title>
  7. <!-- 本地调试保留 mock_flutter.js,正式接入时移除 -->
  8. <script src="./mock_flutter.js"></script>
  9. <script src="./bridge.js"></script>
  10. <script src="./api.js"></script>
  11. <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
  12. <style>
  13. :root {
  14. --primary-purple: #593259;
  15. --primary-orange: #fdcb6e;
  16. --primary-red: #d63031;
  17. --text-dark: #2d3436;
  18. --footer-bg: #483055;
  19. }
  20. * {
  21. box-sizing: border-box;
  22. margin: 0;
  23. padding: 0;
  24. font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  25. -webkit-tap-highlight-color: transparent;
  26. user-select: none;
  27. }
  28. body {
  29. background: #f5f6fa;
  30. width: 100%;
  31. height: 100vh;
  32. overflow: hidden;
  33. display: flex;
  34. flex-direction: column;
  35. }
  36. /* 顶部 Header */
  37. .header-area {
  38. height: 280px;
  39. background: linear-gradient(to bottom, rgba(72, 48, 85, 0.7), rgba(45, 52, 54, 0.95)),
  40. url('https://img.freepik.com/free-vector/silhouette-trail-runner-running-forest-at-night_105940-705.jpg?w=800') center/cover;
  41. padding: 20px;
  42. padding-top: max(20px, env(safe-area-inset-top));
  43. color: white;
  44. border-bottom-left-radius: 30px; border-bottom-right-radius: 30px;
  45. position: relative; flex-shrink: 0;
  46. z-index: 1;
  47. }
  48. .nav-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
  49. .icon-btn {
  50. width: 36px; height: 36px; background: rgba(255,255,255,0.2); backdrop-filter: blur(5px);
  51. border-radius: 50%; display: flex; align-items: center; justify-content: center;
  52. cursor: pointer; border: 1px solid rgba(255,255,255,0.3);
  53. }
  54. .month-select { font-size: 18px; font-weight: bold; display: flex; align-items: center; gap: 6px; cursor: pointer; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }
  55. /* 仪表盘卡片 */
  56. .dashboard-card {
  57. margin-top: 25px;
  58. background: rgba(0, 0, 0, 0.4);
  59. backdrop-filter: blur(10px);
  60. border-radius: 20px;
  61. padding: 15px 20px;
  62. border: 1px solid rgba(255, 255, 255, 0.1);
  63. box-shadow: 0 8px 20px rgba(0,0,0,0.2);
  64. position: relative;
  65. z-index: 5;
  66. }
  67. .dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
  68. .dash-title { font-size: 16px; font-weight: bold; display: flex; align-items: center; gap: 8px; color: #fff; }
  69. .dash-icon { color: var(--primary-orange); }
  70. .dash-badge { background: var(--primary-orange); color: #2d3436; font-size: 12px; font-weight: 800; padding: 4px 12px; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); transition: all 0.3s;}
  71. .dash-badge.completed { background: linear-gradient(135deg, #55efc4, #00b894); color: white; }
  72. .trophy-track-container { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 0 10px; }
  73. .track-line-bg { position: absolute; top: 50%; left: 10px; right: 10px; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; transform: translateY(-50%); z-index: 0; }
  74. .track-line-active {
  75. position: absolute; top: 50%; left: 10px;
  76. width: 25%;
  77. height: 4px; background: var(--primary-orange); border-radius: 2px; transform: translateY(-50%); z-index: 0;
  78. box-shadow: 0 0 8px rgba(253, 203, 110, 0.6);
  79. transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  80. }
  81. .trophy-item {
  82. position: relative; z-index: 1; width: 32px; height: 32px;
  83. background: #2d3436; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%;
  84. display: flex; justify-content: center; align-items: center;
  85. color: #636e72; font-size: 12px;
  86. transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  87. }
  88. .trophy-item.active {
  89. background: #fff; border-color: var(--primary-orange); color: var(--primary-orange);
  90. transform: scale(1.15); box-shadow: 0 0 10px rgba(253, 203, 110, 0.5);
  91. }
  92. .trophy-item.final { width: 40px; height: 40px; border-color: rgba(255,255,255,0.5); font-size: 16px; }
  93. .trophy-item.final.active {
  94. background: linear-gradient(135deg, #f1c40f, #e67e22);
  95. color: white; border: none;
  96. transform: scale(1.3);
  97. box-shadow: 0 0 20px rgba(241, 196, 15, 0.6);
  98. animation: pulseTrophy 2s infinite;
  99. }
  100. @keyframes pulseTrophy {
  101. 0% { box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.7); }
  102. 70% { box-shadow: 0 0 0 10px rgba(241, 196, 15, 0); }
  103. 100% { box-shadow: 0 0 0 0 rgba(241, 196, 15, 0); }
  104. }
  105. /* 领奖台 */
  106. .podium-wrap {
  107. height: 140px;
  108. display: flex; justify-content: center; align-items: flex-end;
  109. margin-top: -60px;
  110. position: relative;
  111. z-index: 10;
  112. padding-bottom: 0px;
  113. }
  114. .p-col { display: flex; flex-direction: column; align-items: center; width: 30%; position: relative;}
  115. .p-2 { z-index: 2; margin-right: -15px; }
  116. .p-1 { z-index: 3; }
  117. .p-3 { z-index: 1; margin-left: -15px; }
  118. .p-img { width: 50px; height: 50px; border-radius: 50%; border: 3px solid white; background: #eee; margin-bottom: -10px; position: relative; z-index: 2; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.2);}
  119. .p-1 .p-img { width: 70px; height: 70px; border-color: #f1c40f; margin-bottom: -15px;}
  120. .p-img img { width: 100%; height: 100%; object-fit: cover; }
  121. .crown {
  122. position: absolute; top: -38px; color: #f1c40f; font-size: 32px;
  123. filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
  124. animation: crownFloat 2s ease-in-out infinite;
  125. z-index: 20;
  126. }
  127. @keyframes crownFloat {
  128. 0%, 100% { transform: translateY(0) rotate(-5deg); }
  129. 50% { transform: translateY(-8px) rotate(5deg); }
  130. }
  131. .p-box { width: 100%; text-align: center; padding-top: 15px; border-radius: 8px 8px 0 0; color: white; box-shadow: 0 5px 15px rgba(0,0,0,0.2); }
  132. .p-1 .p-box { height: 90px; background: linear-gradient(180deg, #f1c40f, #f39c12); padding-top: 20px; }
  133. .p-2 .p-box { height: 70px; background: linear-gradient(180deg, #bdc3c7, #95a5a6); }
  134. .p-3 .p-box { height: 55px; background: linear-gradient(180deg, #e67e22, #d35400); }
  135. .p-name { font-size: 12px; margin-bottom: 2px; text-shadow: 0 1px 1px rgba(0,0,0,0.3); white-space: nowrap; overflow: hidden; max-width: 80px; margin: 0 auto; text-overflow: ellipsis;}
  136. .p-score { font-size: 14px; font-weight: bold; }
  137. /* 列表容器 */
  138. .list-container {
  139. flex: 1; background: white; border-radius: 24px 24px 0 0;
  140. padding: 0 20px 120px 20px;
  141. overflow-y: auto;
  142. margin-top: -10px;
  143. box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
  144. position: relative; z-index: 8;
  145. -webkit-overflow-scrolling: touch;
  146. }
  147. .tabs {
  148. display: flex; justify-content: center; gap: 15px;
  149. position: sticky; top: 0; background: white; z-index: 9;
  150. padding-top: 20px; padding-bottom: 10px;
  151. }
  152. .tab { padding: 8px 20px; border-radius: 20px; font-size: 14px; color: #636e72; background: #f1f2f6; cursor: pointer; transition: 0.2s; }
  153. .tab.active { background: var(--text-dark); color: #fdcb6e; font-weight: bold; }
  154. .list-item { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid #f1f2f6; }
  155. .rank { width: 30px; text-align: center; font-weight: bold; color: #b2bec3; font-style: italic;}
  156. .avatar { width: 40px; height: 40px; border-radius: 50%; margin: 0 12px; background: #eee; overflow: hidden;}
  157. .avatar img { width: 100%; height: 100%; object-fit: cover;}
  158. .info { flex: 1; }
  159. .name { font-size: 14px; color: #2d3436; font-weight: bold; }
  160. .team { font-size: 11px; color: #636e72; display: flex; align-items: center; gap: 4px; }
  161. .score { font-size: 16px; font-weight: bold; color: var(--primary-purple); }
  162. /* 底部我的排名 */
  163. .my-rank-bar {
  164. position: fixed; bottom: 0; left: 0; width: 100%; height: 55px;
  165. background: var(--footer-bg); color: white;
  166. display: flex; align-items: center; padding: 0 20px;
  167. padding-bottom: env(safe-area-inset-bottom);
  168. box-sizing: border-box;
  169. border-radius: 24px 24px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); z-index: 99;
  170. }
  171. .my-rank-bar .rank { font-size: 16px; }
  172. .my-rank-bar .avatar { width: 34px; height: 34px; border-width: 2px; }
  173. .my-rank-bar .name { font-size: 14px; }
  174. .my-rank-bar .team { font-size: 10px; }
  175. .my-score { font-size: 18px; font-weight: bold; color: #ffffff !important; margin-left: auto; }
  176. /* 演示按钮样式 (模态框内) */
  177. .demo-section {
  178. margin: 20px 0 0 0;
  179. border-top: 1px dashed #ddd;
  180. padding-top: 15px;
  181. }
  182. .demo-label { font-size: 12px; color: #999; margin-bottom: 10px; }
  183. .demo-controls {
  184. display: flex; justify-content: center; gap: 10px;
  185. }
  186. .demo-btn {
  187. background: #eee; border: none; padding: 6px 12px; border-radius: 8px; font-size: 12px; color: #555; cursor: pointer;
  188. }
  189. .demo-btn:active { background: #ddd; color: #000; }
  190. /* 下拉菜单 & 模态框 */
  191. .dropdown { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); width: 200px; background: white; border-radius: 12px; box-shadow: 0 10px 50px rgba(0,0,0,0.4); display: none; flex-direction: column; overflow: hidden; z-index: 200; }
  192. .dropdown.show { display: flex; animation: dropIn 0.2s ease-out; }
  193. .dd-item { padding: 12px; color: #636e72; font-size: 14px; text-align: center; border-bottom: 1px solid #f1f2f6; cursor: pointer; }
  194. .dd-active { color: var(--primary-purple); font-weight: bold; background: #f9f0ff; }
  195. @keyframes dropIn { from{opacity:0; transform:translateX(-50%) translateY(-10px);} to{opacity:1; transform:translateX(-50%) translateY(0);} }
  196. .modal-mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 999; display: flex; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
  197. .modal-mask.show { opacity: 1; pointer-events: auto; }
  198. .modal-body { width: 80%; max-width: 320px; background: white; border-radius: 24px; padding: 25px; text-align: center; transform: scale(0.8); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); border: 4px solid var(--primary-purple); box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
  199. .modal-mask.show .modal-body { transform: scale(1); }
  200. .m-close { background: var(--primary-purple); color: white; padding: 10px 25px; border-radius: 20px; border: none; font-weight: bold; cursor: pointer; margin-top: 15px; }
  201. /* 加载遮罩 */
  202. .loading-mask {
  203. position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  204. display: none; align-items: center; justify-content: center;
  205. z-index: 300; color: #fff; font-size: 14px; backdrop-filter: blur(2px);
  206. }
  207. .loading-mask.show { display: flex; }
  208. .loading-spinner {
  209. border: 4px solid rgba(255,255,255,0.3);
  210. border-top-color: #fdcb6e;
  211. border-radius: 50%;
  212. width: 36px; height: 36px;
  213. animation: spin 1s linear infinite;
  214. margin-right: 10px;
  215. }
  216. @keyframes spin { to { transform: rotate(360deg); } }
  217. </style>
  218. </head>
  219. <body>
  220. <!-- 头部 -->
  221. <div class="header-area">
  222. <div class="nav-bar">
  223. <div class="icon-btn" onclick="handleBack()"><i class="fa-solid fa-chevron-left" style="color:white"></i></div>
  224. <div class="month-select" onclick="toggleDropdown()">
  225. <span id="currentMonthText">11月挑战赛</span> <i class="fa-solid fa-caret-down"></i>
  226. </div>
  227. <div class="icon-btn" onclick="openModal()"><i class="fa-solid fa-question" style="color:white"></i></div>
  228. </div>
  229. <!-- 仪表盘卡片 -->
  230. <div class="dashboard-card">
  231. <div class="dash-header">
  232. <div class="dash-title">
  233. <i class="fa-solid fa-medal dash-icon"></i> 定向达人
  234. </div>
  235. <div class="dash-badge" id="dashBadge">挑战 1 / 4</div>
  236. </div>
  237. <div class="trophy-track-container">
  238. <div class="track-line-bg"></div>
  239. <div class="track-line-active" id="progressLine"></div>
  240. <!-- 图标1 -->
  241. <div class="trophy-item active" id="t1"><i class="fa-solid fa-check"></i></div>
  242. <!-- 图标2 -->
  243. <div class="trophy-item" id="t2"><i class="fa-solid fa-lock"></i></div>
  244. <!-- 图标3 -->
  245. <div class="trophy-item" id="t3"><i class="fa-solid fa-lock"></i></div>
  246. <!-- 图标4 (Final) -->
  247. <div class="trophy-item final" id="t4"><i class="fa-solid fa-trophy"></i></div>
  248. </div>
  249. </div>
  250. </div>
  251. <!-- 下拉菜单 -->
  252. <div class="dropdown" id="dropdown"></div>
  253. <!-- 领奖台 -->
  254. <div class="podium-wrap" id="podiumWrap"></div>
  255. <!-- 列表区 -->
  256. <div class="list-container">
  257. <div class="tabs">
  258. <div class="tab active" onclick="switchTab('score', this)">积分排行</div>
  259. <div class="tab" onclick="switchTab('venue', this)">场地排行</div>
  260. </div>
  261. <div id="rankList"></div>
  262. </div>
  263. <!-- 底部我的排名 -->
  264. <div class="my-rank-bar">
  265. <div class="rank" id="myRankNum">--</div>
  266. <div class="avatar" id="myAvatar" style="border:2px solid #fdcb6e"><img src="https://api.dicebear.com/7.x/avataaars/svg?seed=Me" alt=""></div>
  267. <div class="info"><div class="name" id="myName" style="color:white">我</div><div class="team" id="myTeam" style="color:#b2bec3">正在加载...</div></div>
  268. <div class="my-score" id="myScoreValue">--</div>
  269. </div>
  270. <!-- 模态框 -->
  271. <div class="modal-mask" id="infoModal">
  272. <div class="modal-body">
  273. <h3 style="color:#593259; margin-bottom:15px;">📜 规则说明</h3>
  274. <p id="ruleContent" style="text-align:left; color:#636e72; font-size:14px; line-height:1.6;">数据加载中...</p>
  275. <!-- 演示功能区 -->
  276. <div class="demo-section">
  277. <div class="demo-label">✨ 功能演示</div>
  278. <div class="demo-controls">
  279. <button class="demo-btn" onclick="demoProgress(1);closeModal()">1/4</button>
  280. <button class="demo-btn" onclick="demoProgress(3);closeModal()">3/4</button>
  281. <button class="demo-btn" onclick="demoProgress(4);closeModal()">4/4</button>
  282. </div>
  283. </div>
  284. <button class="m-close" onclick="closeModal()">知道了</button>
  285. </div>
  286. </div>
  287. <!-- 加载中遮罩 -->
  288. <div class="loading-mask" id="loadingMask">
  289. <div class="loading-spinner"></div>
  290. <div>数据加载中...</div>
  291. </div>
  292. <script>
  293. const dropdown = document.getElementById('dropdown');
  294. const rankListEl = document.getElementById('rankList');
  295. const trackLine = document.getElementById('progressLine');
  296. const podiumWrap = document.getElementById('podiumWrap');
  297. const ruleContent = document.getElementById('ruleContent');
  298. const loadingMask = document.getElementById('loadingMask');
  299. const state = {
  300. activeTab: 'score',
  301. scoreList: [],
  302. scoreListRendered: null,
  303. venueList: [],
  304. venueListRendered: null,
  305. months: [],
  306. currentYM: null,
  307. currentMonthData: null,
  308. allMonthsData: null
  309. };
  310. function getQuery(name) {
  311. const params = new URLSearchParams(window.location.search);
  312. return params.get(name);
  313. }
  314. function getYearMonth() {
  315. const now = new Date();
  316. const year = parseInt(getQuery('year'), 10) || now.getFullYear();
  317. const month = parseInt(getQuery('month'), 10) || (now.getMonth() + 1);
  318. return { year: year, month: month };
  319. }
  320. function getRecentMonths(count) {
  321. const ym = getYearMonth();
  322. const list = [];
  323. let y = ym.year;
  324. let m = ym.month;
  325. for (let i = 0; i < (count || 3); i++) {
  326. list.push({ year: y, month: m });
  327. m -= 1;
  328. if (m === 0) { m = 12; y -= 1; }
  329. }
  330. return list;
  331. }
  332. function handleBack() {
  333. if (window.Bridge && Bridge.back) Bridge.back();
  334. else window.history.back();
  335. }
  336. function openModal() { document.getElementById('infoModal').classList.add('show'); }
  337. function closeModal() { document.getElementById('infoModal').classList.remove('show'); }
  338. function toggleDropdown() { dropdown.style.display = (dropdown.style.display === 'flex') ? 'none' : 'flex'; }
  339. function setLoading(isLoading) {
  340. rankListEl.style.opacity = isLoading ? '0.4' : '1';
  341. loadingMask.classList.toggle('show', isLoading);
  342. }
  343. function buildAvatar(name, salt) {
  344. const seedBase = name || 'user';
  345. const seed = encodeURIComponent(seedBase + (salt || ''));
  346. return `<img src="https://api.dicebear.com/7.x/avataaars/svg?seed=${seed}" alt="">`;
  347. }
  348. function setProgress(real, target) {
  349. const badge = document.getElementById('dashBadge');
  350. const t1 = document.getElementById('t1');
  351. const t2 = document.getElementById('t2');
  352. const t3 = document.getElementById('t3');
  353. const t4 = document.getElementById('t4');
  354. const safeReal = Math.max(real || 0, 0);
  355. const safeTarget = target && target > 0 ? target : 4;
  356. const ratio = Math.min(safeReal / safeTarget, 1);
  357. const percent = Math.max(0, Math.min(1, ratio)) * 100;
  358. trackLine.style.width = percent + '%';
  359. const textReal = safeReal >= safeTarget ? safeTarget : safeReal;
  360. badge.innerText = safeReal >= safeTarget ? '挑战成功' : `挑战 ${textReal} / ${safeTarget}`;
  361. badge.classList.toggle('completed', safeReal >= safeTarget);
  362. function setIconActive(el, active) {
  363. if (active) {
  364. el.classList.add('active');
  365. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-check"></i>';
  366. } else {
  367. el.classList.remove('active');
  368. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-lock"></i>';
  369. }
  370. }
  371. setIconActive(t1, safeReal >= 1);
  372. setIconActive(t2, safeReal >= 2);
  373. setIconActive(t3, safeReal >= 3);
  374. setIconActive(t4, safeReal >= safeTarget);
  375. }
  376. function renderBadge(real, target) {
  377. setProgress(real, target);
  378. }
  379. function findMonthProgress(year, month, currentMonthData, allMonthsData) {
  380. const result = { realNum: 0, targetNum: 4 };
  381. const pick = (arr) => {
  382. if (!arr || !arr.length) return null;
  383. for (let i = 0; i < arr.length; i++) {
  384. if (Number(arr[i].month) === Number(month)) return arr[i];
  385. }
  386. return null;
  387. };
  388. const fromCurrent = currentMonthData && pick(currentMonthData.monthRs || []);
  389. if (fromCurrent) return { realNum: fromCurrent.realNum || 0, targetNum: fromCurrent.targetNum || 4 };
  390. if (allMonthsData && allMonthsData.length) {
  391. for (let i = 0; i < allMonthsData.length; i++) {
  392. const item = allMonthsData[i];
  393. if (item.year && Number(item.year) !== Number(year)) continue;
  394. const found = pick(item.monthRs || []);
  395. if (found) return { realNum: found.realNum || 0, targetNum: found.targetNum || 4 };
  396. }
  397. }
  398. return result;
  399. }
  400. function renderMonths(list) {
  401. dropdown.innerHTML = '';
  402. if (!list || list.length === 0) {
  403. dropdown.innerHTML = '<div class="dd-item">暂无月份数据</div>';
  404. return;
  405. }
  406. list.forEach((item, idx) => {
  407. const title = `${item.month}月挑战赛`;
  408. const div = document.createElement('div');
  409. const isCurrent = state.currentYM && state.currentYM.year === item.year && state.currentYM.month === item.month;
  410. div.className = 'dd-item' + (isCurrent ? ' dd-active' : '');
  411. div.innerText = (idx === 0 && !isCurrent) ? `${title} (本月)` : title;
  412. div.onclick = () => {
  413. selectMonth(item.year, item.month, title);
  414. };
  415. dropdown.appendChild(div);
  416. });
  417. }
  418. function renderPodium(list, tabType) {
  419. const type = tabType || state.activeTab || 'score';
  420. podiumWrap.innerHTML = '';
  421. if (!list || list.length === 0) {
  422. podiumWrap.innerHTML = '<div style="color:#fff;">暂无榜单数据</div>';
  423. return;
  424. }
  425. const top3 = list.slice(0, 3);
  426. const cols = ['p-2', 'p-1', 'p-3'];
  427. top3.forEach((item, idx) => {
  428. const col = document.createElement('div');
  429. col.className = 'p-col ' + cols[idx];
  430. const name = item.nickName || item.name || item.userName || '选手';
  431. const score = item.score != null ? item.score : (item.inRankNum != null ? item.inRankNum : '--');
  432. const rankNum = item.rankNum || idx + 1;
  433. const isFirst = idx === 1;
  434. col.innerHTML = `
  435. ${isFirst ? '<div class="crown"><i class="fa-solid fa-crown"></i></div>' : ''}
  436. <div class="p-img">${buildAvatar(name, rankNum)}</div>
  437. <div class="p-box">
  438. <div class="p-name">${name}</div>
  439. <div class="p-score">${score}</div>
  440. </div>
  441. `;
  442. podiumWrap.appendChild(col);
  443. });
  444. const remaining = list.slice(3);
  445. if (type === 'venue') {
  446. state.venueListRendered = remaining;
  447. } else {
  448. state.scoreListRendered = remaining;
  449. }
  450. if (state.activeTab === type) renderRankList(remaining);
  451. }
  452. function renderRankList(list) {
  453. rankListEl.innerHTML = '';
  454. if (!list || list.length === 0) {
  455. rankListEl.innerHTML = '<div style="padding:20px; color:#b2bec3; text-align:center;">暂无数据</div>';
  456. return;
  457. }
  458. list.forEach((item, idx) => {
  459. const rankNum = item.rankNum || idx + 1;
  460. const name = item.nickName || item.name || item.userName || item.teamName || '选手';
  461. const scoreVal = (item.score != null ? item.score : item.inRankNum);
  462. const score = scoreVal != null ? scoreVal : '--';
  463. const team = item.teamName || item.coiName || '';
  464. const teamIcon = team ? '<i class="fa-solid fa-user-group"></i> ' : '<i class="fa-solid fa-user"></i> ';
  465. const row = document.createElement('div');
  466. row.className = 'list-item';
  467. row.innerHTML = `
  468. <div class="rank">${rankNum}</div>
  469. <div class="avatar">${buildAvatar(name, rankNum)}</div>
  470. <div class="info">
  471. <div class="name">${name}</div>
  472. <div class="team">${teamIcon}${team || '个人'}</div>
  473. </div>
  474. <div class="score">${score}</div>
  475. `;
  476. rankListEl.appendChild(row);
  477. });
  478. }
  479. function renderMyInfo(myRank, myScore, userInfo) {
  480. const rankNumEl = document.getElementById('myRankNum');
  481. const myScoreEl = document.getElementById('myScoreValue');
  482. const myNameEl = document.getElementById('myName');
  483. const myTeamEl = document.getElementById('myTeam');
  484. const myAvatarEl = document.getElementById('myAvatar');
  485. const rankVal = myRank && Number(myRank.rankNum);
  486. const hasRank = rankVal > 0;
  487. rankNumEl.innerText = hasRank ? rankVal : '--';
  488. myScoreEl.innerText = hasRank && myScore && myScore.score != null ? myScore.score : '--';
  489. const name = (userInfo && (userInfo.nickName || userInfo.userName)) || '我';
  490. myNameEl.innerText = name;
  491. myTeamEl.innerText = hasRank ? '继续加油' : '';
  492. myAvatarEl.innerHTML = buildAvatar(name, 'me');
  493. }
  494. function renderRules(config) {
  495. if (!config || !config.configJson) return;
  496. try {
  497. const parsed = JSON.parse(config.configJson);
  498. const rules = parsed.popupRuleList || [];
  499. if (rules.length > 0 && rules[0].data && rules[0].data.content) {
  500. ruleContent.innerHTML = rules[0].data.content;
  501. }
  502. } catch (err) {
  503. console.warn('[Rule] parse error', err);
  504. }
  505. }
  506. function switchTab(type, tabElement) {
  507. state.activeTab = type;
  508. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  509. if (tabElement) tabElement.classList.add('active');
  510. const baseList = type === 'venue' ? state.venueList : state.scoreList;
  511. renderPodium(baseList, type);
  512. const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
  513. renderRankList(rendered);
  514. }
  515. function demoProgress(step) {
  516. setProgress(step, 4);
  517. }
  518. async function loadMonthData(year, month) {
  519. state.currentYM = { year: year, month: month };
  520. document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
  521. renderMonths(state.months);
  522. setLoading(true);
  523. try {
  524. const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  525. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  526. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  527. state.scoreList = monthGrad;
  528. state.venueList = monthMap;
  529. const prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
  530. renderBadge(prog.realNum, prog.targetNum);
  531. renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
  532. switchTab(state.activeTab, document.querySelector('.tab.active'));
  533. } catch (err) {
  534. console.error('[Month] 加载失败', err);
  535. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  536. } finally {
  537. setLoading(false);
  538. }
  539. }
  540. function selectMonth(year, month, title) {
  541. dropdown.style.display = 'none';
  542. loadMonthData(year, month);
  543. }
  544. async function initPage() {
  545. const ecId = getQuery('ecId') || '4';
  546. const token = getQuery('token');
  547. let baseUrl = getQuery('baseUrl') || undefined;
  548. const env = (getQuery('env') || '').toLowerCase();
  549. const useMock = env === 'mock';
  550. const ym = getYearMonth();
  551. state.currentYM = ym;
  552. state.months = getRecentMonths(3);
  553. if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
  554. if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
  555. API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
  556. const allowLogin = !useMock && token;
  557. if (!token && !useMock && window.Bridge && Bridge.getToken) Bridge.getToken();
  558. renderMonths(state.months);
  559. setLoading(true);
  560. async function safeCall(promiseFactory) {
  561. try { return await promiseFactory(); }
  562. catch (err) { console.warn('[Optional API] ignore error', err); return null; }
  563. }
  564. try {
  565. const monthRank = await API.request('MonthRankDetailQuery', { year: ym.year, month: ym.month, dispArrStr: 'grad,mapNum' });
  566. let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
  567. if (useMock || allowLogin) {
  568. [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
  569. safeCall(() => API.getCardBase(ecId, 'rank')),
  570. safeCall(() => API.request('CurrentMonthlyChallengeQuery', { ecId: ecId })),
  571. safeCall(() => API.getMonthlyChallenge()),
  572. safeCall(() => API.getUserCurrentRank(ecId)),
  573. safeCall(() => API.getScore(ecId)),
  574. safeCall(() => API.getUserInfo()),
  575. safeCall(() => API.getCardConfig(ecId, 'rank'))
  576. ]);
  577. } else {
  578. base = { ecName: `${ym.month}月挑战赛` };
  579. currentMonth = { monthRs: [{ month: ym.month, realNum: 0, targetNum: 4 }] };
  580. allMonths = [];
  581. myRank = null;
  582. myScore = null;
  583. userInfo = null;
  584. cardConfig = null;
  585. }
  586. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  587. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  588. state.scoreList = monthGrad;
  589. state.venueList = monthMap;
  590. const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
  591. if (!base && monthGrad.length) base = { ecName: `${ym.month}月挑战赛` };
  592. state.currentMonthData = currentMonth || null;
  593. state.allMonthsData = allMonths || null;
  594. const prog = findMonthProgress(ym.year, ym.month, state.currentMonthData, state.allMonthsData);
  595. document.getElementById('currentMonthText').innerText = `${ym.month}月挑战赛`;
  596. renderBadge(prog.realNum, prog.targetNum);
  597. renderPodium(state.scoreList, 'score');
  598. switchTab(state.activeTab, document.querySelector('.tab.active'));
  599. let hasRenderedMyInfo = false;
  600. if (allowLogin && myRank) {
  601. const rankVal = Number(myRank.rankNum);
  602. if (rankVal > 0) {
  603. renderMyInfo({ rankNum: rankVal }, myScore, userInfo);
  604. } else {
  605. renderMyInfo({ rankNum: null }, null, userInfo);
  606. }
  607. hasRenderedMyInfo = true;
  608. } else if (selfRow) {
  609. renderMyInfo({ rankNum: selfRow.rankNum }, { score: selfRow.inRankNum || selfRow.score }, { nickName: selfRow.userName });
  610. hasRenderedMyInfo = true;
  611. }
  612. if (!hasRenderedMyInfo) {
  613. renderMyInfo(myRank, myScore, userInfo);
  614. }
  615. renderRules(cardConfig);
  616. } catch (err) {
  617. console.error('[Init] 加载失败', err);
  618. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  619. } finally {
  620. setLoading(false);
  621. }
  622. }
  623. document.addEventListener('click', (e) => {
  624. if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
  625. });
  626. document.addEventListener('DOMContentLoaded', initPage);
  627. </script>
  628. </body>
  629. </html>