detail-windy.html 43 KB

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