| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
- <title>月挑战赛</title>
- <!-- 本地调试保留 mock_flutter.js,正式接入时移除 -->
- <!-- <script src="./mock_flutter.js"></script> -->
- <script src="./bridge.js"></script>
- <script src="./api.js"></script>
- <script src="./js/multiavatar.min.js"></script>
- <link href="./css/all.min.css" rel="stylesheet">
- <style>
- :root {
- --primary-purple: #593259;
- --primary-orange: #fdcb6e;
- --primary-red: #d63031;
- --text-dark: #2d3436;
- --footer-bg: #483055;
- }
- * {
- box-sizing: border-box;
- margin: 0;
- padding: 0;
- font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
- -webkit-tap-highlight-color: transparent;
- user-select: none;
- }
- body {
- background: #f5f6fa;
- width: 100%;
- height: 100vh;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- }
- /* 顶部 Header */
- .header-area {
- height: 210px;
- background: linear-gradient(to bottom, rgba(72, 48, 85, 0.7), rgba(45, 52, 54, 0.95)),
- url('./bg.jpg') center/cover;
- padding: 20px;
- padding-top: max(25px, env(safe-area-inset-top));
- color: white;
- border-bottom-left-radius: 30px; border-bottom-right-radius: 30px;
- position: relative; flex-shrink: 0;
- z-index: 1;
- }
- .nav-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 5px; }
- .icon-btn {
- width: 32px; height: 32px; background: rgba(255,255,255,0.2); backdrop-filter: blur(5px);
- border-radius: 50%; display: flex; align-items: center; justify-content: center;
- cursor: pointer; border: 1px solid rgba(255,255,255,0.3); font-size: 14px;
- }
- .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); }
- /* 仪表盘卡片 */
- .dashboard-card {
- margin-top: 10px;
- background: rgba(0, 0, 0, 0.4);
- backdrop-filter: blur(10px);
- border-radius: 16px;
- padding: 10px 15px;
- border: 1px solid rgba(255, 255, 255, 0.1);
- box-shadow: 0 8px 20px rgba(0,0,0,0.2);
- position: relative;
- z-index: 5;
- }
- .dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
- .dash-title { font-size: 14px; font-weight: bold; display: flex; align-items: center; gap: 6px; color: #fff; }
- .dash-icon { color: var(--primary-orange); }
- .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;}
-
- .dash-badge.completed { background: linear-gradient(135deg, #55efc4, #00b894); color: white; }
- .trophy-track-container { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 0 5px; }
-
- .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; }
-
- .track-line-active {
- position: absolute; top: 50%; left: 10px;
- width: 25%;
- height: 3px; background: var(--primary-orange); border-radius: 2px; transform: translateY(-50%); z-index: 0;
- box-shadow: 0 0 8px rgba(253, 203, 110, 0.6);
- transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
- }
- .trophy-item {
- position: relative; z-index: 1; width: 28px; height: 28px;
- background: #2d3436; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%;
- display: flex; justify-content: center; align-items: center;
- color: #636e72; font-size: 10px;
- transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
- }
-
- .trophy-item.active {
- background: #fff; border-color: var(--primary-orange); color: var(--primary-orange);
- transform: scale(1.15); box-shadow: 0 0 10px rgba(253, 203, 110, 0.5);
- }
- .trophy-item.final { width: 34px; height: 34px; border-color: rgba(255,255,255,0.5); font-size: 14px; }
-
- .trophy-item.final.active {
- background: linear-gradient(135deg, #f1c40f, #e67e22);
- color: white; border: none;
- transform: scale(1.3);
- box-shadow: 0 0 20px rgba(241, 196, 15, 0.6);
- animation: pulseTrophy 2s infinite;
- }
- @keyframes pulseTrophy {
- 0% { box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.7); }
- 70% { box-shadow: 0 0 0 10px rgba(241, 196, 15, 0); }
- 100% { box-shadow: 0 0 0 0 rgba(241, 196, 15, 0); }
- }
- /* 领奖台 */
- .podium-wrap {
- height: 120px;
- display: flex; justify-content: center; align-items: flex-end;
- margin-top: -50px;
- position: relative;
- z-index: 10;
- padding-bottom: 0px;
- }
- .p-col { display: flex; flex-direction: column; align-items: center; width: 30%; position: relative;}
- .p-2 { z-index: 2; margin-right: -15px; }
- .p-1 { z-index: 3; }
- .p-3 { z-index: 1; margin-left: -15px; }
-
- /* Christmas Update: Podium Avatar */
- .p-img { width: 44px; height: 44px; border-radius: 50%; border: 2px solid white; background: #eee; margin-bottom: -10px; position: relative; z-index: 2; overflow: visible; box-shadow: 0 4px 6px rgba(0,0,0,0.2);}
- .p-1 .p-img { width: 60px; height: 60px; border-color: #f1c40f; margin-bottom: -12px;}
- /* Ensure inner image/svg is clipped */
- .p-img > svg, .p-img > img { width: 100%; height: 100%; border-radius: 50%; overflow: hidden; display: block; object-fit: cover; }
-
- /* Podium Party Popper */
- .p-img::after {
- content: '🎉';
- position: absolute;
- top: -14px;
- right: -8px;
- font-size: 24px;
- transform: rotate(-15deg);
- z-index: 20;
- pointer-events: none;
- filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
- }
- /* Larger hat for 1st place */
- .p-1 .p-img::after {
- font-size: 32px;
- top: -20px;
- right: -10px;
- }
- .crown {
- position: absolute; top: -24px; color: #f1c40f; font-size: 26px;
- filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
- animation: crownFloat 2s ease-in-out infinite;
- z-index: 20;
- }
- @keyframes crownFloat {
- 0%, 100% { transform: translateY(0) rotate(-5deg); }
- 50% { transform: translateY(-6px) rotate(5deg); }
- }
- .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); }
- .p-1 .p-box { height: 76px; background: linear-gradient(180deg, #f1c40f, #f39c12); padding-top: 18px; }
- .p-2 .p-box { height: 60px; background: linear-gradient(180deg, #bdc3c7, #95a5a6); }
- .p-3 .p-box { height: 50px; background: linear-gradient(180deg, #e67e22, #d35400); }
- .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;}
- .p-score { font-size: 13px; font-weight: bold; }
- /* 列表容器 */
- .list-container {
- flex: 1; background: white; border-radius: 24px 24px 0 0;
- padding: 0 20px 120px 20px;
- overflow-y: auto;
- margin-top: -10px;
- box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
- position: relative; z-index: 8;
- -webkit-overflow-scrolling: touch;
- }
-
- .tabs {
- display: flex; justify-content: center; gap: 15px;
- position: sticky; top: 0; background: white; z-index: 9;
- padding-top: 20px; padding-bottom: 10px;
- }
-
- .tab { padding: 8px 20px; border-radius: 20px; font-size: 14px; color: #636e72; background: #f1f2f6; cursor: pointer; transition: 0.2s; }
- .tab.active { background: var(--text-dark); color: #fdcb6e; font-weight: bold; }
-
- .list-item { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid #f1f2f6; }
- .rank { width: 30px; text-align: center; font-weight: bold; color: #b2bec3; font-style: italic;}
-
- /* Christmas Update: Avatar styling */
- .avatar { width: 40px; height: 40px; margin: 0 12px; background: transparent; position: relative; z-index: 1; overflow: visible; }
- .avatar > svg, .avatar > img { width: 100%; height: 100%; border-radius: 50%; background: #eee; display: block; }
- /* New Year Party Popper Overlay */
- .avatar::after {
- content: '🎉';
- position: absolute;
- top: -13px;
- right: -8px;
- font-size: 22px;
- transform: rotate(-15deg);
- z-index: 10;
- pointer-events: none;
- filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
- }
-
- .info { flex: 1; }
- .name { font-size: 14px; color: #2d3436; font-weight: bold; }
- .team { font-size: 11px; color: #636e72; display: flex; align-items: center; gap: 4px; }
- .score { font-size: 16px; font-weight: bold; color: var(--primary-purple); }
- /* 底部我的排名 */
- .my-rank-bar {
- position: fixed; bottom: 0; left: 0; width: 100%;
- /* 移除固定高度,改用 padding 撑开,更灵活且紧凑 */
- background: var(--footer-bg); color: white;
- display: flex; align-items: center;
- padding: 0 20px;
-
- /* 上下留出 8px 间距 */
- padding-top: 8px;
- /* 底部间距 = 8px + constant(safe-area-inset-bottom) 用于兼容旧版 iOS */
- padding-bottom: calc(8px + constant(safe-area-inset-bottom));
- /* 底部间距 = 8px + 安全区高度 */
- padding-bottom: calc(8px + env(safe-area-inset-bottom));
-
- box-sizing: border-box;
-
- border-radius: 24px 24px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); z-index: 99;
- }
- .my-rank-bar .rank { font-size: 16px; }
- .my-rank-bar .avatar { width: 34px; height: 34px; border-width: 2px; }
- .my-rank-bar .name { font-size: 14px; }
- .my-rank-bar .team { font-size: 10px; }
- .my-score { font-size: 18px; font-weight: bold; color: #ffffff !important; margin-left: auto; }
- /* 演示按钮样式 (模态框内) */
- .demo-section {
- margin: 20px 0 0 0;
- border-top: 1px dashed #ddd;
- padding-top: 15px;
- }
- .demo-label { font-size: 12px; color: #999; margin-bottom: 10px; }
- .demo-controls {
- display: flex; justify-content: center; gap: 10px;
- }
- .demo-btn {
- background: #eee; border: none; padding: 6px 12px; border-radius: 8px; font-size: 12px; color: #555; cursor: pointer;
- }
- .demo-btn:active { background: #ddd; color: #000; }
- /* 下拉菜单 & 模态框 */
- .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; }
- .dropdown.show { display: flex; animation: dropIn 0.2s ease-out; }
- .dd-item { padding: 12px; color: #636e72; font-size: 14px; text-align: center; border-bottom: 1px solid #f1f2f6; cursor: pointer; }
- .dd-active { color: var(--primary-purple); font-weight: bold; background: #f9f0ff; }
- @keyframes dropIn { from{opacity:0; transform:translateX(-50%) translateY(-10px);} to{opacity:1; transform:translateX(-50%) translateY(0);} }
- .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; }
- .modal-mask.show { opacity: 1; pointer-events: auto; }
- .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); }
- .modal-mask.show .modal-body { transform: scale(1); }
- .m-close { background: var(--primary-purple); color: white; padding: 10px 25px; border-radius: 20px; border: none; font-weight: bold; cursor: pointer; margin-top: 15px; }
- .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); }
- .rule-item { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
- .rule-item:last-child { margin-bottom: 0; }
- .rule-item i { color: var(--primary-orange); margin-top: 2px; }
- .my-rank-bar {
- position: fixed; bottom: 0; left: 0; width: 100%;
- background: var(--footer-bg); color: white;
- display: flex; align-items: center;
- padding: 0 20px;
-
- /* Android / 默认: 稍大一点的间距以防贴边 */
- padding-top: 6px;
- padding-bottom: 10px;
-
- box-sizing: border-box;
- border-radius: 24px 24px 0 0; box-shadow: 0 -5px 20px rgba(0,0,0,0.2); z-index: 99;
- }
- /* iOS 专属优化: 极致压缩高度 */
- @supports (-webkit-touch-callout: none) {
- .my-rank-bar {
- /* 顶部仅留 4px */
- padding-top: 4px !important;
- /* 底部严格贴合安全区,不加任何额外间距 */
- padding-bottom: env(safe-area-inset-bottom) !important;
- }
- }
- .my-rank-bar .rank { font-size: 16px; }
- /* 稍微缩小底部头像以节省高度 */
- .my-rank-bar .avatar { width: 30px; height: 30px; border-width: 2px; }
- .my-rank-bar .name { font-size: 14px; }
-
- .loading-mask {
- position: fixed; inset: 0; background: rgba(0,0,0,0.35);
- display: none; align-items: center; justify-content: center;
- z-index: 300; color: #fff; font-size: 14px; backdrop-filter: blur(2px);
- }
- .loading-mask.show { display: none !important; }
- .loading-spinner {
- border: 4px solid rgba(255,255,255,0.3);
- border-top-color: #fdcb6e;
- border-radius: 50%;
- width: 36px; height: 36px;
- animation: spin 1s linear infinite;
- margin-right: 10px;
- }
- @keyframes spin { to { transform: rotate(360deg); } }
- </style>
- </head>
- <body>
- <!-- New Year Confetti Effect Canvas -->
- <canvas id="confettiCanvas" style="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;"></canvas>
- <!-- 头部 -->
- <div class="header-area">
- <div class="nav-bar">
- <div class="icon-btn" onclick="handleBack()"><i class="fa-solid fa-chevron-left" style="color:white"></i></div>
- <div class="month-select" onclick="toggleDropdown()">
- <span id="currentMonthText">11月挑战赛</span> <i class="fa-solid fa-caret-down"></i>
- </div>
- <div class="icon-btn" onclick="openModal()"><i class="fa-solid fa-question" style="color:white"></i></div>
- </div>
- <!-- 仪表盘卡片 -->
- <div class="dashboard-card">
- <div class="dash-header">
- <div class="dash-title">
- <i class="fa-solid fa-medal dash-icon"></i> 定向达人
- </div>
- <div class="dash-badge" id="dashBadge">挑战 1 / 4</div>
- </div>
- <div class="trophy-track-container">
- <div class="track-line-bg"></div>
- <div class="track-line-active" id="progressLine"></div>
-
- <!-- 图标1 -->
- <div class="trophy-item active" id="t1"><i class="fa-solid fa-check"></i></div>
- <!-- 图标2 -->
- <div class="trophy-item" id="t2"><i class="fa-solid fa-lock"></i></div>
- <!-- 图标3 -->
- <div class="trophy-item" id="t3"><i class="fa-solid fa-lock"></i></div>
- <!-- 图标4 (Final) -->
- <div class="trophy-item final" id="t4"><i class="fa-solid fa-trophy"></i></div>
- </div>
- </div>
- </div>
- <!-- 下拉菜单 -->
- <div class="dropdown" id="dropdown"></div>
- <!-- 领奖台 -->
- <div class="podium-wrap" id="podiumWrap"></div>
- <!-- 列表区 -->
- <div class="list-container">
- <div class="tabs">
- <div class="tab active" onclick="switchTab('score', this)">积分排行</div>
- <div class="tab" onclick="switchTab('venue', this)">场地排行</div>
- </div>
-
- <div id="rankList"></div>
- </div>
- <!-- 底部我的排名 -->
- <div class="my-rank-bar">
- <div class="rank" id="myRankNum">--</div>
- <div class="avatar" id="myAvatar" style="border:2px solid #fdcb6e; overflow:hidden;"></div>
- <div class="info"><div class="name" id="myName" style="color:white">我</div><div class="team" id="myTeam" style="color:#b2bec3">正在加载...</div></div>
- <div class="my-score" id="myScoreValue">--</div>
- </div>
- <!-- 模态框 -->
- <div class="modal-mask" id="infoModal">
- <div class="modal-body">
- <h3 style="color:#593259; margin-bottom:15px;">📜 规则说明</h3>
- <div id="ruleContent" class="rule-box">
- <div class="rule-item"><i class="fa-solid fa-bullseye"></i><div><strong>积分规则:</strong> 在指定公园找到打卡点,耗时越短积分越高。</div></div>
- <div class="rule-item"><i class="fa-solid fa-map-location-dot"></i><div><strong>场地排行:</strong> 按解锁的公园场地数量排名。</div></div>
- <div class="rule-item"><i class="fa-solid fa-trophy"></i><div><strong>奖杯获取:</strong> 完成4次有效挑战点亮全部奖杯。</div></div>
- </div>
- <!-- 演示功能区 -->
- <div class="demo-section">
- <div class="demo-label">✨ 功能演示</div>
- <div class="demo-controls">
- <button class="demo-btn" onclick="demoProgress(1);closeModal()">1/4</button>
- <button class="demo-btn" onclick="demoProgress(3);closeModal()">3/4</button>
- <button class="demo-btn" onclick="demoProgress(4);closeModal()">4/4</button>
- </div>
- </div>
- <button class="m-close" onclick="closeModal()">知道了</button>
- </div>
- </div>
- <!-- 加载中遮罩 -->
- <div class="loading-mask" id="loadingMask" style="display: none !important;">
- <div class="loading-spinner"></div>
- <div>数据加载中...</div>
- </div>
- <script>
- const dropdown = document.getElementById('dropdown');
- const rankListEl = document.getElementById('rankList');
- const trackLine = document.getElementById('progressLine');
- const podiumWrap = document.getElementById('podiumWrap');
- const ruleContent = document.getElementById('ruleContent');
- const loadingMask = document.getElementById('loadingMask');
- const state = {
- activeTab: 'score',
- scoreList: [],
- scoreListRendered: null,
- venueList: [],
- venueListRendered: null,
- months: [],
- currentYM: null,
- currentMonthData: null,
- allMonthsData: null
- };
- // Logger Utility
- const Logger = {
- _isDev: false, // Will be set by initPage based on useMock
- init: function(isDev) {
- this._isDev = isDev;
- },
- log: function() {
- if (this._isDev) {
- console.log.apply(console, arguments);
- }
- },
- warn: function() {
- if (this._isDev) {
- console.warn.apply(console, arguments);
- }
- },
- error: function() {
- // Always log errors, regardless of dev mode
- console.error.apply(console, arguments);
- }
- };
- function getQuery(name) {
- const params = new URLSearchParams(window.location.search);
- return params.get(name);
- }
- function getYearMonth() {
- const now = new Date();
- const year = parseInt(getQuery('year'), 10) || now.getFullYear();
- const month = parseInt(getQuery('month'), 10) || (now.getMonth() + 1);
- return { year: year, month: month };
- }
-
- function getRecentMonths(count) {
- const ym = getYearMonth();
- const list = [];
- let y = ym.year;
- let m = ym.month;
- for (let i = 0; i < (count || 3); i++) {
- list.push({ year: y, month: m });
- m -= 1;
- if (m === 0) { m = 12; y -= 1; }
- }
- return list;
- }
- function handleBack() {
- if (window.Bridge && Bridge.toHome) Bridge.toHome();
- else window.history.back(); // Fallback for web environment
- }
- function openModal() { document.getElementById('infoModal').classList.add('show'); }
- function closeModal() { document.getElementById('infoModal').classList.remove('show'); }
- function toggleDropdown() { dropdown.style.display = (dropdown.style.display === 'flex') ? 'none' : 'flex'; }
- function setLoading(isLoading) {
- rankListEl.style.opacity = isLoading ? '0.4' : '1';
- loadingMask.classList.toggle('show', isLoading);
- }
- function buildAvatar(name, salt) {
- // Use local Multiavatar library (Pure JS, no external requests)
- // It generates high-quality SVG avatars
- const seedBase = name || 'user';
- const seed = seedBase + (salt || '');
-
- // multiavatar(seed) returns an SVG string
- const svgCode = multiavatar(seed);
-
- // We need to wrap it in a container or return it as a data URI or direct HTML
- // Since the existing code expects an <img> tag or innerHTML, putting SVG directly is best for crispness.
- // However, the existing styling puts it inside a small circle div.
- // Multiavatar SVG is square, so we rely on parent CSS (overflow: hidden) to clip it to a circle.
- return svgCode;
- }
- function setProgress(real, target) {
- const badge = document.getElementById('dashBadge');
- const t1 = document.getElementById('t1');
- const t2 = document.getElementById('t2');
- const t3 = document.getElementById('t3');
- const t4 = document.getElementById('t4');
- const safeReal = Math.max(real || 0, 0);
- const safeTarget = target && target > 0 ? target : 4;
- const ratio = Math.min(safeReal / safeTarget, 1);
- const percent = Math.max(0, Math.min(1, ratio)) * 100;
- trackLine.style.width = percent + '%';
- const textReal = safeReal >= safeTarget ? safeTarget : safeReal;
- badge.innerText = safeReal >= safeTarget ? '挑战成功' : `挑战 ${textReal} / ${safeTarget}`;
- badge.classList.toggle('completed', safeReal >= safeTarget);
- function setIconActive(el, active) {
- if (active) {
- el.classList.add('active');
- if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-check"></i>';
- } else {
- el.classList.remove('active');
- if (!el.classList.contains('final')) el.innerHTML = '<i class="fa-solid fa-lock"></i>';
- }
- }
- setIconActive(t1, safeReal >= 1);
- setIconActive(t2, safeReal >= 2);
- setIconActive(t3, safeReal >= 3);
- setIconActive(t4, safeReal >= safeTarget);
- }
- function renderBadge(real, target) {
- setProgress(real, target);
- }
- function findMonthProgress(year, month, currentMonthData, allMonthsData) {
- const result = { realNum: 0, targetNum: 4 };
- const pick = (arr) => {
- if (!arr || !arr.length) return null;
- for (let i = 0; i < arr.length; i++) {
- if (Number(arr[i].month) === Number(month)) return arr[i];
- }
- return null;
- };
- const fromCurrent = currentMonthData && pick(currentMonthData.monthRs || []);
- if (fromCurrent) return { realNum: fromCurrent.realNum || 0, targetNum: fromCurrent.targetNum || 4 };
- if (allMonthsData && allMonthsData.length) {
- for (let i = 0; i < allMonthsData.length; i++) {
- const item = allMonthsData[i];
- if (item.year && Number(item.year) !== Number(year)) continue;
- const found = pick(item.monthRs || []);
- if (found) return { realNum: found.realNum || 0, targetNum: found.targetNum || 4 };
- }
- }
- return result;
- }
- function renderMonths(list) {
- dropdown.innerHTML = '';
- if (!list || list.length === 0) {
- dropdown.innerHTML = '<div class="dd-item">暂无月份数据</div>';
- return;
- }
- list.forEach((item, idx) => {
- const title = `${item.month}月挑战赛`;
- const div = document.createElement('div');
- const isCurrent = state.currentYM && state.currentYM.year === item.year && state.currentYM.month === item.month;
- div.className = 'dd-item' + (isCurrent ? ' dd-active' : '');
- div.innerText = (idx === 0 && !isCurrent) ? `${title} (本月)` : title;
- div.onclick = () => {
- selectMonth(item.year, item.month, title);
- };
- dropdown.appendChild(div);
- });
- }
- function renderPodium(list, tabType) {
- const type = tabType || state.activeTab || 'score';
- podiumWrap.innerHTML = '';
-
- // Ensure we have at least 3 elements for the podium, filling with null if less.
- // This allows the podium structure to always be rendered, even if slots are empty.
- const podiumData = Array(3).fill(null);
- if (list && list.length > 0) {
- list.slice(0, 3).forEach((item, index) => {
- podiumData[index] = item;
- });
- }
- const p1 = podiumData[0]; // Actual Rank 1
- const p2 = podiumData[1]; // Actual Rank 2
- const p3 = podiumData[2]; // Actual Rank 3
- // Define the visual order for rendering (2nd, 1st, 3rd)
- const podiumItems = [
- { person: p2, className: 'p-2' }, // Left column - Second place
- { person: p1, className: 'p-1' }, // Middle column - First place
- { person: p3, className: 'p-3' } // Right column - Third place
- ];
- podiumItems.forEach(itemConfig => {
- const person = itemConfig.person;
- const col = document.createElement('div');
- col.className = 'p-col ' + itemConfig.className;
-
- const name = person ? (person.nickName || person.name || person.userName) : '虚位以待';
- const score = person ? (person.score != null ? person.score : (person.inRankNum != null ? person.inRankNum : '')) : '';
- // Placeholder avatar for empty slots or Multiavatar for actual people
- 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>';
- // Only the actual first place gets the crown, and only if that person exists
- const isActualFirst = (person === p1 && p1 !== null);
- col.innerHTML = `
- ${isActualFirst ? '<div class="crown"><i class="fa-solid fa-crown"></i></div>' : ''}
- <div class="p-img">${avatarContent}</div>
- <div class="p-box">
- <div class="p-name">${name}</div>
- <div class="p-score">${score}</div>
- </div>
- `;
- podiumWrap.appendChild(col);
- });
- // The remaining items for the list below the podium
- const remaining = list && list.length > 3 ? list.slice(3) : [];
- if (type === 'venue') {
- state.venueListRendered = remaining;
- } else {
- state.scoreListRendered = remaining;
- }
- if (state.activeTab === type) renderRankList(remaining);
- }
- function renderRankList(list) {
- rankListEl.innerHTML = '';
- if (!list || list.length === 0) {
- rankListEl.innerHTML = '<div style="padding:20px; color:#b2bec3; text-align:center;">暂无数据</div>';
- return;
- }
- list.forEach((item, idx) => {
- const rankNum = item.rankNum || idx + 1;
- const name = item.nickName || item.name || item.userName || item.teamName || '选手';
- const scoreVal = (item.score != null ? item.score : item.inRankNum);
- const score = scoreVal != null ? scoreVal : '--';
- const team = item.teamName || item.coiName || '';
- const teamIcon = team ? '<i class="fa-solid fa-user-group"></i> ' : '<i class="fa-solid fa-user"></i> ';
- const row = document.createElement('div');
- row.className = 'list-item';
- row.innerHTML = `
- <div class="rank">${rankNum}</div>
- <div class="avatar">${buildAvatar(name, name)}</div>
- <div class="info">
- <div class="name">${name}</div>
- <div class="team">${teamIcon}${team || '个人'}</div>
- </div>
- <div class="score">${score}</div>
- `;
- rankListEl.appendChild(row);
- });
- }
- function renderMyInfo(myRank, myScore, userInfo, statusText) {
- const rankNumEl = document.getElementById('myRankNum');
- const myScoreEl = document.getElementById('myScoreValue');
- const myNameEl = document.getElementById('myName');
- const myTeamEl = document.getElementById('myTeam');
- const myAvatarEl = document.getElementById('myAvatar');
- const rankVal = myRank && Number(myRank.rankNum);
- const hasRank = rankVal > 0;
-
- rankNumEl.innerText = hasRank ? rankVal : '';
- myScoreEl.innerText = hasRank && myScore && myScore.score != null ? myScore.score : '';
-
- const name = (userInfo && (userInfo.nickName || userInfo.userName)) || '我';
- myNameEl.innerText = name;
-
- if (statusText !== undefined) {
- myTeamEl.innerText = statusText;
- } else {
- myTeamEl.innerText = hasRank ? '继续加油' : '继续加油';
- }
-
- myAvatarEl.innerHTML = buildAvatar(name, name);
-
- // Remove click listener if exists (clean slate)
- document.querySelector('.my-rank-bar').onclick = null;
- }
- function renderGuestState() {
- const rankNumEl = document.getElementById('myRankNum');
- const myScoreEl = document.getElementById('myScoreValue');
- const myNameEl = document.getElementById('myName');
- const myTeamEl = document.getElementById('myTeam');
- const myAvatarEl = document.getElementById('myAvatar');
- const myRankBar = document.querySelector('.my-rank-bar');
- rankNumEl.innerText = '--';
- myScoreEl.innerText = '';
- myNameEl.innerText = '您还未登录';
- myTeamEl.innerText = '点击去登录';
- myTeamEl.style.color = '#fdcb6e';
-
- // Random avatar
- const randomSeed = 'guest_' + Math.floor(Math.random() * 10000);
- myAvatarEl.innerHTML = buildAvatar('Guest', randomSeed);
- // Add click listener
- myRankBar.onclick = function() {
- if (window.Bridge && Bridge.toLogin) {
- Bridge.toLogin();
- }
- };
- }
- function renderRules(config) {
- if (!config || !config.configJson) return;
- try {
- const parsed = JSON.parse(config.configJson);
- const rules = parsed.popupRuleList || [];
- if (rules.length > 0 && rules[0].data && rules[0].data.content) {
- ruleContent.innerHTML = rules[0].data.content;
- }
- } catch (err) {
- Logger.warn('[Rule] parse error', err);
- }
- }
- function switchTab(type, tabElement) {
- state.activeTab = type;
- document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
- if (tabElement) tabElement.classList.add('active');
- const baseList = type === 'venue' ? state.venueList : state.scoreList;
- renderPodium(baseList, type);
- const rendered = type === 'venue' ? (state.venueListRendered || baseList.slice(3)) : (state.scoreListRendered || baseList.slice(3));
- renderRankList(rendered);
- }
- function demoProgress(step) {
- setProgress(step, 4);
- }
- async function loadMonthData(year, month) {
- state.currentYM = { year: year, month: month };
- document.getElementById('currentMonthText').innerText = `${month}月挑战赛`;
- renderMonths(state.months);
- setLoading(true);
- try {
- const monthRank = await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
- const monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
- const monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
- state.scoreList = monthGrad;
- state.venueList = monthMap;
- const prog = findMonthProgress(year, month, state.currentMonthData, state.allMonthsData);
- renderBadge(prog.realNum, prog.targetNum);
- renderPodium(state.activeTab === 'venue' ? state.venueList : state.scoreList, state.activeTab);
- switchTab(state.activeTab, document.querySelector('.tab.active'));
- } catch (err) {
- Logger.error('[Month] 加载失败', err);
- rankListEl.innerHTML = '<div style="padding:20px; color:#d63031;">数据加载失败,请重试</div>';
- } finally {
- setLoading(false);
- }
- }
- function selectMonth(year, month, title) {
- dropdown.style.display = 'none';
- loadMonthData(year, month);
- }
- async function initPage() {
- // Platform detection for CSS adjustments
- if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
- document.body.classList.add('platform-ios');
- }
- const ecId = getQuery('ecId') || '4';
- const token = getQuery('token');
- let baseUrl = getQuery('baseUrl') || undefined;
- const env = (getQuery('env') || '').toLowerCase();
- const useMock = env === 'mock';
- Logger.init(useMock); // Initialize logger based on mock status
- const ym = getYearMonth();
-
- // 1. Initialize with 6 months
- state.months = getRecentMonths(6);
-
- if (!baseUrl && !useMock) baseUrl = 'https://colormaprun.com/api/card/';
- if (window.Bridge && window.Bridge.onToken) Bridge.onToken(API.setToken);
- API.init({ token: token || '', useMock: useMock, baseUrl: baseUrl });
- const allowLogin = !useMock && token;
- renderMonths(state.months);
- setLoading(true);
- async function safeCall(promiseFactory) {
- try { return await promiseFactory(); }
- catch (err) { Logger.warn('[Optional API] ignore error', err); return null; }
- }
- // Helper to load data for a specific month
- async function fetchMonthData(year, month) {
- return await API.request('MonthRankDetailQuery', { year: year, month: month, dispArrStr: 'grad,mapNum' });
- }
- try {
- // 2. Try loading current month first
- let targetYM = { year: ym.year, month: ym.month };
- let monthRank = await fetchMonthData(targetYM.year, targetYM.month);
-
- // 3. Check if current month has data
- let monthGrad = monthRank && monthRank.gradRs ? monthRank.gradRs : [];
- let monthMap = monthRank && monthRank.mapNumRs ? monthRank.mapNumRs : [];
- let hasData = monthGrad.length > 0 || monthMap.length > 0;
- // 4. If no data, search backwards in the 6-month list
- if (!hasData) {
- // Start from index 1 because index 0 (current month) is already checked
- for (let i = 1; i < state.months.length; i++) {
- const checkYM = state.months[i];
- const checkRank = await fetchMonthData(checkYM.year, checkYM.month);
- const checkGrad = checkRank && checkRank.gradRs ? checkRank.gradRs : [];
- const checkMap = checkRank && checkRank.mapNumRs ? checkRank.mapNumRs : [];
-
- if (checkGrad.length > 0 || checkMap.length > 0) {
- // Found data! Update target and data
- targetYM = checkYM;
- monthRank = checkRank;
- monthGrad = checkGrad;
- monthMap = checkMap;
- hasData = true;
- break;
- }
- }
- }
- // Update state with the found (or original empty) data
- state.currentYM = targetYM;
- state.scoreList = monthGrad;
- state.venueList = monthMap;
- let base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig;
- if (useMock || allowLogin) {
- [base, currentMonth, allMonths, myRank, myScore, userInfo, cardConfig] = await Promise.all([
- safeCall(() => API.getCardBase(ecId)),
- safeCall(() => API.request('CurrentMonthlyChallengeQuery', { year: targetYM.year, month: targetYM.month })),
- safeCall(() => API.getMonthlyChallenge()),
- safeCall(() => API.getUserCurrentRank(ecId)),
- safeCall(() => API.getScore(ecId)),
- safeCall(() => API.getUserInfo()),
- safeCall(() => API.getCardConfig(ecId, 'rank'))
- ]);
- } else {
- base = { ecName: `${targetYM.month}月挑战赛` };
- currentMonth = { monthRs: [{ month: targetYM.month, realNum: 0, targetNum: 4 }] };
- allMonths = [];
- myRank = null;
- myScore = null;
- userInfo = null;
- cardConfig = null;
- }
- const selfRow = monthGrad.find && monthGrad.find(item => item.isSelf === 1);
- if (!base && monthGrad.length) base = { ecName: `${targetYM.month}月挑战赛` };
- state.currentMonthData = currentMonth || null;
- state.allMonthsData = allMonths || null;
-
- // IMPORTANT: Render with the actually selected month (targetYM)
- const prog = findMonthProgress(targetYM.year, targetYM.month, state.currentMonthData, state.allMonthsData);
- document.getElementById('currentMonthText').innerText = `${targetYM.month}月挑战赛`;
-
- // Re-render dropdown to highlight correct month
- renderMonths(state.months);
- renderBadge(prog.realNum, prog.targetNum);
- renderPodium(state.scoreList, 'score');
- switchTab(state.activeTab, document.querySelector('.tab.active'));
-
- if (!token && !useMock) {
- renderGuestState();
- } else {
- const selfItem = monthGrad && monthGrad.find(item => item.isSelf === 1);
- if (selfItem) {
- renderMyInfo(
- { rankNum: selfItem.rankNum },
- { score: selfItem.score != null ? selfItem.score : selfItem.inRankNum },
- userInfo
- );
- } else {
- renderMyInfo(null, null, userInfo, '继续加油');
- }
- }
- renderRules(cardConfig);
- } finally {
- setLoading(false);
- loadingMask.classList.remove('show'); // Force remove show class
- }
- }
- document.addEventListener('click', (e) => {
- if(!e.target.closest('.month-select') && !e.target.closest('.dropdown')) { dropdown.style.display = 'none'; }
- });
- document.addEventListener('DOMContentLoaded', initPage);
- </script>
- <!-- New Year Confetti Effect Logic -->
- <script>
- (function() {
- // Confetti Effect
- const canvas = document.getElementById('confettiCanvas');
- if (!canvas) return;
- const ctx = canvas.getContext('2d');
- let width, height;
- let particles = [];
- const colors = ['#f1c40f', '#e74c3c', '#3498db', '#9b59b6', '#2ecc71'];
-
- function resize() {
- width = window.innerWidth;
- height = window.innerHeight;
- canvas.width = width;
- canvas.height = height;
- }
-
- function initParticles() {
- particles = [];
- const count = Math.min(150, Math.floor(width * 0.25));
- for(let i=0; i<count; i++) {
- particles.push(createParticle());
- }
- }
- function createParticle() {
- return {
- x: Math.random() * width,
- y: Math.random() * height - height, // Start above
- r: Math.random() * 4 + 2, // Size
- d: Math.random() * 150, // density/weight
- color: colors[Math.floor(Math.random() * colors.length)],
- tilt: Math.floor(Math.random() * 10) - 10,
- tiltAngleIncremental: Math.random() * 0.07 + 0.05,
- tiltAngle: 0
- };
- }
-
- function draw() {
- ctx.clearRect(0, 0, width, height);
- for(let i=0; i<particles.length; i++) {
- const p = particles[i];
- ctx.beginPath();
- ctx.lineWidth = p.r / 2;
- ctx.strokeStyle = p.color;
- ctx.moveTo(p.x + p.tilt + p.r / 4, p.y);
- ctx.lineTo(p.x + p.tilt, p.y + p.tilt + p.r / 4);
- ctx.stroke();
- update(p, i);
- }
- requestAnimationFrame(draw);
- }
-
- let angle = 0;
- function update(p, i) {
- angle += 0.01;
- p.tiltAngle += p.tiltAngleIncremental;
-
- // Movement
- p.y += (Math.cos(angle + p.d) + 3 + p.r / 2) / 2;
- p.x += Math.sin(angle);
- p.tilt = Math.sin(p.tiltAngle) * 15;
- // Respawn
- if(p.y > height) {
- particles[i] = createParticle();
- particles[i].y = -10;
- }
- }
-
- window.addEventListener('resize', () => {
- resize();
- initParticles();
- });
-
- resize();
- initParticles();
- draw();
- })();
- </script>
- </body>
- </html>
|