detail-snow.html 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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. <!-- <script src="./mock_flutter.js"></script> -->
  8. <script src="./bridge.js"></script>
  9. <script src="./api.js"></script>
  10. <script src="./js/multiavatar.min.js"></script>
  11. <link href="./css/all.min.css" rel="stylesheet">
  12. <style>
  13. :root {
  14. /* 调整为冬日冷色调 */
  15. --primary-purple: #2c3e50;
  16. --primary-orange: #74b9ff;
  17. --primary-red: #ff7675;
  18. --text-dark: #2d3436;
  19. --footer-bg: #2f3640;
  20. --snow-white: #ffffff;
  21. }
  22. * {
  23. box-sizing: border-box;
  24. margin: 0;
  25. padding: 0;
  26. font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  27. -webkit-tap-highlight-color: transparent;
  28. user-select: none;
  29. }
  30. body {
  31. background: #dfe6e9;
  32. width: 100%;
  33. height: 100vh;
  34. overflow: hidden;
  35. display: flex;
  36. flex-direction: column;
  37. }
  38. /* 顶部 Header - 冰雪主题背景 */
  39. .header-area {
  40. height: 210px;
  41. /* 使用冷蓝色渐变 */
  42. background: linear-gradient(to bottom, rgba(44, 62, 80, 0.8), rgba(52, 73, 94, 0.95)),
  43. url('./bg.jpg') center/cover;
  44. padding: 20px;
  45. padding-top: max(25px, env(safe-area-inset-top));
  46. color: white;
  47. border-bottom-left-radius: 30px; border-bottom-right-radius: 30px;
  48. position: relative; flex-shrink: 0;
  49. z-index: 1;
  50. }
  51. .nav-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; }
  52. .icon-btn {
  53. width: 32px; height: 32px; background: rgba(255,255,255,0.2); backdrop-filter: blur(5px);
  54. border-radius: 50%; display: flex; align-items: center; justify-content: center;
  55. cursor: pointer; border: 1px solid rgba(255,255,255,0.3); font-size: 14px;
  56. }
  57. .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); }
  58. /* 仪表盘卡片 */
  59. .dashboard-card {
  60. margin-top: 10px;
  61. background: rgba(255, 255, 255, 0.15);
  62. backdrop-filter: blur(10px);
  63. border-radius: 16px;
  64. padding: 10px 15px;
  65. border: 1px solid rgba(255, 255, 255, 0.2);
  66. box-shadow: 0 8px 20px rgba(0,0,0,0.1);
  67. position: relative;
  68. z-index: 5;
  69. }
  70. .dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
  71. .dash-title { font-size: 14px; font-weight: bold; display: flex; align-items: center; gap: 6px; color: #fff; }
  72. .dash-icon { color: var(--primary-orange); }
  73. .dash-badge { background: var(--primary-orange); color: #fff; 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;}
  74. .dash-badge.completed { background: linear-gradient(135deg, #00cec9, #0984e3); color: white; }
  75. .trophy-track-container { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 0 5px; }
  76. .track-line-bg { position: absolute; top: 50%; left: 10px; right: 10px; height: 3px; background: rgba(255,255,255,0.3); border-radius: 2px; transform: translateY(-50%); z-index: 0; }
  77. .track-line-active {
  78. position: absolute; top: 50%; left: 10px;
  79. width: 25%;
  80. height: 3px; background: var(--primary-orange); border-radius: 2px; transform: translateY(-50%); z-index: 0;
  81. box-shadow: 0 0 8px rgba(116, 185, 255, 0.8);
  82. transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  83. }
  84. .trophy-item {
  85. position: relative; z-index: 1; width: 28px; height: 28px;
  86. background: #636e72; border: 2px solid rgba(255,255,255,0.5); border-radius: 50%;
  87. display: flex; justify-content: center; align-items: center;
  88. color: #b2bec3; font-size: 10px;
  89. transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  90. }
  91. .trophy-item.active {
  92. background: #fff; border-color: var(--primary-orange); color: var(--primary-orange);
  93. transform: scale(1.15); box-shadow: 0 0 10px rgba(116, 185, 255, 0.6);
  94. }
  95. .trophy-item.final { width: 34px; height: 34px; border-color: rgba(255,255,255,0.7); font-size: 14px; }
  96. .trophy-item.final.active {
  97. background: linear-gradient(135deg, #74b9ff, #0984e3);
  98. color: white; border: none;
  99. transform: scale(1.3);
  100. box-shadow: 0 0 20px rgba(116, 185, 255, 0.8);
  101. animation: pulseTrophy 2s infinite;
  102. }
  103. @keyframes pulseTrophy {
  104. 0% { box-shadow: 0 0 0 0 rgba(116, 185, 255, 0.7); }
  105. 70% { box-shadow: 0 0 0 10px rgba(116, 185, 255, 0); }
  106. 100% { box-shadow: 0 0 0 0 rgba(116, 185, 255, 0); }
  107. }
  108. /* 领奖台 - 雪地风格 */
  109. .podium-wrap {
  110. height: 120px;
  111. display: flex; justify-content: center; align-items: flex-end;
  112. margin-top: -50px;
  113. position: relative;
  114. z-index: 10;
  115. padding-bottom: 0px;
  116. }
  117. .p-col { display: flex; flex-direction: column; align-items: center; width: 30%; position: relative;}
  118. .p-2 { z-index: 2; margin-right: -15px; }
  119. .p-1 { z-index: 3; }
  120. .p-3 { z-index: 1; margin-left: -15px; }
  121. .p-img { width: 44px; height: 44px; border-radius: 50%; border: 2px solid white; background: #eee; margin-bottom: -10px; position: relative; z-index: 2; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.2); }
  122. .p-1 .p-img { width: 60px; height: 60px; border-color: #74b9ff; margin-bottom: -12px;}
  123. .p-img img { width: 100%; height: 100%; object-fit: cover; }
  124. .crown {
  125. position: absolute; top: -24px; color: #f1c40f; font-size: 26px;
  126. filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
  127. animation: crownFloat 2s ease-in-out infinite;
  128. z-index: 20;
  129. }
  130. @keyframes crownFloat {
  131. 0%, 100% { transform: translateY(0) rotate(-5deg); }
  132. 50% { transform: translateY(-6px) rotate(5deg); }
  133. }
  134. .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.1); position: relative; overflow: hidden; }
  135. /* 增加雪顶效果 */
  136. .p-box::before {
  137. content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 10px;
  138. background: rgba(255,255,255,0.6);
  139. border-radius: 8px 8px 50% 50%;
  140. filter: blur(1px);
  141. }
  142. .p-1 .p-box { height: 76px; background: linear-gradient(180deg, #74b9ff, #0984e3); padding-top: 18px; }
  143. .p-2 .p-box { height: 60px; background: linear-gradient(180deg, #b2bec3, #636e72); }
  144. .p-3 .p-box { height: 50px; background: linear-gradient(180deg, #a29bfe, #6c5ce7); }
  145. .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;}
  146. .p-score { font-size: 13px; font-weight: bold; }
  147. /* 列表容器 */
  148. .list-container {
  149. flex: 1; background: white; border-radius: 24px 24px 0 0;
  150. padding: 0 20px 120px 20px;
  151. overflow-y: auto;
  152. margin-top: -10px;
  153. box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
  154. position: relative; z-index: 8;
  155. -webkit-overflow-scrolling: touch;
  156. }
  157. .tabs {
  158. display: flex; justify-content: center; gap: 15px;
  159. position: sticky; top: 0; background: white; z-index: 9;
  160. padding-top: 20px; padding-bottom: 10px;
  161. }
  162. .tab { padding: 8px 20px; border-radius: 20px; font-size: 14px; color: #636e72; background: #f1f2f6; cursor: pointer; transition: 0.2s; }
  163. .tab.active { background: var(--primary-purple); color: var(--primary-orange); font-weight: bold; }
  164. .list-item { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid #f1f2f6; }
  165. .rank { width: 30px; text-align: center; font-weight: bold; color: #b2bec3; font-style: italic;}
  166. .avatar { width: 40px; height: 40px; border-radius: 50%; margin: 0 12px; background: #eee; overflow: hidden;}
  167. .avatar img { width: 100%; height: 100%; object-fit: cover;}
  168. .info { flex: 1; }
  169. .name { font-size: 14px; color: #2d3436; font-weight: bold; }
  170. .team { font-size: 11px; color: #636e72; display: flex; align-items: center; gap: 4px; }
  171. .score { font-size: 16px; font-weight: bold; color: var(--primary-purple); }
  172. /* 底部我的排名 */
  173. .my-rank-bar {
  174. position: fixed; bottom: 0; left: 0; width: 100%;
  175. background: var(--footer-bg); color: white;
  176. display: flex; align-items: center;
  177. padding: 0 20px;
  178. padding-top: 8px;
  179. padding-bottom: calc(8px + constant(safe-area-inset-bottom));
  180. padding-bottom: calc(8px + env(safe-area-inset-bottom));
  181. box-sizing: border-box;
  182. border-radius: 24px 24px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); z-index: 99;
  183. }
  184. .my-rank-bar .rank { font-size: 16px; }
  185. .my-rank-bar .avatar { width: 34px; height: 34px; border-width: 2px; }
  186. .my-rank-bar .name { font-size: 14px; }
  187. .my-rank-bar .team { font-size: 10px; }
  188. .my-score { font-size: 18px; font-weight: bold; color: #74b9ff !important; margin-left: auto; }
  189. /* 演示按钮样式 (模态框内) */
  190. .demo-section {
  191. margin: 20px 0 0 0;
  192. border-top: 1px dashed #ddd;
  193. padding-top: 15px;
  194. }
  195. .demo-label { font-size: 12px; color: #999; margin-bottom: 10px; }
  196. .demo-controls {
  197. display: flex; justify-content: center; gap: 10px;
  198. }
  199. .demo-btn {
  200. background: #eee; border: none; padding: 6px 12px; border-radius: 8px; font-size: 12px; color: #555; cursor: pointer;
  201. }
  202. .demo-btn:active { background: #ddd; color: #000; }
  203. /* 下拉菜单 & 模态框 */
  204. .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; }
  205. .dropdown.show { display: flex; animation: dropIn 0.2s ease-out; }
  206. .dd-item { padding: 12px; color: #636e72; font-size: 14px; text-align: center; border-bottom: 1px solid #f1f2f6; cursor: pointer; }
  207. .dd-active { color: var(--primary-purple); font-weight: bold; background: #ecf0f1; }
  208. @keyframes dropIn { from{opacity:0; transform:translateX(-50%) translateY(-10px);} to{opacity:1; transform:translateX(-50%) translateY(0);} }
  209. .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; }
  210. .modal-mask.show { opacity: 1; pointer-events: auto; }
  211. .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); }
  212. .modal-mask.show .modal-body { transform: scale(1); }
  213. .m-close { background: var(--primary-purple); color: white; padding: 10px 25px; border-radius: 20px; border: none; font-weight: bold; cursor: pointer; margin-top: 15px; }
  214. .rule-box { text-align: left; background: #ecf0f1; border: 1px solid #dfe6e9; border-radius: 12px; padding: 12px; color: #2c3e50; font-size: 13px; line-height: 1.6; box-shadow: inset 0 1px 0 rgba(255,255,255,0.7); }
  215. .rule-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
  216. .rule-item:last-child { margin-bottom: 0; }
  217. .rule-item i { color: var(--primary-orange); margin-top: 2px; }
  218. /* 下雪 Canvas */
  219. #snowCanvas {
  220. position: fixed;
  221. top: 0;
  222. left: 0;
  223. width: 100%;
  224. height: 100%;
  225. pointer-events: none; /* 让点击事件穿透 */
  226. z-index: 9999;
  227. }
  228. /* iOS 专属优化 */
  229. @supports (-webkit-touch-callout: none) {
  230. .my-rank-bar {
  231. padding-top: 4px !important;
  232. padding-bottom: env(safe-area-inset-bottom) !important;
  233. }
  234. }
  235. .loading-mask {
  236. position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  237. display: none; align-items: center; justify-content: center;
  238. z-index: 300; color: #fff; font-size: 14px; backdrop-filter: blur(2px);
  239. }
  240. .loading-mask.show { display: none !important; }
  241. .loading-spinner {
  242. border: 4px solid rgba(255,255,255,0.3);
  243. border-top-color: #74b9ff;
  244. border-radius: 50%;
  245. width: 36px; height: 36px;
  246. animation: spin 1s linear infinite;
  247. margin-right: 10px;
  248. }
  249. @keyframes spin { to { transform: rotate(360deg); } }
  250. </style>
  251. </head>
  252. <body>
  253. <!-- 雪花画布 -->
  254. <canvas id="snowCanvas"></canvas>
  255. <!-- 头部 -->
  256. <div class="header-area">
  257. <div class="nav-bar">
  258. <div class="icon-btn" onclick="handleBack()"><i class="fa-solid fa-chevron-left" style="color:white"></i></div>
  259. <div class="month-select" onclick="toggleDropdown()">
  260. <span id="currentMonthText">12月挑战赛</span> <i class="fa-solid fa-caret-down"></i>
  261. </div>
  262. <div class="icon-btn" onclick="openModal()"><i class="fa-solid fa-question" style="color:white"></i></div>
  263. </div>
  264. <!-- 仪表盘卡片 -->
  265. <div class="dashboard-card">
  266. <div class="dash-header">
  267. <div class="dash-title">
  268. <i class="fa-solid fa-snowflake dash-icon"></i> 定向冰雪达人
  269. </div>
  270. <div class="dash-badge" id="dashBadge">挑战 1 / 4</div>
  271. </div>
  272. <div class="trophy-track-container">
  273. <div class="track-line-bg"></div>
  274. <div class="track-line-active" id="progressLine"></div>
  275. <!-- 图标1 -->
  276. <div class="trophy-item active" id="t1"><i class="fa-solid fa-check"></i></div>
  277. <!-- 图标2 -->
  278. <div class="trophy-item" id="t2"><i class="fa-solid fa-lock"></i></div>
  279. <!-- 图标3 -->
  280. <div class="trophy-item" id="t3"><i class="fa-solid fa-lock"></i></div>
  281. <!-- 图标4 (Final) -->
  282. <div class="trophy-item final" id="t4"><i class="fa-solid fa-trophy"></i></div>
  283. </div>
  284. </div>
  285. </div>
  286. <!-- 下拉菜单 -->
  287. <div class="dropdown" id="dropdown"></div>
  288. <!-- 领奖台 -->
  289. <div class="podium-wrap" id="podiumWrap"></div>
  290. <!-- 列表区 -->
  291. <div class="list-container">
  292. <div class="tabs">
  293. <div class="tab active" onclick="switchTab('score', this)">积分排行</div>
  294. <div class="tab" onclick="switchTab('venue', this)">场地排行</div>
  295. </div>
  296. <div id="rankList"></div>
  297. </div>
  298. <!-- 底部我的排名 -->
  299. <div class="my-rank-bar">
  300. <div class="rank" id="myRankNum">--</div>
  301. <div class="avatar" id="myAvatar" style="border:2px solid #74b9ff; overflow:hidden;"></div>
  302. <div class="info"><div class="name" id="myName" style="color:white">我</div><div class="team" id="myTeam" style="color:#b2bec3">正在加载...</div></div>
  303. <div class="my-score" id="myScoreValue">--</div>
  304. </div>
  305. <!-- 模态框 -->
  306. <div class="modal-mask" id="infoModal">
  307. <div class="modal-body">
  308. <h3 style="color:#2c3e50; margin-bottom:15px;">❄️ 冰雪规则说明</h3>
  309. <div id="ruleContent" class="rule-box">
  310. <div class="rule-item"><i class="fa-solid fa-snowflake"></i><div><strong>积分规则:</strong> 在指定公园找到打卡点,耗时越短积分越高。</div></div>
  311. <div class="rule-item"><i class="fa-solid fa-map-location-dot"></i><div><strong>场地排行:</strong> 按解锁的公园场地数量排名。</div></div>
  312. <div class="rule-item"><i class="fa-solid fa-trophy"></i><div><strong>奖杯获取:</strong> 完成4次有效挑战点亮全部奖杯。</div></div>
  313. </div>
  314. <!-- 演示功能区 -->
  315. <div class="demo-section">
  316. <div class="demo-label">✨ 功能演示</div>
  317. <div class="demo-controls">
  318. <button class="demo-btn" onclick="demoProgress(1);closeModal()">1/4</button>
  319. <button class="demo-btn" onclick="demoProgress(3);closeModal()">3/4</button>
  320. <button class="demo-btn" onclick="demoProgress(4);closeModal()">4/4</button>
  321. </div>
  322. </div>
  323. <button class="m-close" onclick="closeModal()">知道了</button>
  324. </div>
  325. </div>
  326. <!-- 加载中遮罩 -->
  327. <div class="loading-mask" id="loadingMask" style="display: none !important;">
  328. <div class="loading-spinner"></div>
  329. <div>数据加载中...</div>
  330. </div>
  331. <script>
  332. // --- 下雪动画脚本 ---
  333. (function() {
  334. var canvas = document.getElementById('snowCanvas');
  335. var ctx = canvas.getContext('2d');
  336. var width = window.innerWidth;
  337. var height = window.innerHeight;
  338. canvas.width = width;
  339. canvas.height = height;
  340. var maxFlakes = 150; // 雪花数量
  341. var flakes = [];
  342. // 初始化雪花
  343. for (var i = 0; i < maxFlakes; i++) {
  344. flakes.push({
  345. x: Math.random() * width,
  346. y: Math.random() * height,
  347. r: Math.random() * 3 + 1, // 半径
  348. d: Math.random() * maxFlakes, // 密度因子
  349. a: Math.random() // 透明度
  350. });
  351. }
  352. function drawFlakes() {
  353. ctx.clearRect(0, 0, width, height);
  354. ctx.fillStyle = "rgba(255, 255, 255, 0.8)";
  355. ctx.beginPath();
  356. for (var i = 0; i < maxFlakes; i++) {
  357. var f = flakes[i];
  358. ctx.moveTo(f.x, f.y);
  359. ctx.arc(f.x, f.y, f.r, 0, Math.PI * 2, true);
  360. }
  361. ctx.fill();
  362. moveFlakes();
  363. }
  364. var angle = 0;
  365. function moveFlakes() {
  366. angle += 0.01;
  367. for (var i = 0; i < maxFlakes; i++) {
  368. var f = flakes[i];
  369. // 更新坐标
  370. f.y += Math.pow(f.d, 2) * 0.0005 + 1; // 下落速度
  371. f.x += Math.sin(angle + f.d) * 0.5; // 左右摇摆
  372. // 如果雪花超出屏幕底部,重置到顶部
  373. if (f.y > height) {
  374. flakes[i] = { x: Math.random() * width, y: 0, r: f.r, d: f.d, a: f.a };
  375. }
  376. // 如果雪花超出屏幕左右,从另一侧出现
  377. if (f.x > width) f.x = 0;
  378. if (f.x < 0) f.x = width;
  379. }
  380. }
  381. function animate() {
  382. drawFlakes();
  383. requestAnimationFrame(animate);
  384. }
  385. // 窗口大小改变时重置画布
  386. window.addEventListener('resize', function() {
  387. width = window.innerWidth;
  388. height = window.innerHeight;
  389. canvas.width = width;
  390. canvas.height = height;
  391. });
  392. animate();
  393. })();
  394. // --- 业务逻辑脚本 (保持原有的逻辑) ---
  395. const dropdown = document.getElementById('dropdown');
  396. const rankListEl = document.getElementById('rankList');
  397. const trackLine = document.getElementById('progressLine');
  398. const podiumWrap = document.getElementById('podiumWrap');
  399. const ruleContent = document.getElementById('ruleContent');
  400. const loadingMask = document.getElementById('loadingMask');
  401. const state = {
  402. activeTab: 'score',
  403. scoreList: [],
  404. scoreListRendered: null,
  405. venueList: [],
  406. venueListRendered: null,
  407. months: [],
  408. currentYM: null,
  409. currentMonthData: null,
  410. allMonthsData: null
  411. };
  412. const Logger = {
  413. _isDev: false,
  414. init: function(isDev) { this._isDev = isDev; },
  415. log: function() { if (this._isDev) console.log.apply(console, arguments); },
  416. warn: function() { if (this._isDev) console.warn.apply(console, arguments); },
  417. error: function() { console.error.apply(console, arguments); }
  418. };
  419. function getQuery(name) {
  420. const params = new URLSearchParams(window.location.search);
  421. return params.get(name);
  422. }
  423. function getYearMonth() {
  424. const now = new Date();
  425. const year = parseInt(getQuery('year'), 10) || now.getFullYear();
  426. const month = parseInt(getQuery('month'), 10) || (now.getMonth() + 1);
  427. return { year: year, month: month };
  428. }
  429. function getRecentMonths(count) {
  430. const ym = getYearMonth();
  431. const list = [];
  432. let y = ym.year;
  433. let m = ym.month;
  434. for (let i = 0; i < (count || 3); i++) {
  435. list.push({ year: y, month: m });
  436. m -= 1;
  437. if (m === 0) { m = 12; y -= 1; }
  438. }
  439. return list;
  440. }
  441. function handleBack() {
  442. if (window.Bridge && Bridge.toHome) Bridge.toHome();
  443. else window.history.back();
  444. }
  445. function openModal() { document.getElementById('infoModal').classList.add('show'); }
  446. function closeModal() { document.getElementById('infoModal').classList.remove('show'); }
  447. function toggleDropdown() { dropdown.style.display = (dropdown.style.display === 'flex') ? 'none' : 'flex'; }
  448. function setLoading(isLoading) {
  449. rankListEl.style.opacity = isLoading ? '0.4' : '1';
  450. loadingMask.classList.toggle('show', isLoading);
  451. }
  452. function buildAvatar(name, salt) {
  453. const seedBase = name || 'user';
  454. const seed = seedBase + (salt || '');
  455. return multiavatar(seed);
  456. }
  457. function setProgress(real, target) {
  458. const badge = document.getElementById('dashBadge');
  459. const t1 = document.getElementById('t1');
  460. const t2 = document.getElementById('t2');
  461. const t3 = document.getElementById('t3');
  462. const t4 = document.getElementById('t4');
  463. const safeReal = Math.max(real || 0, 0);
  464. const safeTarget = target && target > 0 ? target : 4;
  465. const ratio = Math.min(safeReal / safeTarget, 1);
  466. const percent = Math.max(0, Math.min(1, ratio)) * 100;
  467. trackLine.style.width = percent + '%';
  468. const textReal = safeReal >= safeTarget ? safeTarget : safeReal;
  469. badge.innerText = safeReal >= safeTarget ? '挑战成功' : `挑战 ${textReal} / ${safeTarget}`;
  470. badge.classList.toggle('completed', safeReal >= safeTarget);
  471. function setIconActive(el, active) {
  472. if (active) {
  473. el.classList.add('active');
  474. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-check"></i>';
  475. } else {
  476. el.classList.remove('active');
  477. if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-lock"></i>';
  478. }
  479. }
  480. setIconActive(t1, safeReal >= 1);
  481. setIconActive(t2, safeReal >= 2);
  482. setIconActive(t3, safeReal >= 3);
  483. setIconActive(t4, safeReal >= safeTarget);
  484. }
  485. function renderBadge(real, target) {
  486. setProgress(real, target);
  487. }
  488. function findMonthProgress(year, month, currentMonthData, allMonthsData) {
  489. const result = { realNum: 0, targetNum: 4 };
  490. const pick = (arr) => {
  491. if (!arr || !arr.length) return null;
  492. for (let i = 0; i < arr.length; i++) {
  493. if (Number(arr[i].month) === Number(month)) return arr[i];
  494. }
  495. return null;
  496. };
  497. const fromCurrent = currentMonthData && pick(currentMonthData.monthRs || []);
  498. if (fromCurrent) return { realNum: fromCurrent.realNum || 0, targetNum: fromCurrent.targetNum || 4 };
  499. if (allMonthsData && allMonthsData.length) {
  500. for (let i = 0; i < allMonthsData.length; i++) {
  501. const item = allMonthsData[i];
  502. if (item.year && Number(item.year) !== Number(year)) continue;
  503. const found = pick(item.monthRs || []);
  504. if (found) return { realNum: found.realNum || 0, targetNum: found.targetNum || 4 };
  505. }
  506. }
  507. return result;
  508. }
  509. function renderMonths(list) {
  510. dropdown.innerHTML = '';
  511. if (!list || list.length === 0) {
  512. dropdown.innerHTML = '<div class="dd-item">暂无月份数据</div>';
  513. return;
  514. }
  515. list.forEach((item, idx) => {
  516. const title = `${item.month}月挑战赛`;
  517. const div = document.createElement('div');
  518. const isCurrent = state.currentYM && state.currentYM.year === item.year && state.currentYM.month === item.month;
  519. div.className = 'dd-item' + (isCurrent ? ' dd-active' : '');
  520. div.innerText = (idx === 0 && !isCurrent) ? `${title} (本月)` : title;
  521. div.onclick = () => {
  522. selectMonth(item.year, item.month, title);
  523. };
  524. dropdown.appendChild(div);
  525. });
  526. }
  527. function renderPodium(list, tabType) {
  528. const type = tabType || state.activeTab || 'score';
  529. podiumWrap.innerHTML = '';
  530. const podiumData = Array(3).fill(null);
  531. if (list && list.length > 0) {
  532. list.slice(0, 3).forEach((item, index) => {
  533. podiumData[index] = item;
  534. });
  535. }
  536. const p1 = podiumData[0];
  537. const p2 = podiumData[1];
  538. const p3 = podiumData[2];
  539. const podiumItems = [
  540. { person: p2, className: 'p-2' },
  541. { person: p1, className: 'p-1' },
  542. { person: p3, className: 'p-3' }
  543. ];
  544. podiumItems.forEach(itemConfig => {
  545. const person = itemConfig.person;
  546. const col = document.createElement('div');
  547. col.className = 'p-col ' + itemConfig.className;
  548. const name = person ? (person.nickName || person.name || person.userName) : '虚位以待';
  549. const score = person ? (person.score != null ? person.score : (person.inRankNum != null ? person.inRankNum : '')) : '';
  550. 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>';
  551. const isActualFirst = (person === p1 && p1 !== null);
  552. col.innerHTML = `
  553. ${isActualFirst ? '<div class="crown"><i class="fa-solid fa-crown"></i></div>' : ''}
  554. <div class="p-img">${avatarContent}</div>
  555. <div class="p-box">
  556. <div class="p-name">${name}</div>
  557. <div class="p-score">${score}</div>
  558. </div>
  559. `;
  560. podiumWrap.appendChild(col);
  561. });
  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. document.querySelector('.my-rank-bar').onclick = null;
  612. }
  613. function renderGuestState() {
  614. const rankNumEl = document.getElementById('myRankNum');
  615. const myScoreEl = document.getElementById('myScoreValue');
  616. const myNameEl = document.getElementById('myName');
  617. const myTeamEl = document.getElementById('myTeam');
  618. const myAvatarEl = document.getElementById('myAvatar');
  619. const myRankBar = document.querySelector('.my-rank-bar');
  620. rankNumEl.innerText = '--';
  621. myScoreEl.innerText = '';
  622. myNameEl.innerText = '您还未登录';
  623. myTeamEl.innerText = '点击去登录';
  624. myTeamEl.style.color = '#74b9ff';
  625. const randomSeed = 'guest_' + Math.floor(Math.random() * 10000);
  626. myAvatarEl.innerHTML = buildAvatar('Guest', randomSeed);
  627. myRankBar.onclick = function() {
  628. if (window.Bridge && Bridge.toLogin) {
  629. Bridge.toLogin();
  630. }
  631. };
  632. }
  633. function renderRules(config) {
  634. if (!config || !config.configJson) return;
  635. try {
  636. const parsed = JSON.parse(config.configJson);
  637. const rules = parsed.popupRuleList || [];
  638. if (rules.length > 0 && rules[0].data && rules[0].data.content) {
  639. ruleContent.innerHTML = rules[0].data.content;
  640. }
  641. } catch (err) {
  642. Logger.warn('[Rule] parse error', err);
  643. }
  644. }
  645. function switchTab(type, tabElement) {
  646. state.activeTab = type;
  647. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  648. if (tabElement) tabElement.classList.add('active');
  649. const baseList = type === 'venue' ? state.venueList : state.scoreList;
  650. renderPodium(baseList, type);
  651. const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
  652. renderRankList(rendered);
  653. }
  654. function demoProgress(step) {
  655. setProgress(step, 4);
  656. }
  657. async function loadMonthData(year, month) {
  658. state.currentYM = { year: year, month: month };
  659. document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
  660. renderMonths(state.months);
  661. setLoading(true);
  662. try {
  663. const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  664. const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  665. const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  666. state.scoreList = monthGrad;
  667. state.venueList = monthMap;
  668. const prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
  669. renderBadge(prog.realNum, prog.targetNum);
  670. renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
  671. switchTab(state.activeTab, document.querySelector('.tab.active'));
  672. } catch (err) {
  673. Logger.error('[Month] 加载失败', err);
  674. rankListEl.innerHTML = '<div style="padding:20px; color:#ff7675;">数据加载失败,请重试</div>';
  675. } finally {
  676. setLoading(false);
  677. }
  678. }
  679. function selectMonth(year, month, title) {
  680. dropdown.style.display = 'none';
  681. loadMonthData(year, month);
  682. }
  683. async function initPage() {
  684. if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
  685. document.body.classList.add('platform-ios');
  686. }
  687. const ecId = getQuery('ecId') || '4';
  688. const token = getQuery('token');
  689. let baseUrl = getQuery('baseUrl') || undefined;
  690. const env = (getQuery('env') || '').toLowerCase();
  691. const useMock = env === 'mock';
  692. Logger.init(useMock);
  693. const ym = getYearMonth();
  694. state.months = getRecentMonths(6);
  695. if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
  696. if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
  697. API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
  698. const allowLogin = !useMock && token;
  699. renderMonths(state.months);
  700. setLoading(true);
  701. async function safeCall(promiseFactory) {
  702. try { return await promiseFactory(); }
  703. catch (err) { Logger.warn('[Optional API] ignore error', err); return null; }
  704. }
  705. async function fetchMonthData(year, month) {
  706. return await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
  707. }
  708. try {
  709. let targetYM = { year: ym.year, month: ym.month };
  710. let monthRank = await fetchMonthData(targetYM.year, targetYM.month);
  711. let monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
  712. let monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
  713. let hasData = monthGrad.length > 0 || monthMap.length > 0;
  714. if (!hasData) {
  715. for (let i = 1; i < state.months.length; i++) {
  716. const checkYM = state.months[i];
  717. const checkRank = await fetchMonthData(checkYM.year, checkYM.month);
  718. const checkGrad = checkRank && checkRank.gradRs ? checkRank.gradRs : [];
  719. const checkMap = checkRank && checkRank.mapNumRs ? checkRank.mapNumRs : [];
  720. if (checkGrad.length > 0 || checkMap.length > 0) {
  721. targetYM = checkYM;
  722. monthRank = checkRank;
  723. monthGrad = checkGrad;
  724. monthMap = checkMap;
  725. hasData = true;
  726. break;
  727. }
  728. }
  729. }
  730. state.currentYM = targetYM;
  731. state.scoreList = monthGrad;
  732. state.venueList = monthMap;
  733. let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
  734. if (useMock || allowLogin) {
  735. [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
  736. safeCall(() => API.getCardBase(ecId, 'rank')),
  737. safeCall(() => API.request('CurrentMonthlyChallengeQuery', { ecId: ecId })),
  738. safeCall(() => API.getMonthlyChallenge()),
  739. safeCall(() => API.getUserCurrentRank(ecId)),
  740. safeCall(() => API.getScore(ecId)),
  741. safeCall(() => API.getUserInfo()),
  742. safeCall(() => API.getCardConfig(ecId, 'rank'))
  743. ]);
  744. } else {
  745. base = { ecName: `${targetYM.month}月挑战赛` };
  746. currentMonth = { monthRs: [{ month: targetYM.month, realNum: 0, targetNum: 4 }] };
  747. allMonths = [];
  748. myRank = null;
  749. myScore = null;
  750. userInfo = null;
  751. cardConfig = null;
  752. }
  753. const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
  754. if (!base && monthGrad.length) base = { ecName: `${targetYM.month}月挑战赛` };
  755. state.currentMonthData = currentMonth || null;
  756. state.allMonthsData = allMonths || null;
  757. const prog = findMonthProgress(targetYM.year, targetYM.month, state.currentMonthData, state.allMonthsData);
  758. document.getElementById('currentMonthText').innerText = `${targetYM.month}月挑战赛`;
  759. renderMonths(state.months);
  760. renderBadge(prog.realNum, prog.targetNum);
  761. renderPodium(state.scoreList, 'score');
  762. switchTab(state.activeTab, document.querySelector('.tab.active'));
  763. if (!token && !useMock) {
  764. renderGuestState();
  765. } else {
  766. let hasRenderedMyInfo = false;
  767. if (allowLogin && myRank) {
  768. const rankVal = Number(myRank.rankNum);
  769. if (rankVal > 0) {
  770. renderMyInfo({ rankNum: rankVal }, myScore, userInfo);
  771. } else {
  772. renderMyInfo({ rankNum: null }, null, userInfo);
  773. }
  774. hasRenderedMyInfo = true;
  775. } else if (selfRow) {
  776. renderMyInfo({ rankNum: selfRow.rankNum }, { score: selfRow.inRankNum || selfRow.score }, { nickName: selfRow.userName });
  777. hasRenderedMyInfo = true;
  778. }
  779. if (!hasRenderedMyInfo) {
  780. renderMyInfo(myRank, myScore, userInfo);
  781. }
  782. }
  783. renderRules(cardConfig);
  784. } finally {
  785. setLoading(false);
  786. loadingMask.classList.remove('show');
  787. }
  788. }
  789. document.addEventListener('click', (e) => {
  790. if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
  791. });
  792. document.addEventListener('DOMContentLoaded', initPage);
  793. </script>
  794. </body>
  795. </html>