detail-cloud.html 40 KB

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