detail.html 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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. --sport-bg: #0f0f0f;
  16. --sport-card: #1e1e1e;
  17. --sport-accent: #ccff00; /* Neon Green */
  18. --sport-secondary: #00ccff; /* Electric Blue */
  19. --sport-text: #ffffff;
  20. --sport-dim: #888;
  21. --footer-bg: #1a1a1a;
  22. }
  23. * {
  24. box-sizing: border-box;
  25. margin: 0;
  26. padding: 0;
  27. font-family: 'Segoe UI', 'Roboto', sans-serif;
  28. -webkit-tap-highlight-color: transparent;
  29. user-select: none;
  30. }
  31. /* detail.html 应该全屏显示,无需圆角 */
  32. html {
  33. width: 100%;
  34. height: 100%;
  35. overflow: hidden; /* 确保全屏不滚动,由内部 list-container 滚动 */
  36. }
  37. body {
  38. background: var(--sport-bg);
  39. width: 100%;
  40. height: 100%; /* 占满全屏 */
  41. margin: 0;
  42. display: flex;
  43. flex-direction: column;
  44. color: var(--sport-text);
  45. }
  46. /* 顶部 Header */
  47. .header-area {
  48. height: 200px;
  49. background: var(--sport-card);
  50. padding: 20px;
  51. padding-top: max(30px, env(safe-area-inset-top)); /* 调整顶部填充,避开手机状态栏 */
  52. position: relative; flex-shrink: 0;
  53. z-index: 1;
  54. /* 底部斜切 */
  55. clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
  56. border-bottom: 2px solid #333;
  57. }
  58. .nav-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; }
  59. .icon-btn {
  60. width: 36px; height: 36px;
  61. background: #333;
  62. border-radius: 8px; /* 方形倒角 */
  63. display: flex; align-items: center; justify-content: center;
  64. cursor: pointer; border: 1px solid #444;
  65. transform: skewX(-10deg);
  66. }
  67. .icon-btn i { transform: skewX(10deg); } /* 反向纠正图标 */
  68. .month-select {
  69. font-size: 18px; font-weight: 900; font-style: italic;
  70. display: flex; align-items: center; gap: 8px; cursor: pointer;
  71. color: var(--sport-text);
  72. text-transform: uppercase;
  73. }
  74. .month-select span { border-bottom: 2px solid var(--sport-accent); padding-bottom: 2px; }
  75. /* 仪表盘卡片 */
  76. .dashboard-card {
  77. margin-top: 15px;
  78. background: #000;
  79. border-radius: 0;
  80. padding: 15px 20px;
  81. border-left: 4px solid var(--sport-accent);
  82. box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  83. position: relative;
  84. z-index: 5;
  85. transform: skewX(-5deg);
  86. margin-left: 10px; margin-right: 10px;
  87. }
  88. /* 内容反向纠正 */
  89. .dashboard-card > * { transform: skewX(5deg); }
  90. .dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
  91. .dash-title { font-size: 14px; font-weight: bold; display: flex; align-items: center; gap: 8px; color: #aaa; text-transform: uppercase; letter-spacing: 1px; }
  92. .dash-icon { color: var(--sport-accent); }
  93. .dash-badge {
  94. background: transparent;
  95. color: var(--sport-accent);
  96. font-size: 14px; font-weight: 900; font-style: italic;
  97. padding: 2px 8px;
  98. border: 1px solid var(--sport-accent);
  99. }
  100. .dash-badge.completed { background: var(--sport-accent); color: #000; }
  101. .trophy-track-container { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 0 5px; margin-top: 10px;}
  102. /* 进度条改为分段格子 */
  103. .track-bg-grid {
  104. position: absolute; top: 50%; left: 10px; right: 10px; height: 6px;
  105. background: repeating-linear-gradient(90deg, #222, #222 4px, transparent 4px, transparent 8px);
  106. transform: translateY(-50%); z-index: 0;
  107. }
  108. .track-line-active {
  109. position: absolute; top: 50%; left: 10px;
  110. width: 25%;
  111. height: 6px; background: var(--sport-accent);
  112. transform: translateY(-50%); z-index: 0;
  113. box-shadow: 0 0 10px var(--sport-accent);
  114. transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  115. }
  116. .trophy-item {
  117. position: relative; z-index: 1; width: 24px; height: 24px;
  118. background: #222; border: 1px solid #444;
  119. transform: rotate(45deg); /* 菱形节点 */
  120. display: flex; justify-content: center; align-items: center;
  121. color: #666; font-size: 10px;
  122. transition: all 0.4s;
  123. }
  124. .trophy-item i { transform: rotate(-45deg); } /* 图标回正 */
  125. .trophy-item.active {
  126. background: #000; border-color: var(--sport-accent); color: var(--sport-accent);
  127. box-shadow: 0 0 8px var(--sport-accent);
  128. }
  129. .trophy-item.final { width: 32px; height: 32px; border-color: #666; font-size: 14px; }
  130. .trophy-item.final.active {
  131. background: var(--sport-accent); color: #000; border: none;
  132. box-shadow: 0 0 20px var(--sport-accent);
  133. }
  134. /* 领奖台 */
  135. .podium-wrap {
  136. height: 130px;
  137. display: flex; justify-content: center; align-items: flex-end;
  138. margin-top: -40px;
  139. position: relative;
  140. z-index: 10;
  141. padding-bottom: 0px;
  142. }
  143. .p-col { display: flex; flex-direction: column; align-items: center; width: 30%; position: relative;}
  144. .p-2 { z-index: 2; margin-right: -8px; }
  145. .p-1 { z-index: 3; }
  146. .p-3 { z-index: 1; margin-left: -8px; }
  147. /* 六边形头像遮罩 */
  148. .p-img {
  149. width: 48px; height: 48px;
  150. background: #222; margin-bottom: -15px; position: relative; z-index: 2;
  151. clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  152. display: flex; justify-content: center; align-items: center;
  153. }
  154. .p-img img { width: 100%; height: 100%; object-fit: cover; }
  155. /* 边框模拟 */
  156. .p-img::before {
  157. content: ''; position: absolute; inset: 0;
  158. border: 2px solid #444;
  159. clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  160. pointer-events: none;
  161. }
  162. .p-1 .p-img { width: 64px; height: 64px; margin-bottom: -20px;}
  163. .p-1 .p-img::before { border-color: var(--sport-accent); box-shadow: inset 0 0 10px var(--sport-accent); }
  164. .crown {
  165. position: absolute; top: -28px; color: var(--sport-accent); font-size: 24px;
  166. filter: drop-shadow(0 0 5px var(--sport-accent));
  167. animation: crownFloat 2s ease-in-out infinite;
  168. z-index: 20;
  169. }
  170. @keyframes crownFloat {
  171. 0%, 100% { transform: translateY(0); }
  172. 50% { transform: translateY(-5px); }
  173. }
  174. /* 梯形底座 */
  175. .p-box {
  176. width: 100%; text-align: center; padding-top: 20px;
  177. color: white;
  178. clip-path: polygon(15% 0, 85% 0, 100% 100%, 0% 100%);
  179. }
  180. .p-1 .p-box {
  181. height: 85px;
  182. background: linear-gradient(180deg, rgba(204,255,0,0.2), rgba(204,255,0,0.05));
  183. border-top: 2px solid var(--sport-accent);
  184. }
  185. .p-2 .p-box {
  186. height: 65px;
  187. background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
  188. border-top: 2px solid #888;
  189. }
  190. .p-3 .p-box {
  191. height: 55px;
  192. background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
  193. border-top: 2px solid #666;
  194. }
  195. .p-name { font-size: 10px; margin-bottom: 2px; color: #aaa; white-space: nowrap; overflow: hidden; max-width: 70px; margin: 0 auto; text-overflow: ellipsis;}
  196. .p-score { font-size: 14px; font-weight: 900; font-style: italic; color: #fff; }
  197. .p-1 .p-score { color: var(--sport-accent); }
  198. /* 列表容器 */
  199. .list-container {
  200. flex: 1; background: var(--sport-bg);
  201. padding: 0 15px 120px 15px;
  202. overflow-y: auto;
  203. margin-top: 10px;
  204. position: relative; z-index: 8;
  205. -webkit-overflow-scrolling: touch;
  206. }
  207. .tabs {
  208. display: flex; justify-content: center; gap: 20px;
  209. position: sticky; top: 0; background: var(--sport-bg); z-index: 9;
  210. padding-top: 10px; padding-bottom: 10px;
  211. border-bottom: 1px solid #222;
  212. }
  213. .tab {
  214. padding: 8px 0;
  215. font-size: 14px; color: #666; cursor: pointer;
  216. transition: 0.2s; text-transform: uppercase; font-weight: bold;
  217. position: relative;
  218. }
  219. .tab.active { color: var(--sport-text); }
  220. .tab.active::after {
  221. content: ''; position: absolute; bottom: 0; left: 0; right: 0;
  222. height: 3px; background: var(--sport-accent);
  223. box-shadow: 0 0 5px var(--sport-accent);
  224. }
  225. .list-item {
  226. display: flex; align-items: center; padding: 12px 10px;
  227. margin-bottom: 8px;
  228. background: #161616;
  229. border: 1px solid #222;
  230. transform: skewX(-5deg); /* 列表项倾斜 */
  231. }
  232. /* 内容反向纠正 */
  233. .list-item > * { transform: skewX(5deg); }
  234. .rank { width: 30px; text-align: center; font-weight: 900; font-style: italic; color: #444; font-size: 16px;}
  235. /* 前三名排名颜色 */
  236. .list-item:nth-child(1) .rank { color: var(--sport-accent); }
  237. .list-item:nth-child(2) .rank { color: #fff; }
  238. .list-item:nth-child(3) .rank { color: #ccc; }
  239. .avatar { width: 36px; height: 36px; margin: 0 12px; background: #333; clip-path: circle(50%);}
  240. .avatar img { width: 100%; height: 100%; object-fit: cover;}
  241. .info { flex: 1; }
  242. .name { font-size: 14px; color: #eee; font-weight: bold; }
  243. .team { font-size: 10px; color: #666; display: flex; align-items: center; gap: 4px; text-transform: uppercase;}
  244. .score { font-size: 16px; font-weight: 900; font-style: italic; color: var(--sport-accent); }
  245. /* 底部我的排名 */
  246. .my-rank-bar {
  247. position: fixed; bottom: 0; left: 0; width: 100%;
  248. background: #111; border-top: 2px solid var(--sport-accent);
  249. display: flex; align-items: center;
  250. padding: 0 20px;
  251. padding-top: 10px;
  252. padding-bottom: calc(10px + env(safe-area-inset-bottom));
  253. box-sizing: border-box;
  254. z-index: 99;
  255. box-shadow: 0 -10px 30px rgba(0,0,0,0.8);
  256. }
  257. .my-rank-bar .rank { font-size: 18px; color: var(--sport-accent); }
  258. .my-rank-bar .avatar { width: 34px; height: 34px; border: 2px solid var(--sport-accent); }
  259. .my-rank-bar .name { font-size: 14px; }
  260. .my-rank-bar .team { font-size: 10px; }
  261. .my-score { font-size: 20px; font-weight: 900; font-style: italic; color: #fff !important; margin-left: auto; text-shadow: 0 0 5px rgba(255,255,255,0.5);}
  262. /* 演示按钮样式 */
  263. .demo-section {
  264. margin: 20px 0 0 0; border-top: 1px dashed #333; padding-top: 15px;
  265. }
  266. .demo-label { font-size: 12px; color: #666; margin-bottom: 10px; }
  267. .demo-controls { display: flex; justify-content: center; gap: 10px; }
  268. .demo-btn {
  269. background: #333; border: 1px solid #555; padding: 6px 12px; font-size: 12px; color: #aaa; cursor: pointer;
  270. text-transform: uppercase;
  271. }
  272. .demo-btn:active { background: var(--sport-accent); color: #000; border-color: var(--sport-accent); }
  273. /* 下拉菜单 & 模态框 */
  274. .dropdown {
  275. position: absolute; top: 60px; left: 50%; transform: translateX(-50%); width: 200px;
  276. background: #222; border: 1px solid #444;
  277. box-shadow: 0 10px 50px rgba(0,0,0,0.8); display: none; flex-direction: column; z-index: 200;
  278. }
  279. .dropdown.show { display: flex; animation: dropIn 0.2s ease-out; }
  280. .dd-item { padding: 12px; color: #aaa; font-size: 14px; text-align: center; border-bottom: 1px solid #333; cursor: pointer; }
  281. .dd-active { color: #000; font-weight: bold; background: var(--sport-accent); }
  282. @keyframes dropIn { from{opacity:0; transform:translateX(-50%) translateY(-10px);} to{opacity:1; transform:translateX(-50%) translateY(0);} }
  283. .modal-mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); z-index: 999; display: flex; justify-content: center; align-items: center; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
  284. .modal-mask.show { opacity: 1; pointer-events: auto; }
  285. .modal-body {
  286. width: 80%; max-width: 320px;
  287. background: #1a1a1a; border: 1px solid #444;
  288. padding: 25px; text-align: center; transform: scale(0.8); transition: transform 0.3s;
  289. box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  290. }
  291. .modal-mask.show .modal-body { transform: scale(1); }
  292. .m-close {
  293. background: transparent; color: var(--sport-accent);
  294. padding: 10px 25px; border: 1px solid var(--sport-accent);
  295. font-weight: bold; cursor: pointer; margin-top: 15px; text-transform: uppercase;
  296. }
  297. .rule-box { text-align: left; background: #111; border: 1px solid #333; padding: 15px; color: #ccc; font-size: 13px; line-height: 1.6; }
  298. .rule-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
  299. .rule-item:last-child { margin-bottom: 0; }
  300. .rule-item i { color: var(--sport-accent); margin-top: 2px; }
  301. .loading-mask {
  302. position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  303. display: none; align-items: center; justify-content: center;
  304. z-index: 300; color: #fff; font-size: 14px; backdrop-filter: blur(2px);
  305. }
  306. .loading-mask.show { display: flex !important; } /* Fix: display flex to center content */
  307. .loading-spinner {
  308. border: 4px solid rgba(255,255,255,0.1);
  309. border-top-color: var(--sport-accent);
  310. border-radius: 50%;
  311. width: 36px; height: 36px;
  312. animation: spin 1s linear infinite;
  313. margin-right: 10px;
  314. }
  315. @keyframes spin { to { transform: rotate(360deg); } }
  316. </style>
  317. </head>
  318. <body>
  319. <!-- 头部 -->
  320. <div class="header-area">
  321. <div class="nav-bar">
  322. <div class="icon-btn" onclick="handleBack()"><i class="fa-solid fa-chevron-left" style="color:#ccc"></i></div>
  323. <div class="month-select" onclick="toggleDropdown()">
  324. <span id="currentMonthText">11月挑战赛</span> <i class="fa-solid fa-caret-down" style="font-size: 12px; margin-left: 5px;"></i>
  325. </div>
  326. <div class="icon-btn" onclick="openModal()"><i class="fa-solid fa-info" style="color:#ccc"></i></div>
  327. </div>
  328. <!-- 仪表盘卡片 -->
  329. <div class="dashboard-card">
  330. <div class="dash-header">
  331. <div class="dash-title">
  332. 任务状态
  333. </div>
  334. <div class="dash-badge" id="dashBadge">1 / 4</div>
  335. </div>
  336. <div class="trophy-track-container">
  337. <div class="track-bg-grid"></div>
  338. <div class="track-line-active" id="progressLine"></div>
  339. <!-- 图标1 -->
  340. <div class="trophy-item active" id="t1"><i class="fa-solid fa-check"></i></div>
  341. <!-- 图标2 -->
  342. <div class="trophy-item" id="t2"><i class="fa-solid fa-lock"></i></div>
  343. <!-- 图标3 -->
  344. <div class="trophy-item" id="t3"><i class="fa-solid fa-lock"></i></div>
  345. <!-- 图标4 (Final) -->
  346. <div class="trophy-item final" id="t4"><i class="fa-solid fa-trophy"></i></div>
  347. </div>
  348. </div>
  349. </div>
  350. <!-- 下拉菜单 -->
  351. <div class="dropdown" id="dropdown"></div>
  352. <!-- 领奖台 -->
  353. <div class="podium-wrap" id="podiumWrap"></div>
  354. <!-- 列表区 -->
  355. <div class="list-container">
  356. <div class="tabs">
  357. <div class="tab active" onclick="switchTab('score', this)">积分排名</div>
  358. <div class="tab" onclick="switchTab('venue', this)">场地排名</div>
  359. </div>
  360. <div id="rankList"></div>
  361. </div>
  362. <!-- 底部我的排名 -->
  363. <div class="my-rank-bar">
  364. <div class="rank" id="myRankNum">--</div>
  365. <div class="avatar" id="myAvatar"></div>
  366. <div class="info"><div class="name" id="myName">我</div><div class="team" id="myTeam">正在加载...</div></div>
  367. <div class="my-score" id="myScoreValue">--</div>
  368. </div>
  369. <!-- 模态框 -->
  370. <div class="modal-mask" id="infoModal">
  371. <div class="modal-body">
  372. <h3 style="color:var(--sport-text); margin-bottom:15px; text-transform:uppercase; letter-spacing:2px;">规则说明</h3>
  373. <div id="ruleContent" class="rule-box">
  374. <div class="rule-item"><i class="fa-solid fa-angle-right"></i><div><strong>积分规则:</strong> 在指定公园找到打卡点,耗时越短积分越高。</div></div>
  375. <div class="rule-item"><i class="fa-solid fa-angle-right"></i><div><strong>场地排行:</strong> 按解锁的公园场地数量排名。</div></div>
  376. <div class="rule-item"><i class="fa-solid fa-angle-right"></i><div><strong>奖杯获取:</strong> 完成4次有效挑战点亮全部奖杯。</div></div>
  377. </div>
  378. <!-- 演示功能区 -->
  379. <div class="demo-section">
  380. <div class="demo-label">功能演示</div>
  381. <div class="demo-controls">
  382. <button class="demo-btn" onclick="demoProgress(1);closeModal()">1/4</button>
  383. <button class="demo-btn" onclick="demoProgress(3);closeModal()">3/4</button>
  384. <button class="demo-btn" onclick="demoProgress(4);closeModal()">4/4</button>
  385. </div>
  386. </div>
  387. <button class="m-close" onclick="closeModal()">关闭</button>
  388. </div>
  389. </div>
  390. <!-- 加载中遮罩 -->
  391. <div class="loading-mask" id="loadingMask">
  392. <div class="loading-spinner"></div>
  393. <div>数据加载中...</div>
  394. </div>
  395. <script>
  396. const dropdown = document.getElementById('dropdown');
  397. const rankListEl = document.getElementById('rankList');
  398. const trackLine = document.getElementById('progressLine');
  399. const podiumWrap = document.getElementById('podiumWrap');
  400. const ruleContent = document.getElementById('ruleContent');
  401. const loadingMask = document.getElementById('loadingMask');
  402. const state = {
  403. activeTab: 'score',
  404. scoreList: [],
  405. scoreListRendered: null,
  406. venueList: [],
  407. venueListRendered: null,
  408. months: [],
  409. currentYM: null,
  410. currentMonthData: null,
  411. allMonthsData: null
  412. };
  413. // Logger Utility
  414. const Logger = {
  415. _isDev: false, // Will be set by initPage based on useMock
  416. init: function(isDev) {
  417. this._isDev = isDev;
  418. },
  419. log: function() {
  420. if (this._isDev) {
  421. console.log.apply(console, arguments);
  422. }
  423. },
  424. warn: function() {
  425. if (this._isDev) {
  426. console.warn.apply(console, arguments);
  427. }
  428. },
  429. error: function() {
  430. // Always log errors, regardless of dev mode
  431. console.error.apply(console, arguments);
  432. }
  433. };
  434. function getQuery(name) {
  435. const params = new URLSearchParams(window.location.search);
  436. return params.get(name);
  437. }
  438. function getYearMonth() {
  439. const now = new Date();
  440. const year = parseInt(getQuery('year'), 10) || now.getFullYear();
  441. const month = parseInt(getQuery('month'), 10) || (now.getMonth() + 1);
  442. return { year: year, month: month };
  443. }
  444. function getRecentMonths(count) {
  445. const ym = getYearMonth();
  446. const list = [];
  447. let y = ym.year;
  448. let m = ym.month;
  449. for (let i = 0; i < (count || 3); i++) {
  450. list.push({ year: y, month: m });
  451. m -= 1;
  452. if (m === 0) { m = 12; y -= 1; }
  453. }
  454. return list;
  455. }
  456. function handleBack() {
  457. if (window.Bridge && Bridge.toHome) Bridge.toHome();
  458. else window.history.back(); // Fallback for web environment
  459. }
  460. function openModal() { document.getElementById('infoModal').classList.add('show'); }
  461. function closeModal() { document.getElementById('infoModal').classList.remove('show'); }
  462. function toggleDropdown() { dropdown.style.display = (dropdown.style.display === 'flex') ? 'none' : 'flex'; }
  463. function setLoading(isLoading) {
  464. rankListEl.style.opacity = isLoading ? '0.4' : '1';
  465. // Use flex for the new layout
  466. if (isLoading) loadingMask.classList.add('show');
  467. else loadingMask.classList.remove('show');
  468. }
  469. function buildAvatar(name, salt) {
  470. // Use local Multiavatar library (Pure JS, no external requests)
  471. // It generates high-quality SVG avatars
  472. const seedBase = name || 'user';
  473. const seed = seedBase + (salt || '');
  474. // multiavatar(seed) returns an SVG string
  475. const svgCode = multiavatar(seed);
  476. // We need to wrap it in a container or return it as a data URI or direct HTML
  477. // Since the existing code expects an <img> tag or innerHTML, putting SVG directly is best for crispness.
  478. // However, the existing styling puts it inside a small circle div.
  479. // Multiavatar SVG is square, so we rely on parent CSS (overflow: hidden) to clip it to a circle.
  480. return svgCode;
  481. }
  482. function setProgress(real, target) {
  483. const badge = document.getElementById('dashBadge');
  484. const t1 = document.getElementById('t1');
  485. const t2 = document.getElementById('t2');
  486. const t3 = document.getElementById('t3');
  487. const t4 = document.getElementById('t4');
  488. const safeReal = Math.max(real || 0, 0);
  489. const safeTarget = target && target > 0 ? target : 4;
  490. const ratio = Math.min(safeReal / safeTarget, 1);
  491. const percent = Math.max(0, Math.min(1, ratio)) * 100;
  492. trackLine.style.width = percent + '%';
  493. const textReal = safeReal >= safeTarget ? safeTarget : safeReal;
  494. badge.innerText = safeReal >= safeTarget ? 'SUCCESS' : `${textReal} / ${safeTarget}`;
  495. badge.classList.toggle('completed', safeReal >= safeTarget);
  496. function setIconActive(el, active) {
  497. if (active) {
  498. el.classList.add('active');
  499. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-check"></i>';
  500. } else {
  501. el.classList.remove('active');
  502. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-lock"></i>';
  503. }
  504. }
  505. setIconActive(t1, safeReal >= 1);
  506. setIconActive(t2, safeReal >= 2);
  507. setIconActive(t3, safeReal >= 3);
  508. setIconActive(t4, safeReal >= safeTarget);
  509. }
  510. function renderBadge(real, target) {
  511. setProgress(real, target);
  512. }
  513. function findMonthProgress(year, month, currentMonthData, allMonthsData) {
  514. const result = { realNum: 0, targetNum: 4 };
  515. const pick = (arr) => {
  516. if (!arr || !arr.length) return null;
  517. for (let i = 0; i < arr.length; i++) {
  518. if (Number(arr[i].month) === Number(month)) return arr[i];
  519. }
  520. return null;
  521. };
  522. const fromCurrent = currentMonthData && pick(currentMonthData.monthRs || []);
  523. if (fromCurrent) return { realNum: fromCurrent.realNum || 0, targetNum: fromCurrent.targetNum || 4 };
  524. if (allMonthsData && allMonthsData.length) {
  525. for (let i = 0; i < allMonthsData.length; i++) {
  526. const item = allMonthsData[i];
  527. if (item.year && Number(item.year) !== Number(year)) continue;
  528. const found = pick(item.monthRs || []);
  529. if (found) return { realNum: found.realNum || 0, targetNum: found.targetNum || 4 };
  530. }
  531. }
  532. return result;
  533. }
  534. function renderMonths(list) {
  535. dropdown.innerHTML = '';
  536. if (!list || list.length === 0) {
  537. dropdown.innerHTML = '<div class="dd-item">暂无月份数据</div>';
  538. return;
  539. }
  540. list.forEach((item, idx) => {
  541. const title = `${item.month}月挑战赛`;
  542. const div = document.createElement('div');
  543. const isCurrent = state.currentYM && state.currentYM.year === item.year && state.currentYM.month === item.month;
  544. div.className = 'dd-item' + (isCurrent ? ' dd-active' : '');
  545. div.innerText = (idx === 0 && !isCurrent) ? `${title} (本月)` : title;
  546. div.onclick = () => {
  547. selectMonth(item.year, item.month, title);
  548. };
  549. dropdown.appendChild(div);
  550. });
  551. }
  552. function renderPodium(list, tabType) {
  553. const type = tabType || state.activeTab || 'score';
  554. podiumWrap.innerHTML = '';
  555. // Ensure we have at least 3 elements for the podium, filling with null if less.
  556. // This allows the podium structure to always be rendered, even if slots are empty.
  557. const podiumData = Array(3).fill(null);
  558. if (list && list.length > 0) {
  559. list.slice(0, 3).forEach((item, index) => {
  560. podiumData[index] = item;
  561. });
  562. }
  563. const p1 = podiumData[0]; // Actual Rank 1
  564. const p2 = podiumData[1]; // Actual Rank 2
  565. const p3 = podiumData[2]; // Actual Rank 3
  566. // Define the visual order for rendering (2nd, 1st, 3rd)
  567. const podiumItems = [
  568. { person: p2, className: 'p-2' }, // Left column - Second place
  569. { person: p1, className: 'p-1' }, // Middle column - First place
  570. { person: p3, className: 'p-3' } // Right column - Third place
  571. ];
  572. podiumItems.forEach(itemConfig => {
  573. const person = itemConfig.person;
  574. const col = document.createElement('div');
  575. col.className = 'p-col ' + itemConfig.className;
  576. const name = person ? (person.nickName || person.name || person.userName) : '---';
  577. const score = person ? (person.score != null ? person.score : (person.inRankNum != null ? person.inRankNum : '')) : '';
  578. // Placeholder avatar for empty slots or Multiavatar for actual people
  579. const avatarContent = person ? buildAvatar(name, person.rankNum) : '<div style="width:100%;height:100%;background:#111;display:flex;align-items:center;justify-content:center;color:#333;font-size:12px;font-weight:bold;">?</div>';
  580. // Only the actual first place gets the crown, and only if that person exists
  581. const isActualFirst = (person === p1 && p1 !== null);
  582. col.innerHTML = `
  583. ${isActualFirst ? '<div class="crown"><i class="fa-solid fa-crown"></i></div>' : ''}
  584. <div class="p-img">${avatarContent}</div>
  585. <div class="p-box">
  586. <div class="p-name">${name}</div>
  587. <div class="p-score">${score}</div>
  588. </div>
  589. `;
  590. podiumWrap.appendChild(col);
  591. });
  592. // The remaining items for the list below the podium
  593. const remaining = list && list.length > 3 ? list.slice(3) : [];
  594. if (type === 'venue') {
  595. state.venueListRendered = remaining;
  596. } else {
  597. state.scoreListRendered = remaining;
  598. }
  599. if (state.activeTab === type) renderRankList(remaining);
  600. }
  601. function renderRankList(list) {
  602. rankListEl.innerHTML = '';
  603. if (!list || list.length === 0) {
  604. rankListEl.innerHTML = '<div style="padding:20px; color:#666; text-align:center; text-transform:uppercase;">暂无数据</div>';
  605. return;
  606. }
  607. list.forEach((item, idx) => {
  608. const rankNum = item.rankNum || idx + 1;
  609. const name = item.nickName || item.name || item.userName || item.teamName || '选手';
  610. const scoreVal = (item.score != null ? item.score : item.inRankNum);
  611. const score = scoreVal != null ? scoreVal : '--';
  612. const team = item.teamName || item.coiName || '';
  613. const teamIcon = team ? '<i class="fa-solid fa-users"></i> ' : '<i class="fa-solid fa-user"></i> ';
  614. const row = document.createElement('div');
  615. row.className = 'list-item';
  616. row.innerHTML = `
  617. <div class="rank">${rankNum}</div>
  618. <div class="avatar">${buildAvatar(name, rankNum)}</div>
  619. <div class="info">
  620. <div class="name">${name}</div>
  621. <div class="team">${teamIcon}${team || '个人'}</div>
  622. </div>
  623. <div class="score">${score}</div>
  624. `;
  625. rankListEl.appendChild(row);
  626. });
  627. }
  628. function renderMyInfo(myRank, myScore, userInfo) {
  629. const rankNumEl = document.getElementById('myRankNum');
  630. const myScoreEl = document.getElementById('myScoreValue');
  631. const myNameEl = document.getElementById('myName');
  632. const myTeamEl = document.getElementById('myTeam');
  633. const myAvatarEl = document.getElementById('myAvatar');
  634. const rankVal = myRank && Number(myRank.rankNum);
  635. const hasRank = rankVal > 0;
  636. rankNumEl.innerText = hasRank ? rankVal : '--';
  637. myScoreEl.innerText = hasRank && myScore && myScore.score != null ? myScore.score : '--';
  638. const name = (userInfo && (userInfo.nickName || userInfo.userName)) || '我';
  639. myNameEl.innerText = name;
  640. myTeamEl.innerText = hasRank ? '继续挑战' : '';
  641. myAvatarEl.innerHTML = buildAvatar(name, 'me');
  642. // Remove click listener if exists (clean slate)
  643. document.querySelector('.my-rank-bar').onclick = null;
  644. }
  645. function renderGuestState() {
  646. const rankNumEl = document.getElementById('myRankNum');
  647. const myScoreEl = document.getElementById('myScoreValue');
  648. const myNameEl = document.getElementById('myName');
  649. const myTeamEl = document.getElementById('myTeam');
  650. const myAvatarEl = document.getElementById('myAvatar');
  651. const myRankBar = document.querySelector('.my-rank-bar');
  652. rankNumEl.innerText = '--';
  653. myScoreEl.innerText = '';
  654. myNameEl.innerText = '游客';
  655. myTeamEl.innerText = '点击登录';
  656. myTeamEl.style.color = 'var(--sport-accent)';
  657. // Random avatar
  658. const randomSeed = 'guest_' + Math.floor(Math.random() * 10000);
  659. myAvatarEl.innerHTML = buildAvatar('Guest', randomSeed);
  660. // Add click listener
  661. myRankBar.onclick = function() {
  662. if (window.Bridge && Bridge.toLogin) {
  663. Bridge.toLogin();
  664. }
  665. };
  666. }
  667. function renderRules(config) {
  668. if (!config || !config.configJson) return;
  669. try {
  670. const parsed = JSON.parse(config.configJson);
  671. const rules = parsed.popupRuleList || [];
  672. if (rules.length > 0 && rules[0].data && rules[0].data.content) {
  673. ruleContent.innerHTML = rules[0].data.content;
  674. }
  675. } catch (err) {
  676. Logger.warn('[Rule] parse error', err);
  677. }
  678. }
  679. function switchTab(type, tabElement) {
  680. state.activeTab = type;
  681. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  682. if (tabElement) tabElement.classList.add('active');
  683. const baseList = type === 'venue' ? state.venueList : state.scoreList;
  684. renderPodium(baseList, type);
  685. const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
  686. renderRankList(rendered);
  687. }
  688. function demoProgress(step) {
  689. setProgress(step, 4);
  690. }
  691. async function loadMonthData(year, month) {
  692. state.currentYM = { year: year, month: month };
  693. document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
  694. renderMonths(state.months);
  695. setLoading(true);
  696. try {
  697. const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  698. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  699. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  700. state.scoreList = monthGrad;
  701. state.venueList = monthMap;
  702. const prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
  703. renderBadge(prog.realNum, prog.targetNum);
  704. renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
  705. switchTab(state.activeTab, document.querySelector('.tab.active'));
  706. } catch (err) {
  707. Logger.error('[Month] 加载失败', err);
  708. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  709. } finally {
  710. setLoading(false);
  711. }
  712. }
  713. function selectMonth(year, month, title) {
  714. dropdown.style.display = 'none';
  715. loadMonthData(year, month);
  716. }
  717. async function initPage() {
  718. // Platform detection for CSS adjustments
  719. if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
  720. document.body.classList.add('platform-ios');
  721. }
  722. const ecId = getQuery('ecId') || '4';
  723. const token = getQuery('token');
  724. let baseUrl = getQuery('baseUrl') || undefined;
  725. const env = (getQuery('env') || '').toLowerCase();
  726. const useMock = env === 'mock';
  727. Logger.init(useMock); // Initialize logger based on mock status
  728. const ym = getYearMonth();
  729. // 1. Initialize with 6 months
  730. state.months = getRecentMonths(6);
  731. if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
  732. if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
  733. API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
  734. const allowLogin = !useMock && token;
  735. renderMonths(state.months);
  736. setLoading(true);
  737. async function safeCall(promiseFactory) {
  738. try { return await promiseFactory(); }
  739. catch (err) { Logger.warn('[Optional API] ignore error', err); return null; }
  740. }
  741. // Helper to load data for a specific month
  742. async function fetchMonthData(year, month) {
  743. return await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  744. }
  745. try {
  746. // 2. Try loading current month first
  747. let targetYM = { year: ym.year, month: ym.month };
  748. let monthRank = await fetchMonthData(targetYM.year, targetYM.month);
  749. // 3. Check if current month has data
  750. let monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  751. let monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  752. let hasData = monthGrad.length > 0 || monthMap.length > 0;
  753. // 4. If no data, search backwards in the 6-month list
  754. if (!hasData) {
  755. // Start from index 1 because index 0 (current month) is already checked
  756. for (let i = 1; i < state.months.length; i++) {
  757. const checkYM = state.months[i];
  758. const checkRank = await fetchMonthData(checkYM.year, checkYM.month);
  759. const checkGrad = checkRank && checkRank.gradRs ? checkRank.gradRs : [];
  760. const checkMap = checkRank && checkRank.mapNumRs ? checkRank.mapNumRs : [];
  761. if (checkGrad.length > 0 || checkMap.length > 0) {
  762. // Found data! Update target and data
  763. targetYM = checkYM;
  764. monthRank = checkRank;
  765. monthGrad = checkGrad;
  766. monthMap = checkMap;
  767. hasData = true;
  768. break;
  769. }
  770. }
  771. }
  772. // Update state with the found (or original empty) data
  773. state.currentYM = targetYM;
  774. state.scoreList = monthGrad;
  775. state.venueList = monthMap;
  776. let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
  777. if (useMock || allowLogin) {
  778. [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
  779. safeCall(() => API.getCardBase(ecId, 'rank')),
  780. safeCall(() => API.request('CurrentMonthlyChallengeQuery', { ecId: ecId })),
  781. safeCall(() => API.getMonthlyChallenge()),
  782. safeCall(() => API.getUserCurrentRank(ecId)),
  783. safeCall(() => API.getScore(ecId)),
  784. safeCall(() => API.getUserInfo()),
  785. safeCall(() => API.getCardConfig(ecId, 'rank'))
  786. ]);
  787. } else {
  788. base = { ecName: `${targetYM.month}月挑战赛` };
  789. currentMonth = { monthRs: [{ month: targetYM.month, realNum: 0, targetNum: 4 }] };
  790. allMonths = [];
  791. myRank = null;
  792. myScore = null;
  793. userInfo = null;
  794. cardConfig = null;
  795. }
  796. const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
  797. if (!base && monthGrad.length) base = { ecName: `${targetYM.month}月挑战赛` };
  798. state.currentMonthData = currentMonth || null;
  799. state.allMonthsData = allMonths || null;
  800. // IMPORTANT: Render with the actually selected month (targetYM)
  801. const prog = findMonthProgress(targetYM.year, targetYM.month, state.currentMonthData, state.allMonthsData);
  802. document.getElementById('currentMonthText').innerText = `${targetYM.month}月挑战赛`;
  803. // Re-render dropdown to highlight correct month
  804. renderMonths(state.months);
  805. renderBadge(prog.realNum, prog.targetNum);
  806. renderPodium(state.scoreList, 'score');
  807. switchTab(state.activeTab, document.querySelector('.tab.active'));
  808. if (!token && !useMock) {
  809. renderGuestState();
  810. } else {
  811. let hasRenderedMyInfo = false;
  812. if (allowLogin && myRank) {
  813. const rankVal = Number(myRank.rankNum);
  814. if (rankVal > 0) {
  815. renderMyInfo({ rankNum: rankVal }, myScore, userInfo);
  816. } else {
  817. renderMyInfo({ rankNum: null }, null, userInfo);
  818. }
  819. hasRenderedMyInfo = true;
  820. } else if (selfRow) {
  821. renderMyInfo({ rankNum: selfRow.rankNum }, { score: selfRow.inRankNum || selfRow.score }, { nickName: selfRow.userName });
  822. hasRenderedMyInfo = true;
  823. }
  824. if (!hasRenderedMyInfo) {
  825. renderMyInfo(myRank, myScore, userInfo);
  826. }
  827. }
  828. renderRules(cardConfig);
  829. } finally {
  830. setLoading(false);
  831. loadingMask.classList.remove('show'); // Force remove show class
  832. }
  833. }
  834. document.addEventListener('click', (e) => {
  835. if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
  836. });
  837. document.addEventListener('DOMContentLoaded', initPage);
  838. </script>
  839. </body>
  840. </html>