detail.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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('./bg.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. .rule-box { text-align: left; background: #f9f4ff; border: 1px solid #e3d7ff; border-radius: 12px; padding: 12px; color: #4b3a67; font-size: 13px; line-height: 1.6; box-shadow: inset 0 1px 0 rgba(255,255,255,0.7); }
  202. .rule-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
  203. .rule-item:last-child { margin-bottom: 0; }
  204. .rule-item i { color: var(--primary-orange); margin-top: 2px; }
  205. /* 加载遮罩 */
  206. .loading-mask {
  207. position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  208. display: none; align-items: center; justify-content: center;
  209. z-index: 300; color: #fff; font-size: 14px; backdrop-filter: blur(2px);
  210. }
  211. .loading-mask.show { display: flex; }
  212. .loading-spinner {
  213. border: 4px solid rgba(255,255,255,0.3);
  214. border-top-color: #fdcb6e;
  215. border-radius: 50%;
  216. width: 36px; height: 36px;
  217. animation: spin 1s linear infinite;
  218. margin-right: 10px;
  219. }
  220. @keyframes spin { to { transform: rotate(360deg); } }
  221. </style>
  222. </head>
  223. <body>
  224. <!-- 头部 -->
  225. <div class="header-area">
  226. <div class="nav-bar">
  227. <div class="icon-btn" onclick="handleBack()"><i class="fa-solid fa-chevron-left" style="color:white"></i></div>
  228. <div class="month-select" onclick="toggleDropdown()">
  229. <span id="currentMonthText">11月挑战赛</span> <i class="fa-solid fa-caret-down"></i>
  230. </div>
  231. <div class="icon-btn" onclick="openModal()"><i class="fa-solid fa-question" style="color:white"></i></div>
  232. </div>
  233. <!-- 仪表盘卡片 -->
  234. <div class="dashboard-card">
  235. <div class="dash-header">
  236. <div class="dash-title">
  237. <i class="fa-solid fa-medal dash-icon"></i> 定向达人
  238. </div>
  239. <div class="dash-badge" id="dashBadge">挑战 1 / 4</div>
  240. </div>
  241. <div class="trophy-track-container">
  242. <div class="track-line-bg"></div>
  243. <div class="track-line-active" id="progressLine"></div>
  244. <!-- 图标1 -->
  245. <div class="trophy-item active" id="t1"><i class="fa-solid fa-check"></i></div>
  246. <!-- 图标2 -->
  247. <div class="trophy-item" id="t2"><i class="fa-solid fa-lock"></i></div>
  248. <!-- 图标3 -->
  249. <div class="trophy-item" id="t3"><i class="fa-solid fa-lock"></i></div>
  250. <!-- 图标4 (Final) -->
  251. <div class="trophy-item final" id="t4"><i class="fa-solid fa-trophy"></i></div>
  252. </div>
  253. </div>
  254. </div>
  255. <!-- 下拉菜单 -->
  256. <div class="dropdown" id="dropdown"></div>
  257. <!-- 领奖台 -->
  258. <div class="podium-wrap" id="podiumWrap"></div>
  259. <!-- 列表区 -->
  260. <div class="list-container">
  261. <div class="tabs">
  262. <div class="tab active" onclick="switchTab('score', this)">积分排行</div>
  263. <div class="tab" onclick="switchTab('venue', this)">场地排行</div>
  264. </div>
  265. <div id="rankList"></div>
  266. </div>
  267. <!-- 底部我的排名 -->
  268. <div class="my-rank-bar">
  269. <div class="rank" id="myRankNum">--</div>
  270. <div class="avatar" id="myAvatar" style="border:2px solid #fdcb6e"><img src="https://api.dicebear.com/7.x/avataaars/svg?seed=Me" alt=""></div>
  271. <div class="info"><div class="name" id="myName" style="color:white">我</div><div class="team" id="myTeam" style="color:#b2bec3">正在加载...</div></div>
  272. <div class="my-score" id="myScoreValue">--</div>
  273. </div>
  274. <!-- 模态框 -->
  275. <div class="modal-mask" id="infoModal">
  276. <div class="modal-body">
  277. <h3 style="color:#593259; margin-bottom:15px;">📜 规则说明</h3>
  278. <div id="ruleContent" class="rule-box">
  279. <div class="rule-item"><i class="fa-solid fa-bullseye"></i><div><strong>积分规则:</strong> 在指定公园找到打卡点,耗时越短积分越高。</div></div>
  280. <div class="rule-item"><i class="fa-solid fa-map-location-dot"></i><div><strong>场地排行:</strong> 按解锁的公园场地数量排名。</div></div>
  281. <div class="rule-item"><i class="fa-solid fa-trophy"></i><div><strong>奖杯获取:</strong> 完成4次有效挑战点亮全部奖杯。</div></div>
  282. </div>
  283. <!-- 演示功能区 -->
  284. <div class="demo-section">
  285. <div class="demo-label">✨ 功能演示</div>
  286. <div class="demo-controls">
  287. <button class="demo-btn" onclick="demoProgress(1);closeModal()">1/4</button>
  288. <button class="demo-btn" onclick="demoProgress(3);closeModal()">3/4</button>
  289. <button class="demo-btn" onclick="demoProgress(4);closeModal()">4/4</button>
  290. </div>
  291. </div>
  292. <button class="m-close" onclick="closeModal()">知道了</button>
  293. </div>
  294. </div>
  295. <!-- 加载中遮罩 -->
  296. <div class="loading-mask" id="loadingMask">
  297. <div class="loading-spinner"></div>
  298. <div>数据加载中...</div>
  299. </div>
  300. <script>
  301. const dropdown = document.getElementById('dropdown');
  302. const rankListEl = document.getElementById('rankList');
  303. const trackLine = document.getElementById('progressLine');
  304. const podiumWrap = document.getElementById('podiumWrap');
  305. const ruleContent = document.getElementById('ruleContent');
  306. const loadingMask = document.getElementById('loadingMask');
  307. const state = {
  308. activeTab: 'score',
  309. scoreList: [],
  310. scoreListRendered: null,
  311. venueList: [],
  312. venueListRendered: null,
  313. months: [],
  314. currentYM: null,
  315. currentMonthData: null,
  316. allMonthsData: null
  317. };
  318. function getQuery(name) {
  319. const params = new URLSearchParams(window.location.search);
  320. return params.get(name);
  321. }
  322. function getYearMonth() {
  323. const now = new Date();
  324. const year = parseInt(getQuery('year'), 10) || now.getFullYear();
  325. const month = parseInt(getQuery('month'), 10) || (now.getMonth() + 1);
  326. return { year: year, month: month };
  327. }
  328. function getRecentMonths(count) {
  329. const ym = getYearMonth();
  330. const list = [];
  331. let y = ym.year;
  332. let m = ym.month;
  333. for (let i = 0; i < (count || 3); i++) {
  334. list.push({ year: y, month: m });
  335. m -= 1;
  336. if (m === 0) { m = 12; y -= 1; }
  337. }
  338. return list;
  339. }
  340. function handleBack() {
  341. if (window.Bridge && Bridge.toHome) Bridge.toHome();
  342. else window.history.back(); // Fallback for web environment
  343. }
  344. function openModal() { document.getElementById('infoModal').classList.add('show'); }
  345. function closeModal() { document.getElementById('infoModal').classList.remove('show'); }
  346. function toggleDropdown() { dropdown.style.display = (dropdown.style.display === 'flex') ? 'none' : 'flex'; }
  347. function setLoading(isLoading) {
  348. rankListEl.style.opacity = isLoading ? '0.4' : '1';
  349. loadingMask.classList.toggle('show', isLoading);
  350. }
  351. function buildAvatar(name, salt) {
  352. const seedBase = name || 'user';
  353. const seed = encodeURIComponent(seedBase + (salt || ''));
  354. return `<img src="https://api.dicebear.com/7.x/avataaars/svg?seed=${seed}" alt="">`;
  355. }
  356. function setProgress(real, target) {
  357. const badge = document.getElementById('dashBadge');
  358. const t1 = document.getElementById('t1');
  359. const t2 = document.getElementById('t2');
  360. const t3 = document.getElementById('t3');
  361. const t4 = document.getElementById('t4');
  362. const safeReal = Math.max(real || 0, 0);
  363. const safeTarget = target && target > 0 ? target : 4;
  364. const ratio = Math.min(safeReal / safeTarget, 1);
  365. const percent = Math.max(0, Math.min(1, ratio)) * 100;
  366. trackLine.style.width = percent + '%';
  367. const textReal = safeReal >= safeTarget ? safeTarget : safeReal;
  368. badge.innerText = safeReal >= safeTarget ? '挑战成功' : `挑战 ${textReal} / ${safeTarget}`;
  369. badge.classList.toggle('completed', safeReal >= safeTarget);
  370. function setIconActive(el, active) {
  371. if (active) {
  372. el.classList.add('active');
  373. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-check"></i>';
  374. } else {
  375. el.classList.remove('active');
  376. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-lock"></i>';
  377. }
  378. }
  379. setIconActive(t1, safeReal >= 1);
  380. setIconActive(t2, safeReal >= 2);
  381. setIconActive(t3, safeReal >= 3);
  382. setIconActive(t4, safeReal >= safeTarget);
  383. }
  384. function renderBadge(real, target) {
  385. setProgress(real, target);
  386. }
  387. function findMonthProgress(year, month, currentMonthData, allMonthsData) {
  388. const result = { realNum: 0, targetNum: 4 };
  389. const pick = (arr) => {
  390. if (!arr || !arr.length) return null;
  391. for (let i = 0; i < arr.length; i++) {
  392. if (Number(arr[i].month) === Number(month)) return arr[i];
  393. }
  394. return null;
  395. };
  396. const fromCurrent = currentMonthData && pick(currentMonthData.monthRs || []);
  397. if (fromCurrent) return { realNum: fromCurrent.realNum || 0, targetNum: fromCurrent.targetNum || 4 };
  398. if (allMonthsData && allMonthsData.length) {
  399. for (let i = 0; i < allMonthsData.length; i++) {
  400. const item = allMonthsData[i];
  401. if (item.year && Number(item.year) !== Number(year)) continue;
  402. const found = pick(item.monthRs || []);
  403. if (found) return { realNum: found.realNum || 0, targetNum: found.targetNum || 4 };
  404. }
  405. }
  406. return result;
  407. }
  408. function renderMonths(list) {
  409. dropdown.innerHTML = '';
  410. if (!list || list.length === 0) {
  411. dropdown.innerHTML = '<div class="dd-item">暂无月份数据</div>';
  412. return;
  413. }
  414. list.forEach((item, idx) => {
  415. const title = `${item.month}月挑战赛`;
  416. const div = document.createElement('div');
  417. const isCurrent = state.currentYM && state.currentYM.year === item.year && state.currentYM.month === item.month;
  418. div.className = 'dd-item' + (isCurrent ? ' dd-active' : '');
  419. div.innerText = (idx === 0 && !isCurrent) ? `${title} (本月)` : title;
  420. div.onclick = () => {
  421. selectMonth(item.year, item.month, title);
  422. };
  423. dropdown.appendChild(div);
  424. });
  425. }
  426. function renderPodium(list, tabType) {
  427. const type = tabType || state.activeTab || 'score';
  428. podiumWrap.innerHTML = '';
  429. if (!list || list.length === 0) {
  430. podiumWrap.innerHTML = '<div style="color:#fff;">暂无榜单数据</div>';
  431. return;
  432. }
  433. // Ensure we have at least 3 elements, fill with null if less
  434. const p1 = list[0]; // Actual Rank 1
  435. const p2 = list[1]; // Actual Rank 2
  436. const p3 = list[2]; // Actual Rank 3
  437. // Define the visual order for rendering (2nd, 1st, 3rd)
  438. const podiumItems = [
  439. { person: p2, className: 'p-2' }, // Left column - Second place
  440. { person: p1, className: 'p-1' }, // Middle column - First place
  441. { person: p3, className: 'p-3' } // Right column - Third place
  442. ];
  443. podiumItems.forEach(itemConfig => {
  444. const person = itemConfig.person;
  445. if (!person) return; // Skip if no person for this position
  446. const col = document.createElement('div');
  447. col.className = 'p-col ' + itemConfig.className;
  448. const name = person.nickName || person.name || person.userName || '选手';
  449. const score = person.score != null ? person.score : (person.inRankNum != null ? person.inRankNum : '--');
  450. const rankNum = person.rankNum; // Use actual rank from item
  451. // Only the actual first place gets the crown
  452. const isActualFirst = (person === p1);
  453. col.innerHTML = `
  454. ${isActualFirst ? '<div class="crown"><i class="fa-solid fa-crown"></i></div>' : ''}
  455. <div class="p-img">${buildAvatar(name, rankNum)}</div>
  456. <div class="p-box">
  457. <div class="p-name">${name}</div>
  458. <div class="p-score">${score}</div>
  459. </div>
  460. `;
  461. podiumWrap.appendChild(col);
  462. });
  463. const remaining = list.slice(3);
  464. if (type === 'venue') {
  465. state.venueListRendered = remaining;
  466. } else {
  467. state.scoreListRendered = remaining;
  468. }
  469. if (state.activeTab === type) renderRankList(remaining);
  470. }
  471. function renderRankList(list) {
  472. rankListEl.innerHTML = '';
  473. if (!list || list.length === 0) {
  474. rankListEl.innerHTML = '<div style="padding:20px; color:#b2bec3; text-align:center;">暂无数据</div>';
  475. return;
  476. }
  477. list.forEach((item, idx) => {
  478. const rankNum = item.rankNum || idx + 1;
  479. const name = item.nickName || item.name || item.userName || item.teamName || '选手';
  480. const scoreVal = (item.score != null ? item.score : item.inRankNum);
  481. const score = scoreVal != null ? scoreVal : '--';
  482. const team = item.teamName || item.coiName || '';
  483. const teamIcon = team ? '<i class="fa-solid fa-user-group"></i> ' : '<i class="fa-solid fa-user"></i> ';
  484. const row = document.createElement('div');
  485. row.className = 'list-item';
  486. row.innerHTML = `
  487. <div class="rank">${rankNum}</div>
  488. <div class="avatar">${buildAvatar(name, rankNum)}</div>
  489. <div class="info">
  490. <div class="name">${name}</div>
  491. <div class="team">${teamIcon}${team || '个人'}</div>
  492. </div>
  493. <div class="score">${score}</div>
  494. `;
  495. rankListEl.appendChild(row);
  496. });
  497. }
  498. function renderMyInfo(myRank, myScore, userInfo) {
  499. const rankNumEl = document.getElementById('myRankNum');
  500. const myScoreEl = document.getElementById('myScoreValue');
  501. const myNameEl = document.getElementById('myName');
  502. const myTeamEl = document.getElementById('myTeam');
  503. const myAvatarEl = document.getElementById('myAvatar');
  504. const rankVal = myRank && Number(myRank.rankNum);
  505. const hasRank = rankVal > 0;
  506. rankNumEl.innerText = hasRank ? rankVal : '--';
  507. myScoreEl.innerText = hasRank && myScore && myScore.score != null ? myScore.score : '--';
  508. const name = (userInfo && (userInfo.nickName || userInfo.userName)) || '我';
  509. myNameEl.innerText = name;
  510. myTeamEl.innerText = hasRank ? '继续加油' : '';
  511. myAvatarEl.innerHTML = buildAvatar(name, 'me');
  512. }
  513. function renderRules(config) {
  514. if (!config || !config.configJson) return;
  515. try {
  516. const parsed = JSON.parse(config.configJson);
  517. const rules = parsed.popupRuleList || [];
  518. if (rules.length > 0 && rules[0].data && rules[0].data.content) {
  519. ruleContent.innerHTML = rules[0].data.content;
  520. }
  521. } catch (err) {
  522. console.warn('[Rule] parse error', err);
  523. }
  524. }
  525. function switchTab(type, tabElement) {
  526. state.activeTab = type;
  527. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  528. if (tabElement) tabElement.classList.add('active');
  529. const baseList = type === 'venue' ? state.venueList : state.scoreList;
  530. renderPodium(baseList, type);
  531. const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
  532. renderRankList(rendered);
  533. }
  534. function demoProgress(step) {
  535. setProgress(step, 4);
  536. }
  537. async function loadMonthData(year, month) {
  538. state.currentYM = { year: year, month: month };
  539. document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
  540. renderMonths(state.months);
  541. setLoading(true);
  542. try {
  543. const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  544. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  545. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  546. state.scoreList = monthGrad;
  547. state.venueList = monthMap;
  548. const prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
  549. renderBadge(prog.realNum, prog.targetNum);
  550. renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
  551. switchTab(state.activeTab, document.querySelector('.tab.active'));
  552. } catch (err) {
  553. console.error('[Month] 加载失败', err);
  554. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  555. } finally {
  556. setLoading(false);
  557. }
  558. }
  559. function selectMonth(year, month, title) {
  560. dropdown.style.display = 'none';
  561. loadMonthData(year, month);
  562. }
  563. async function initPage() {
  564. const ecId = getQuery('ecId') || '4';
  565. const token = getQuery('token');
  566. let baseUrl = getQuery('baseUrl') || undefined;
  567. const env = (getQuery('env') || '').toLowerCase();
  568. const useMock = env === 'mock';
  569. const ym = getYearMonth();
  570. state.currentYM = ym;
  571. state.months = getRecentMonths(3);
  572. if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
  573. if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
  574. API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
  575. const allowLogin = !useMock && token;
  576. renderMonths(state.months);
  577. setLoading(true);
  578. async function safeCall(promiseFactory) {
  579. try { return await promiseFactory(); }
  580. catch (err) { console.warn('[Optional API] ignore error', err); return null; }
  581. }
  582. try {
  583. const monthRank = await API.request('MonthRankDetailQuery', { year: ym.year, month: ym.month, dispArrStr: 'grad,mapNum' });
  584. let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
  585. if (useMock || allowLogin) {
  586. [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
  587. safeCall(() => API.getCardBase(ecId, 'rank')),
  588. safeCall(() => API.request('CurrentMonthlyChallengeQuery', { ecId: ecId })),
  589. safeCall(() => API.getMonthlyChallenge()),
  590. safeCall(() => API.getUserCurrentRank(ecId)),
  591. safeCall(() => API.getScore(ecId)),
  592. safeCall(() => API.getUserInfo()),
  593. safeCall(() => API.getCardConfig(ecId, 'rank'))
  594. ]);
  595. } else {
  596. base = { ecName: `${ym.month}月挑战赛` };
  597. currentMonth = { monthRs: [{ month: ym.month, realNum: 0, targetNum: 4 }] };
  598. allMonths = [];
  599. myRank = null;
  600. myScore = null;
  601. userInfo = null;
  602. cardConfig = null;
  603. }
  604. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  605. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  606. state.scoreList = monthGrad;
  607. state.venueList = monthMap;
  608. const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
  609. if (!base && monthGrad.length) base = { ecName: `${ym.month}月挑战赛` };
  610. state.currentMonthData = currentMonth || null;
  611. state.allMonthsData = allMonths || null;
  612. const prog = findMonthProgress(ym.year, ym.month, state.currentMonthData, state.allMonthsData);
  613. document.getElementById('currentMonthText').innerText = `${ym.month}月挑战赛`;
  614. renderBadge(prog.realNum, prog.targetNum);
  615. renderPodium(state.scoreList, 'score');
  616. switchTab(state.activeTab, document.querySelector('.tab.active'));
  617. let hasRenderedMyInfo = false;
  618. if (allowLogin && myRank) {
  619. const rankVal = Number(myRank.rankNum);
  620. if (rankVal > 0) {
  621. renderMyInfo({ rankNum: rankVal }, myScore, userInfo);
  622. } else {
  623. renderMyInfo({ rankNum: null }, null, userInfo);
  624. }
  625. hasRenderedMyInfo = true;
  626. } else if (selfRow) {
  627. renderMyInfo({ rankNum: selfRow.rankNum }, { score: selfRow.inRankNum || selfRow.score }, { nickName: selfRow.userName });
  628. hasRenderedMyInfo = true;
  629. }
  630. if (!hasRenderedMyInfo) {
  631. renderMyInfo(myRank, myScore, userInfo);
  632. }
  633. renderRules(cardConfig);
  634. } catch (err) {
  635. console.error('[Init] 加载失败', err);
  636. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  637. } finally {
  638. setLoading(false);
  639. }
  640. }
  641. document.addEventListener('click', (e) => {
  642. if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
  643. });
  644. document.addEventListener('DOMContentLoaded', initPage);
  645. </script>
  646. </body>
  647. </html>