detail-christmas.html 46 KB

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