detail.html 35 KB

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