detail-christmas.html 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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, 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>';
  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, rankNum)}</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) {
  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. myTeamEl.innerText = hasRank ? '继续加油' : '';
  610. myAvatarEl.innerHTML = buildAvatar(name, 'me');
  611. // Remove click listener if exists (clean slate)
  612. document.querySelector('.my-rank-bar').onclick = null;
  613. }
  614. function renderGuestState() {
  615. const rankNumEl = document.getElementById('myRankNum');
  616. const myScoreEl = document.getElementById('myScoreValue');
  617. const myNameEl = document.getElementById('myName');
  618. const myTeamEl = document.getElementById('myTeam');
  619. const myAvatarEl = document.getElementById('myAvatar');
  620. const myRankBar = document.querySelector('.my-rank-bar');
  621. rankNumEl.innerText = '--';
  622. myScoreEl.innerText = '';
  623. myNameEl.innerText = '您还未登录';
  624. myTeamEl.innerText = '点击去登录';
  625. myTeamEl.style.color = '#fdcb6e';
  626. // Random avatar
  627. const randomSeed = 'guest_' + Math.floor(Math.random() * 10000);
  628. myAvatarEl.innerHTML = buildAvatar('Guest', randomSeed);
  629. // Add click listener
  630. myRankBar.onclick = function() {
  631. if (window.Bridge && Bridge.toLogin) {
  632. Bridge.toLogin();
  633. }
  634. };
  635. }
  636. function renderRules(config) {
  637. if (!config || !config.configJson) return;
  638. try {
  639. const parsed = JSON.parse(config.configJson);
  640. const rules = parsed.popupRuleList || [];
  641. if (rules.length > 0 && rules[0].data && rules[0].data.content) {
  642. ruleContent.innerHTML = rules[0].data.content;
  643. }
  644. } catch (err) {
  645. Logger.warn('[Rule] parse error', err);
  646. }
  647. }
  648. function switchTab(type, tabElement) {
  649. state.activeTab = type;
  650. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  651. if (tabElement) tabElement.classList.add('active');
  652. const baseList = type === 'venue' ? state.venueList : state.scoreList;
  653. renderPodium(baseList, type);
  654. const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
  655. renderRankList(rendered);
  656. }
  657. function demoProgress(step) {
  658. setProgress(step, 4);
  659. }
  660. async function loadMonthData(year, month) {
  661. state.currentYM = { year: year, month: month };
  662. document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
  663. renderMonths(state.months);
  664. setLoading(true);
  665. try {
  666. const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  667. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  668. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  669. state.scoreList = monthGrad;
  670. state.venueList = monthMap;
  671. const prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
  672. renderBadge(prog.realNum, prog.targetNum);
  673. renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
  674. switchTab(state.activeTab, document.querySelector('.tab.active'));
  675. } catch (err) {
  676. Logger.error('[Month] 加载失败', err);
  677. rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
  678. } finally {
  679. setLoading(false);
  680. }
  681. }
  682. function selectMonth(year, month, title) {
  683. dropdown.style.display = 'none';
  684. loadMonthData(year, month);
  685. }
  686. async function initPage() {
  687. // Platform detection for CSS adjustments
  688. if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
  689. document.body.classList.add('platform-ios');
  690. }
  691. const ecId = getQuery('ecId') || '4';
  692. const token = getQuery('token');
  693. let baseUrl = getQuery('baseUrl') || undefined;
  694. const env = (getQuery('env') || '').toLowerCase();
  695. const useMock = env === 'mock';
  696. Logger.init(useMock); // Initialize logger based on mock status
  697. const ym = getYearMonth();
  698. // 1. Initialize with 6 months
  699. state.months = getRecentMonths(6);
  700. if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
  701. if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
  702. API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
  703. const allowLogin = !useMock && token;
  704. renderMonths(state.months);
  705. setLoading(true);
  706. async function safeCall(promiseFactory) {
  707. try { return await promiseFactory(); }
  708. catch (err) { Logger.warn('[Optional API] ignore error', err); return null; }
  709. }
  710. // Helper to load data for a specific month
  711. async function fetchMonthData(year, month) {
  712. return await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  713. }
  714. try {
  715. // 2. Try loading current month first
  716. let targetYM = { year: ym.year, month: ym.month };
  717. let monthRank = await fetchMonthData(targetYM.year, targetYM.month);
  718. // 3. Check if current month has data
  719. let monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  720. let monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  721. let hasData = monthGrad.length > 0 || monthMap.length > 0;
  722. // 4. If no data, search backwards in the 6-month list
  723. if (!hasData) {
  724. // Start from index 1 because index 0 (current month) is already checked
  725. for (let i = 1; i < state.months.length; i++) {
  726. const checkYM = state.months[i];
  727. const checkRank = await fetchMonthData(checkYM.year, checkYM.month);
  728. const checkGrad = checkRank && checkRank.gradRs ? checkRank.gradRs : [];
  729. const checkMap = checkRank && checkRank.mapNumRs ? checkRank.mapNumRs : [];
  730. if (checkGrad.length > 0 || checkMap.length > 0) {
  731. // Found data! Update target and data
  732. targetYM = checkYM;
  733. monthRank = checkRank;
  734. monthGrad = checkGrad;
  735. monthMap = checkMap;
  736. hasData = true;
  737. break;
  738. }
  739. }
  740. }
  741. // Update state with the found (or original empty) data
  742. state.currentYM = targetYM;
  743. state.scoreList = monthGrad;
  744. state.venueList = monthMap;
  745. let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
  746. if (useMock || allowLogin) {
  747. [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
  748. safeCall(() => API.getCardBase(ecId, 'rank')),
  749. safeCall(() => API.request('CurrentMonthlyChallengeQuery', { ecId: ecId })),
  750. safeCall(() => API.getMonthlyChallenge()),
  751. safeCall(() => API.getUserCurrentRank(ecId)),
  752. safeCall(() => API.getScore(ecId)),
  753. safeCall(() => API.getUserInfo()),
  754. safeCall(() => API.getCardConfig(ecId, 'rank'))
  755. ]);
  756. } else {
  757. base = { ecName: `${targetYM.month}月挑战赛` };
  758. currentMonth = { monthRs: [{ month: targetYM.month, realNum: 0, targetNum: 4 }] };
  759. allMonths = [];
  760. myRank = null;
  761. myScore = null;
  762. userInfo = null;
  763. cardConfig = null;
  764. }
  765. const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
  766. if (!base && monthGrad.length) base = { ecName: `${targetYM.month}月挑战赛` };
  767. state.currentMonthData = currentMonth || null;
  768. state.allMonthsData = allMonths || null;
  769. // IMPORTANT: Render with the actually selected month (targetYM)
  770. const prog = findMonthProgress(targetYM.year, targetYM.month, state.currentMonthData, state.allMonthsData);
  771. document.getElementById('currentMonthText').innerText = `${targetYM.month}月挑战赛`;
  772. // Re-render dropdown to highlight correct month
  773. renderMonths(state.months);
  774. renderBadge(prog.realNum, prog.targetNum);
  775. renderPodium(state.scoreList, 'score');
  776. switchTab(state.activeTab, document.querySelector('.tab.active'));
  777. if (!token && !useMock) {
  778. renderGuestState();
  779. } else {
  780. let hasRenderedMyInfo = false;
  781. if (allowLogin && myRank) {
  782. const rankVal = Number(myRank.rankNum);
  783. if (rankVal > 0) {
  784. renderMyInfo({ rankNum: rankVal }, myScore, userInfo);
  785. } else {
  786. renderMyInfo({ rankNum: null }, null, userInfo);
  787. }
  788. hasRenderedMyInfo = true;
  789. } else if (selfRow) {
  790. renderMyInfo({ rankNum: selfRow.rankNum }, { score: selfRow.inRankNum || selfRow.score }, { nickName: selfRow.userName });
  791. hasRenderedMyInfo = true;
  792. }
  793. if (!hasRenderedMyInfo) {
  794. renderMyInfo(myRank, myScore, userInfo);
  795. }
  796. }
  797. renderRules(cardConfig);
  798. } finally {
  799. setLoading(false);
  800. loadingMask.classList.remove('show'); // Force remove show class
  801. }
  802. }
  803. document.addEventListener('click', (e) => {
  804. if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
  805. });
  806. document.addEventListener('DOMContentLoaded', initPage);
  807. </script>
  808. <!-- Christmas Snow Effect Logic -->
  809. <script>
  810. (function() {
  811. // Snow Effect
  812. const canvas = document.getElementById('snowCanvas');
  813. if (!canvas) return;
  814. const ctx = canvas.getContext('2d');
  815. let width, height;
  816. let particles = [];
  817. function resize() {
  818. width = window.innerWidth;
  819. height = window.innerHeight;
  820. canvas.width = width;
  821. canvas.height = height;
  822. }
  823. function initParticles() {
  824. particles = [];
  825. // Density: roughly 1 particle per 5px width, capped for performance
  826. const count = Math.min(200, Math.floor(width * 0.3));
  827. for(let i=0; i<count; i++) {
  828. particles.push({
  829. x: Math.random() * width,
  830. y: Math.random() * height,
  831. r: Math.random() * 2 + 1, // Radius 1-3px
  832. d: Math.random() * count, // density factor
  833. s: Math.random() * 1 + 0.5 // speed
  834. });
  835. }
  836. }
  837. function draw() {
  838. ctx.clearRect(0, 0, width, height);
  839. ctx.fillStyle = "rgba(255, 255, 255, 0.8)";
  840. ctx.beginPath();
  841. for(let i=0; i<particles.length; i++) {
  842. const p = particles[i];
  843. ctx.moveTo(p.x, p.y);
  844. ctx.arc(p.x, p.y, p.r, 0, Math.PI*2, true);
  845. }
  846. ctx.fill();
  847. update();
  848. }
  849. let angle = 0;
  850. function update() {
  851. angle += 0.01;
  852. for(let i=0; i<particles.length; i++) {
  853. const p = particles[i];
  854. // Movement logic: fall down + sway
  855. p.y += Math.cos(angle + p.d) + 1 + p.r/2;
  856. p.x += Math.sin(angle) * 2;
  857. // Reset if out of bounds
  858. if(p.x > width + 5 || p.x < -5 || p.y > height) {
  859. if(i % 3 > 0) {
  860. // 66% chance to respawn at top
  861. particles[i] = {x: Math.random()*width, y: -10, r: p.r, d: p.d, s: p.s};
  862. } else {
  863. // 33% chance to respawn at sides (wind effect)
  864. if(Math.sin(angle) > 0) {
  865. particles[i] = {x: -5, y: Math.random()*height, r: p.r, d: p.d, s: p.s};
  866. } else {
  867. particles[i] = {x: width+5, y: Math.random()*height, r: p.r, d: p.d, s: p.s};
  868. }
  869. }
  870. }
  871. }
  872. requestAnimationFrame(draw);
  873. }
  874. window.addEventListener('resize', () => {
  875. resize();
  876. initParticles();
  877. });
  878. resize();
  879. initParticles();
  880. draw();
  881. })();
  882. </script>
  883. </body>
  884. </html>