detail.html 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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: -28px; 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%;
  166. /* 移除固定高度,改用 padding 撑开,更灵活且紧凑 */
  167. background: var(--footer-bg); color: white;
  168. display: flex; align-items: center;
  169. padding: 0 20px;
  170. /* 上下留出 8px 间距 */
  171. padding-top: 8px;
  172. /* 底部间距 = 8px + constant(safe-area-inset-bottom) 用于兼容旧版 iOS */
  173. padding-bottom: calc(8px + constant(safe-area-inset-bottom));
  174. /* 底部间距 = 8px + 安全区高度 */
  175. padding-bottom: calc(8px + env(safe-area-inset-bottom));
  176. box-sizing: border-box;
  177. border-radius: 24px 24px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); z-index: 99;
  178. }
  179. .my-rank-bar .rank { font-size: 16px; }
  180. .my-rank-bar .avatar { width: 34px; height: 34px; border-width: 2px; }
  181. .my-rank-bar .name { font-size: 14px; }
  182. .my-rank-bar .team { font-size: 10px; }
  183. .my-score { font-size: 18px; font-weight: bold; color: #ffffff !important; margin-left: auto; }
  184. /* 演示按钮样式 (模态框内) */
  185. .demo-section {
  186. margin: 20px 0 0 0;
  187. border-top: 1px dashed #ddd;
  188. padding-top: 15px;
  189. }
  190. .demo-label { font-size: 12px; color: #999; margin-bottom: 10px; }
  191. .demo-controls {
  192. display: flex; justify-content: center; gap: 10px;
  193. }
  194. .demo-btn {
  195. background: #eee; border: none; padding: 6px 12px; border-radius: 8px; font-size: 12px; color: #555; cursor: pointer;
  196. }
  197. .demo-btn:active { background: #ddd; color: #000; }
  198. /* 下拉菜单 & 模态框 */
  199. .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; }
  200. .dropdown.show { display: flex; animation: dropIn 0.2s ease-out; }
  201. .dd-item { padding: 12px; color: #636e72; font-size: 14px; text-align: center; border-bottom: 1px solid #f1f2f6; cursor: pointer; }
  202. .dd-active { color: var(--primary-purple); font-weight: bold; background: #f9f0ff; }
  203. @keyframes dropIn { from{opacity:0; transform:translateX(-50%) translateY(-10px);} to{opacity:1; transform:translateX(-50%) translateY(0);} }
  204. .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; }
  205. .modal-mask.show { opacity: 1; pointer-events: auto; }
  206. .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); }
  207. .modal-mask.show .modal-body { transform: scale(1); }
  208. .m-close { background: var(--primary-purple); color: white; padding: 10px 25px; border-radius: 20px; border: none; font-weight: bold; cursor: pointer; margin-top: 15px; }
  209. .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); }
  210. .rule-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
  211. .rule-item:last-child { margin-bottom: 0; }
  212. .rule-item i { color: var(--primary-orange); margin-top: 2px; }
  213. .my-rank-bar {
  214. position: fixed; bottom: 0; left: 0; width: 100%;
  215. background: var(--footer-bg); color: white;
  216. display: flex; align-items: center;
  217. padding: 0 20px;
  218. /* Android / 默认: 稍大一点的间距以防贴边 */
  219. padding-top: 6px;
  220. padding-bottom: 10px;
  221. box-sizing: border-box;
  222. border-radius: 24px 24px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); z-index: 99;
  223. }
  224. /* iOS 专属优化: 极致压缩高度 */
  225. @supports (-webkit-touch-callout: none) {
  226. .my-rank-bar {
  227. /* 顶部仅留 4px */
  228. padding-top: 4px !important;
  229. /* 底部严格贴合安全区,不加任何额外间距 */
  230. padding-bottom: env(safe-area-inset-bottom) !important;
  231. }
  232. }
  233. .my-rank-bar .rank { font-size: 16px; }
  234. /* 稍微缩小底部头像以节省高度 */
  235. .my-rank-bar .avatar { width: 30px; height: 30px; border-width: 2px; }
  236. .my-rank-bar .name { font-size: 14px; }
  237. position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  238. display: none; align-items: center; justify-content: center;
  239. z-index: 300; color: #fff; font-size: 14px; backdrop-filter: blur(2px);
  240. }
  241. .loading-mask.show { display: none !important; }
  242. .loading-spinner {
  243. border: 4px solid rgba(255,255,255,0.3);
  244. border-top-color: #fdcb6e;
  245. border-radius: 50%;
  246. width: 36px; height: 36px;
  247. animation: spin 1s linear infinite;
  248. margin-right: 10px;
  249. }
  250. @keyframes spin { to { transform: rotate(360deg); } }
  251. </style>
  252. </head>
  253. <body>
  254. <!-- 头部 -->
  255. <div class="header-area">
  256. <div class="nav-bar">
  257. <div class="icon-btn" onclick="handleBack()"><i class="fa-solid fa-chevron-left" style="color:white"></i></div>
  258. <div class="month-select" onclick="toggleDropdown()">
  259. <span id="currentMonthText">11月挑战赛</span> <i class="fa-solid fa-caret-down"></i>
  260. </div>
  261. <div class="icon-btn" onclick="openModal()"><i class="fa-solid fa-question" style="color:white"></i></div>
  262. </div>
  263. <!-- 仪表盘卡片 -->
  264. <div class="dashboard-card">
  265. <div class="dash-header">
  266. <div class="dash-title">
  267. <i class="fa-solid fa-medal dash-icon"></i> 定向达人
  268. </div>
  269. <div class="dash-badge" id="dashBadge">挑战 1 / 4</div>
  270. </div>
  271. <div class="trophy-track-container">
  272. <div class="track-line-bg"></div>
  273. <div class="track-line-active" id="progressLine"></div>
  274. <!-- 图标1 -->
  275. <div class="trophy-item active" id="t1"><i class="fa-solid fa-check"></i></div>
  276. <!-- 图标2 -->
  277. <div class="trophy-item" id="t2"><i class="fa-solid fa-lock"></i></div>
  278. <!-- 图标3 -->
  279. <div class="trophy-item" id="t3"><i class="fa-solid fa-lock"></i></div>
  280. <!-- 图标4 (Final) -->
  281. <div class="trophy-item final" id="t4"><i class="fa-solid fa-trophy"></i></div>
  282. </div>
  283. </div>
  284. </div>
  285. <!-- 下拉菜单 -->
  286. <div class="dropdown" id="dropdown"></div>
  287. <!-- 领奖台 -->
  288. <div class="podium-wrap" id="podiumWrap"></div>
  289. <!-- 列表区 -->
  290. <div class="list-container">
  291. <div class="tabs">
  292. <div class="tab active" onclick="switchTab('score', this)">积分排行</div>
  293. <div class="tab" onclick="switchTab('venue', this)">场地排行</div>
  294. </div>
  295. <div id="rankList"></div>
  296. </div>
  297. <!-- 底部我的排名 -->
  298. <div class="my-rank-bar">
  299. <div class="rank" id="myRankNum">--</div>
  300. <div class="avatar" id="myAvatar" style="border:2px solid #fdcb6e; overflow:hidden;"></div>
  301. <div class="info"><div class="name" id="myName" style="color:white">我</div><div class="team" id="myTeam" style="color:#b2bec3">正在加载...</div></div>
  302. <div class="my-score" id="myScoreValue">--</div>
  303. </div>
  304. <!-- 模态框 -->
  305. <div class="modal-mask" id="infoModal">
  306. <div class="modal-body">
  307. <h3 style="color:#593259; margin-bottom:15px;">📜 规则说明</h3>
  308. <div id="ruleContent" class="rule-box">
  309. <div class="rule-item"><i class="fa-solid fa-bullseye"></i><div><strong>积分规则:</strong> 在指定公园找到打卡点,耗时越短积分越高。</div></div>
  310. <div class="rule-item"><i class="fa-solid fa-map-location-dot"></i><div><strong>场地排行:</strong> 按解锁的公园场地数量排名。</div></div>
  311. <div class="rule-item"><i class="fa-solid fa-trophy"></i><div><strong>奖杯获取:</strong> 完成4次有效挑战点亮全部奖杯。</div></div>
  312. </div>
  313. <!-- 演示功能区 -->
  314. <div class="demo-section">
  315. <div class="demo-label">✨ 功能演示</div>
  316. <div class="demo-controls">
  317. <button class="demo-btn" onclick="demoProgress(1);closeModal()">1/4</button>
  318. <button class="demo-btn" onclick="demoProgress(3);closeModal()">3/4</button>
  319. <button class="demo-btn" onclick="demoProgress(4);closeModal()">4/4</button>
  320. </div>
  321. </div>
  322. <button class="m-close" onclick="closeModal()">知道了</button>
  323. </div>
  324. </div>
  325. <!-- 加载中遮罩 -->
  326. <div class="loading-mask" id="loadingMask" style="display: none !important;">
  327. <div class="loading-spinner"></div>
  328. <div>数据加载中...</div>
  329. </div>
  330. <script>
  331. const dropdown = document.getElementById('dropdown');
  332. const rankListEl = document.getElementById('rankList');
  333. const trackLine = document.getElementById('progressLine');
  334. const podiumWrap = document.getElementById('podiumWrap');
  335. const ruleContent = document.getElementById('ruleContent');
  336. const loadingMask = document.getElementById('loadingMask');
  337. const state = {
  338. activeTab: 'score',
  339. scoreList: [],
  340. scoreListRendered: null,
  341. venueList: [],
  342. venueListRendered: null,
  343. months: [],
  344. currentYM: null,
  345. currentMonthData: null,
  346. allMonthsData: null
  347. };
  348. function getQuery(name) {
  349. const params = new URLSearchParams(window.location.search);
  350. return params.get(name);
  351. }
  352. function getYearMonth() {
  353. const now = new Date();
  354. const year = parseInt(getQuery('year'), 10) || now.getFullYear();
  355. const month = parseInt(getQuery('month'), 10) || (now.getMonth() + 1);
  356. return { year: year, month: month };
  357. }
  358. function getRecentMonths(count) {
  359. const ym = getYearMonth();
  360. const list = [];
  361. let y = ym.year;
  362. let m = ym.month;
  363. for (let i = 0; i < (count || 3); i++) {
  364. list.push({ year: y, month: m });
  365. m -= 1;
  366. if (m === 0) { m = 12; y -= 1; }
  367. }
  368. return list;
  369. }
  370. function handleBack() {
  371. if (window.Bridge && Bridge.toHome) Bridge.toHome();
  372. else window.history.back(); // Fallback for web environment
  373. }
  374. function openModal() { document.getElementById('infoModal').classList.add('show'); }
  375. function closeModal() { document.getElementById('infoModal').classList.remove('show'); }
  376. function toggleDropdown() { dropdown.style.display = (dropdown.style.display === 'flex') ? 'none' : 'flex'; }
  377. function setLoading(isLoading) {
  378. rankListEl.style.opacity = isLoading ? '0.4' : '1';
  379. loadingMask.classList.toggle('show', isLoading);
  380. }
  381. function buildAvatar(name, salt) {
  382. // Use local Multiavatar library (Pure JS, no external requests)
  383. // It generates high-quality SVG avatars
  384. const seedBase = name || 'user';
  385. const seed = seedBase + (salt || '');
  386. // multiavatar(seed) returns an SVG string
  387. const svgCode = multiavatar(seed);
  388. // We need to wrap it in a container or return it as a data URI or direct HTML
  389. // Since the existing code expects an <img> tag or innerHTML, putting SVG directly is best for crispness.
  390. // However, the existing styling puts it inside a small circle div.
  391. // Multiavatar SVG is square, so we rely on parent CSS (overflow: hidden) to clip it to a circle.
  392. return svgCode;
  393. }
  394. function setProgress(real, target) {
  395. const badge = document.getElementById('dashBadge');
  396. const t1 = document.getElementById('t1');
  397. const t2 = document.getElementById('t2');
  398. const t3 = document.getElementById('t3');
  399. const t4 = document.getElementById('t4');
  400. const safeReal = Math.max(real || 0, 0);
  401. const safeTarget = target && target > 0 ? target : 4;
  402. const ratio = Math.min(safeReal / safeTarget, 1);
  403. const percent = Math.max(0, Math.min(1, ratio)) * 100;
  404. trackLine.style.width = percent + '%';
  405. const textReal = safeReal >= safeTarget ? safeTarget : safeReal;
  406. badge.innerText = safeReal >= safeTarget ? '挑战成功' : `挑战 ${textReal} / ${safeTarget}`;
  407. badge.classList.toggle('completed', safeReal >= safeTarget);
  408. function setIconActive(el, active) {
  409. if (active) {
  410. el.classList.add('active');
  411. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-check"></i>';
  412. } else {
  413. el.classList.remove('active');
  414. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-lock"></i>';
  415. }
  416. }
  417. setIconActive(t1, safeReal >= 1);
  418. setIconActive(t2, safeReal >= 2);
  419. setIconActive(t3, safeReal >= 3);
  420. setIconActive(t4, safeReal >= safeTarget);
  421. }
  422. function renderBadge(real, target) {
  423. setProgress(real, target);
  424. }
  425. function findMonthProgress(year, month, currentMonthData, allMonthsData) {
  426. const result = { realNum: 0, targetNum: 4 };
  427. const pick = (arr) => {
  428. if (!arr || !arr.length) return null;
  429. for (let i = 0; i < arr.length; i++) {
  430. if (Number(arr[i].month) === Number(month)) return arr[i];
  431. }
  432. return null;
  433. };
  434. const fromCurrent = currentMonthData && pick(currentMonthData.monthRs || []);
  435. if (fromCurrent) return { realNum: fromCurrent.realNum || 0, targetNum: fromCurrent.targetNum || 4 };
  436. if (allMonthsData && allMonthsData.length) {
  437. for (let i = 0; i < allMonthsData.length; i++) {
  438. const item = allMonthsData[i];
  439. if (item.year && Number(item.year) !== Number(year)) continue;
  440. const found = pick(item.monthRs || []);
  441. if (found) return { realNum: found.realNum || 0, targetNum: found.targetNum || 4 };
  442. }
  443. }
  444. return result;
  445. }
  446. function renderMonths(list) {
  447. dropdown.innerHTML = '';
  448. if (!list || list.length === 0) {
  449. dropdown.innerHTML = '<div class="dd-item">暂无月份数据</div>';
  450. return;
  451. }
  452. list.forEach((item, idx) => {
  453. const title = `${item.month}月挑战赛`;
  454. const div = document.createElement('div');
  455. const isCurrent = state.currentYM && state.currentYM.year === item.year && state.currentYM.month === item.month;
  456. div.className = 'dd-item' + (isCurrent ? ' dd-active' : '');
  457. div.innerText = (idx === 0 && !isCurrent) ? `${title} (本月)` : title;
  458. div.onclick = () => {
  459. selectMonth(item.year, item.month, title);
  460. };
  461. dropdown.appendChild(div);
  462. });
  463. }
  464. function renderPodium(list, tabType) {
  465. const type = tabType || state.activeTab || 'score';
  466. podiumWrap.innerHTML = '';
  467. // Ensure we have at least 3 elements for the podium, filling with null if less.
  468. // This allows the podium structure to always be rendered, even if slots are empty.
  469. const podiumData = Array(3).fill(null);
  470. if (list && list.length > 0) {
  471. list.slice(0, 3).forEach((item, index) => {
  472. podiumData[index] = item;
  473. });
  474. }
  475. const p1 = podiumData[0]; // Actual Rank 1
  476. const p2 = podiumData[1]; // Actual Rank 2
  477. const p3 = podiumData[2]; // Actual Rank 3
  478. // Define the visual order for rendering (2nd, 1st, 3rd)
  479. const podiumItems = [
  480. { person: p2, className: 'p-2' }, // Left column - Second place
  481. { person: p1, className: 'p-1' }, // Middle column - First place
  482. { person: p3, className: 'p-3' } // Right column - Third place
  483. ];
  484. podiumItems.forEach(itemConfig => {
  485. const person = itemConfig.person;
  486. const col = document.createElement('div');
  487. col.className = 'p-col ' + itemConfig.className;
  488. const name = person ? (person.nickName || person.name || person.userName) : '虚位以待';
  489. const score = person ? (person.score != null ? person.score : (person.inRankNum != null ? person.inRankNum : '')) : '';
  490. // Placeholder avatar for empty slots or Multiavatar for actual people
  491. const avatarContent = person ? buildAvatar(name, person.rankNum) : '<div style="width:100%;height:100%;background:#ddd;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#666;font-size:12px;font-weight:bold;">?</div>';
  492. // Only the actual first place gets the crown, and only if that person exists
  493. const isActualFirst = (person === p1 && p1 !== null);
  494. col.innerHTML = `
  495. ${isActualFirst ? '<div class="crown"><i class="fa-solid fa-crown"></i></div>' : ''}
  496. <div class="p-img">${avatarContent}</div>
  497. <div class="p-box">
  498. <div class="p-name">${name}</div>
  499. <div class="p-score">${score}</div>
  500. </div>
  501. `;
  502. podiumWrap.appendChild(col);
  503. });
  504. // The remaining items for the list below the podium
  505. const remaining = list && list.length > 3 ? list.slice(3) : [];
  506. if (type === 'venue') {
  507. state.venueListRendered = remaining;
  508. } else {
  509. state.scoreListRendered = remaining;
  510. }
  511. if (state.activeTab === type) renderRankList(remaining);
  512. }
  513. function renderRankList(list) {
  514. rankListEl.innerHTML = '';
  515. if (!list || list.length === 0) {
  516. rankListEl.innerHTML = '<div style="padding:20px; color:#b2bec3; text-align:center;">暂无数据</div>';
  517. return;
  518. }
  519. list.forEach((item, idx) => {
  520. const rankNum = item.rankNum || idx + 1;
  521. const name = item.nickName || item.name || item.userName || item.teamName || '选手';
  522. const scoreVal = (item.score != null ? item.score : item.inRankNum);
  523. const score = scoreVal != null ? scoreVal : '--';
  524. const team = item.teamName || item.coiName || '';
  525. const teamIcon = team ? '<i class="fa-solid fa-user-group"></i> ' : '<i class="fa-solid fa-user"></i> ';
  526. const row = document.createElement('div');
  527. row.className = 'list-item';
  528. row.innerHTML = `
  529. <div class="rank">${rankNum}</div>
  530. <div class="avatar">${buildAvatar(name, rankNum)}</div>
  531. <div class="info">
  532. <div class="name">${name}</div>
  533. <div class="team">${teamIcon}${team || '个人'}</div>
  534. </div>
  535. <div class="score">${score}</div>
  536. `;
  537. rankListEl.appendChild(row);
  538. });
  539. }
  540. function renderMyInfo(myRank, myScore, userInfo) {
  541. const rankNumEl = document.getElementById('myRankNum');
  542. const myScoreEl = document.getElementById('myScoreValue');
  543. const myNameEl = document.getElementById('myName');
  544. const myTeamEl = document.getElementById('myTeam');
  545. const myAvatarEl = document.getElementById('myAvatar');
  546. const rankVal = myRank && Number(myRank.rankNum);
  547. const hasRank = rankVal > 0;
  548. rankNumEl.innerText = hasRank ? rankVal : '--';
  549. myScoreEl.innerText = hasRank && myScore && myScore.score != null ? myScore.score : '--';
  550. const name = (userInfo && (userInfo.nickName || userInfo.userName)) || '我';
  551. myNameEl.innerText = name;
  552. myTeamEl.innerText = hasRank ? '继续加油' : '';
  553. myAvatarEl.innerHTML = buildAvatar(name, 'me');
  554. }
  555. function renderRules(config) {
  556. if (!config || !config.configJson) return;
  557. try {
  558. const parsed = JSON.parse(config.configJson);
  559. const rules = parsed.popupRuleList || [];
  560. if (rules.length > 0 && rules[0].data && rules[0].data.content) {
  561. ruleContent.innerHTML = rules[0].data.content;
  562. }
  563. } catch (err) {
  564. console.warn('[Rule] parse error', err);
  565. }
  566. }
  567. function switchTab(type, tabElement) {
  568. state.activeTab = type;
  569. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  570. if (tabElement) tabElement.classList.add('active');
  571. const baseList = type === 'venue' ? state.venueList : state.scoreList;
  572. renderPodium(baseList, type);
  573. const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
  574. renderRankList(rendered);
  575. }
  576. function demoProgress(step) {
  577. setProgress(step, 4);
  578. }
  579. async function loadMonthData(year, month) {
  580. state.currentYM = { year: year, month: month };
  581. document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
  582. renderMonths(state.months);
  583. setLoading(true);
  584. try {
  585. const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  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 prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
  591. renderBadge(prog.realNum, prog.targetNum);
  592. renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
  593. switchTab(state.activeTab, document.querySelector('.tab.active'));
  594. } catch (err) {
  595. console.error('[Month] 加载失败', err);
  596. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  597. } finally {
  598. setLoading(false);
  599. }
  600. }
  601. function selectMonth(year, month, title) {
  602. dropdown.style.display = 'none';
  603. loadMonthData(year, month);
  604. }
  605. async function initPage() {
  606. // Platform detection for CSS adjustments
  607. if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
  608. document.body.classList.add('platform-ios');
  609. }
  610. const ecId = getQuery('ecId') || '4';
  611. const token = getQuery('token');
  612. let baseUrl = getQuery('baseUrl') || undefined;
  613. const env = (getQuery('env') || '').toLowerCase();
  614. const useMock = env === 'mock';
  615. const ym = getYearMonth();
  616. // 1. Initialize with 6 months
  617. state.months = getRecentMonths(6);
  618. if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
  619. if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
  620. API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
  621. const allowLogin = !useMock && token;
  622. renderMonths(state.months);
  623. setLoading(true);
  624. async function safeCall(promiseFactory) {
  625. try { return await promiseFactory(); }
  626. catch (err) { console.warn('[Optional API] ignore error', err); return null; }
  627. }
  628. // Helper to load data for a specific month
  629. async function fetchMonthData(year, month) {
  630. return await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  631. }
  632. try {
  633. // 2. Try loading current month first
  634. let targetYM = { year: ym.year, month: ym.month };
  635. let monthRank = await fetchMonthData(targetYM.year, targetYM.month);
  636. // 3. Check if current month has data
  637. let monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  638. let monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  639. let hasData = monthGrad.length > 0 || monthMap.length > 0;
  640. // 4. If no data, search backwards in the 6-month list
  641. if (!hasData) {
  642. // Start from index 1 because index 0 (current month) is already checked
  643. for (let i = 1; i < state.months.length; i++) {
  644. const checkYM = state.months[i];
  645. const checkRank = await fetchMonthData(checkYM.year, checkYM.month);
  646. const checkGrad = checkRank && checkRank.gradRs ? checkRank.gradRs : [];
  647. const checkMap = checkRank && checkRank.mapNumRs ? checkRank.mapNumRs : [];
  648. if (checkGrad.length > 0 || checkMap.length > 0) {
  649. // Found data! Update target and data
  650. targetYM = checkYM;
  651. monthRank = checkRank;
  652. monthGrad = checkGrad;
  653. monthMap = checkMap;
  654. hasData = true;
  655. break;
  656. }
  657. }
  658. }
  659. // Update state with the found (or original empty) data
  660. state.currentYM = targetYM;
  661. state.scoreList = monthGrad;
  662. state.venueList = monthMap;
  663. let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
  664. if (useMock || allowLogin) {
  665. [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
  666. safeCall(() => API.getCardBase(ecId, 'rank')),
  667. safeCall(() => API.request('CurrentMonthlyChallengeQuery', { ecId: ecId })),
  668. safeCall(() => API.getMonthlyChallenge()),
  669. safeCall(() => API.getUserCurrentRank(ecId)),
  670. safeCall(() => API.getScore(ecId)),
  671. safeCall(() => API.getUserInfo()),
  672. safeCall(() => API.getCardConfig(ecId, 'rank'))
  673. ]);
  674. } else {
  675. base = { ecName: `${targetYM.month}月挑战赛` };
  676. currentMonth = { monthRs: [{ month: targetYM.month, realNum: 0, targetNum: 4 }] };
  677. allMonths = [];
  678. myRank = null;
  679. myScore = null;
  680. userInfo = null;
  681. cardConfig = null;
  682. }
  683. const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
  684. if (!base && monthGrad.length) base = { ecName: `${targetYM.month}月挑战赛` };
  685. state.currentMonthData = currentMonth || null;
  686. state.allMonthsData = allMonths || null;
  687. // IMPORTANT: Render with the actually selected month (targetYM)
  688. const prog = findMonthProgress(targetYM.year, targetYM.month, state.currentMonthData, state.allMonthsData);
  689. document.getElementById('currentMonthText').innerText = `${targetYM.month}月挑战赛`;
  690. // Re-render dropdown to highlight correct month
  691. renderMonths(state.months);
  692. renderBadge(prog.realNum, prog.targetNum);
  693. renderPodium(state.scoreList, 'score');
  694. switchTab(state.activeTab, document.querySelector('.tab.active'));
  695. let hasRenderedMyInfo = false;
  696. if (allowLogin && myRank) {
  697. const rankVal = Number(myRank.rankNum);
  698. if (rankVal > 0) {
  699. renderMyInfo({ rankNum: rankVal }, myScore, userInfo);
  700. } else {
  701. renderMyInfo({ rankNum: null }, null, userInfo);
  702. }
  703. hasRenderedMyInfo = true;
  704. } else if (selfRow) {
  705. renderMyInfo({ rankNum: selfRow.rankNum }, { score: selfRow.inRankNum || selfRow.score }, { nickName: selfRow.userName });
  706. hasRenderedMyInfo = true;
  707. }
  708. if (!hasRenderedMyInfo) {
  709. renderMyInfo(myRank, myScore, userInfo);
  710. }
  711. renderRules(cardConfig);
  712. } finally {
  713. setLoading(false);
  714. loadingMask.classList.remove('show'); // Force remove show class
  715. }
  716. }
  717. document.addEventListener('click', (e) => {
  718. if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
  719. });
  720. document.addEventListener('DOMContentLoaded', initPage);
  721. </script>
  722. </body>
  723. </html>