detail-rain.html 43 KB

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