| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="https://cdn.tailwindcss.com"></script>
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
- <script>
- tailwind.config = {
- theme: {
- extend: {
- colors: {
- primary: '#3372ac',
- },
- animation: {
- marquee: 'marquee 25s linear infinite',
- },
- keyframes: {
- marquee: {
- '0%': { transform: 'translateX(100%)' },
- '100%': { transform: 'translateX(-100%)' },
- }
- }
- }
- }
- }
- </script>
- <style>
- @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;800&display=swap');
- body { font-family: 'Nunito', sans-serif; }
- .no-scrollbar::-webkit-scrollbar { display: none; }
- .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
- .snap-mandatory { scroll-behavior: smooth; }
- .fade-in-up { animation: fadeInUp 0.4s ease-out forwards; opacity: 0; transform: translateY(10px); }
- @keyframes fadeInUp { to { opacity: 1; transform: translateY(0); } }
-
- .dropdown-enter { opacity: 0; transform: translateY(-10px) scale(0.95); }
- .dropdown-enter-active { opacity: 1; transform: translateY(0) scale(1); transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
- </style>
- </head>
- <body class="bg-slate-50 relative pb-24" onclick="closeDropdownOnClickOutside(event)">
- <!-- 1. 顶部 Header -->
- <div class="relative w-full h-[260px]">
- <img src="https://orienteering.beswell.com/card/nanning/cardtop1122-2.jpg"
- class="w-full h-full object-cover shadow-md" alt="Header BG">
- <div class="absolute inset-0 bg-gradient-to-b from-primary/60 via-transparent to-black/30"></div>
- <div class="absolute top-0 w-full pt-10 px-5 flex justify-between items-center z-10 text-white">
- <button class="bg-black/20 backdrop-blur-sm p-2 rounded-full w-9 h-9 flex items-center justify-center active:scale-90 transition">
- <i class="fas fa-chevron-left"></i>
- </button>
- <h1 class="text-lg font-bold tracking-wider shadow-sm">实时赛况</h1>
- <button onclick="openInfoModal()" class="bg-black/20 backdrop-blur-sm px-3 py-1.5 rounded-full text-xs font-semibold flex items-center gap-1 active:scale-90 transition">
- <i class="fas fa-question-circle"></i> 说明
- </button>
- </div>
- <!-- 底部公告跑马灯 -->
- <div class="absolute bottom-[35px] w-full z-10 px-4">
- <div class="bg-black/40 backdrop-blur-md rounded-full py-1.5 px-3 flex items-center gap-2 overflow-hidden border border-white/10 shadow-lg">
- <i class="fas fa-bullhorn text-yellow-300 text-xs shrink-0"></i>
- <div class="flex-1 overflow-hidden relative h-4">
- <div id="marqueeTextContainer" class="absolute whitespace-nowrap text-[10px] text-white animate-marquee leading-4">
- 总里程: 5024km | 总打点数: 8900个 | 答题正确率: 1500道 | 距离比赛结束还有 1天 5小时 | 加油!冲鸭!
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 2. 个人信息卡 -->
- <div class="px-4 -mt-8 relative z-20">
- <div class="bg-white rounded-xl shadow-lg p-4 flex justify-between items-center border border-white/50">
- <div class="flex items-center gap-3">
- <div class="relative">
- <img src="https://i.pravatar.cc/100?img=12" class="w-12 h-12 rounded-full border-2 border-slate-100">
- <div class="absolute -bottom-1 -right-1 bg-primary text-white text-[8px] px-1.5 py-0.5 rounded-full border border-white">Lv.3</div>
- </div>
- <div>
- <!-- 昵称 & 编辑按钮 -->
- <h2 class="font-bold text-gray-800 text-sm flex items-center gap-1">
- <span id="profileName">奔跑的蜗牛</span>
- <button onclick="openEditModal()" class="text-xs text-primary/60 p-1 hover:text-primary transition-colors"><i class="fas fa-pen"></i></button>
- </h2>
- <!-- 战队 -->
- <p class="text-xs text-gray-500 mt-0.5 flex items-center gap-1">
- <i class="fas fa-user-friends text-blue-300 text-[10px]"></i>
- <span id="profileTeam">飞虎队</span>
- </p>
- </div>
- </div>
- <div class="text-center pl-4 border-l border-gray-100">
- <div id="currentScoreDisplay" class="text-2xl font-black text-primary font-mono leading-none">120</div>
- <div class="text-[10px] text-gray-400 mt-1">当前积分</div>
- </div>
- </div>
- </div>
- <!-- 3. 排行榜 Tabs -->
- <div class="mt-6 px-4">
-
- <!-- 主榜单切换:轻量化分段控制器风格 -->
- <div class="bg-slate-100 p-1 rounded-full flex gap-1 mb-4 relative shadow-inner">
- <button onclick="switchMainTab('team')" id="tab-team"
- class="flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 bg-white text-primary shadow-sm">
- 团队榜
- </button>
- <button onclick="switchMainTab('individual')" id="tab-ind"
- class="flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 text-gray-500 hover:text-gray-700">
- 个人榜
- </button>
- </div>
-
- <!-- 维度切换 -->
- <div class="flex gap-2 justify-center pt-4 overflow-x-auto no-scrollbar pb-2" id="metric-tabs">
- <button onclick="switchMetric('score')" id="metric-score" class="metric-btn bg-primary text-white px-3 py-1 rounded-full text-xs shadow-md shadow-blue-100 font-bold shrink-0 relative overflow-visible">
- 积分
- <span id="prize-badge" class="absolute -top-2 -right-2 bg-red-500 text-white text-[9px] px-1.5 py-0.5 rounded-full shadow-sm border border-white z-10 leading-none">奖</span>
- </button>
- <button onclick="switchMetric('mileage')" id="metric-mileage" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">里程</button>
- <button onclick="switchMetric('accuracy')" id="metric-accuracy" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">答题正确率</button>
- <button onclick="switchMetric('count')" id="metric-count" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">打点数</button>
- <button onclick="switchMetric('lap')" id="metric-lap" class="metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors">单圈用时</button>
- </div>
- </div>
- <!-- 4. 排行榜列表容器 -->
- <!-- 修改点:space-y-2 (间距变小), 内层渲染 logic 变 p-2 -->
- <div id="leaderboard-container" class="px-4 mt-1 space-y-2 mb-24 min-h-[300px]"></div>
- <!-- 5. 底部悬浮栏 -->
- <div class="fixed bottom-0 w-full bg-white border-t border-gray-100 shadow-[0_-5px_20px_rgba(0,0,0,0.05)] px-4 py-3 flex items-center z-40 safe-area-bottom">
- <button onclick="openDrawer()" class="w-full bg-gradient-to-r from-orange-500 to-red-600 text-white py-3 rounded-full font-bold shadow-lg shadow-orange-100 transform active:scale-[0.98] transition flex items-center justify-center gap-2 text-base">
- <i class="fas fa-flag-checkered animate-pulse"></i> 进入比赛
- </button>
- </div>
- <!-- ================= 模态框区域 ================= -->
- <!-- A. 编辑个人资料模态框 -->
- <div id="editProfileModal" class="fixed inset-0 z-[60] hidden flex items-center justify-center">
- <div class="absolute inset-0 bg-slate-900/60 backdrop-blur-sm" onclick="closeEditModal()"></div>
- <div class="bg-white w-[85%] rounded-2xl p-6 relative z-10 shadow-2xl animate-[fadeInUp_0.3s_ease-out]">
- <h3 class="font-bold text-lg mb-6 text-gray-800 text-center">修改报名信息</h3>
- <div class="space-y-5">
- <div>
- <label class="block text-sm font-bold text-gray-500 mb-2">我的昵称</label>
- <input type="text" id="editNameInput" value="奔跑的蜗牛"
- class="w-full bg-slate-50 border border-gray-200 rounded-lg px-4 py-2.5 text-sm font-bold text-gray-800 focus:outline-none focus:ring-1 focus:ring-primary focus:bg-white transition-colors">
- </div>
- <div>
- <label class="block text-sm font-bold text-gray-500 mb-2">所属战队</label>
- <div class="relative group">
- <button type="button" id="dropdownBtn" onclick="toggleDropdown(event)"
- class="w-full bg-slate-50 border border-gray-200 rounded-lg px-4 py-2.5 text-sm font-bold text-left flex items-center justify-between focus:outline-none focus:ring-1 focus:ring-primary transition-all">
- <span id="selectedTeamText" class="text-gray-800 flex items-center gap-2">
- <i class="fas fa-user-friends text-primary"></i> 飞虎队
- </span>
- <i class="fas fa-chevron-circle-down text-gray-400 transition-transform duration-300" id="dropdownArrow"></i>
- </button>
- <div id="dropdownMenu" class="hidden absolute top-[110%] left-0 w-full bg-white rounded-xl shadow-2xl border border-gray-100 overflow-hidden z-50 dropdown-enter max-h-48 overflow-y-auto">
- <ul class="text-sm text-gray-700">
- <li onclick="selectOption('飞虎队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between border-b border-gray-50"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 飞虎队</span></li>
- <li onclick="selectOption('火箭队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between border-b border-gray-50"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 火箭队</span></li>
- <li onclick="selectOption('摸鱼队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between border-b border-gray-50"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 摸鱼队</span></li>
- <li onclick="selectOption('汪汪队')" class="px-4 py-3 hover:bg-blue-50 cursor-pointer flex items-center justify-between"><span class="font-bold flex items-center gap-2"><i class="fas fa-user-friends text-blue-200"></i> 汪汪队</span></li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="flex gap-3 mt-8">
- <button onclick="closeEditModal()" class="flex-1 py-2.5 rounded-full border border-gray-200 text-gray-500 font-bold text-sm">取消</button>
- <button onclick="saveProfile()" class="flex-1 py-2.5 rounded-full bg-primary text-white font-bold text-sm shadow-lg shadow-blue-200">保存修改</button>
- </div>
- </div>
- </div>
- <!-- B. 说明模态框 -->
- <div id="infoModal" class="fixed inset-0 z-50 hidden transition-opacity duration-300">
- <div class="absolute inset-0 bg-slate-900/70 backdrop-blur-sm" onclick="closeInfoModal()"></div>
- <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[90%] bg-white rounded-3xl p-6 shadow-2xl">
- <button onclick="closeInfoModal()" class="absolute -top-12 right-0 text-white/80 hover:text-white w-10 h-10 border border-white/30 rounded-full flex items-center justify-center">
- <i class="fas fa-times text-lg"></i>
- </button>
- <h3 class="text-center font-bold text-xl mb-4 text-primary border-b border-gray-100 pb-3">
- <i class="fas fa-book-open mr-2"></i>比赛规则说明
- </h3>
- <div id="modalSlider" class="overflow-x-auto flex snap-x snap-mandatory no-scrollbar space-x-4 pb-2" onscroll="updateDots()">
- <div class="snap-center shrink-0 w-full bg-blue-50 rounded-2xl p-5 text-center border border-blue-100">
- <div class="w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3"><i class="fas fa-map-marker-alt text-xl text-primary"></i></div>
- <h4 class="font-bold text-base text-gray-800 mb-1">1. 定向寻宝</h4>
- <p class="text-gray-600 text-xs leading-relaxed">比赛设置12个隐藏打卡点。</p>
- </div>
- <div class="snap-center shrink-0 w-full bg-blue-50 rounded-2xl p-5 text-center border border-blue-100">
- <div class="w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3"><i class="fas fa-mobile-alt text-xl text-primary"></i></div>
- <h4 class="font-bold text-base text-gray-800 mb-1">2. 扫码打卡</h4>
- <p class="text-gray-600 text-xs leading-relaxed">到达点位后,使用APP扫描二维码。</p>
- </div>
- <div class="snap-center shrink-0 w-full bg-blue-50 rounded-2xl p-5 text-center border border-blue-100">
- <div class="w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3"><i class="fas fa-medal text-xl text-primary"></i></div>
- <h4 class="font-bold text-base text-gray-800 mb-1">3. 完赛奖励</h4>
- <p class="text-gray-600 text-xs leading-relaxed">前50名有精美礼品!加油!</p>
- </div>
- </div>
- <div class="flex justify-center gap-2 mt-4" id="dotsContainer">
- <div class="dot w-6 h-1.5 rounded-full bg-primary transition-all duration-300"></div>
- <div class="dot w-1.5 h-1.5 rounded-full bg-gray-300 transition-all duration-300"></div>
- <div class="dot w-1.5 h-1.5 rounded-full bg-gray-300 transition-all duration-300"></div>
- </div>
- </div>
- </div>
- <!-- C. 上滑抽屉 -->
- <div id="drawer-backdrop" class="fixed inset-0 bg-black/50 z-50 hidden transition-opacity" onclick="closeDrawer()"></div>
- <div id="drawer" class="fixed bottom-0 left-0 w-full bg-white rounded-t-3xl p-6 z-50 transform translate-y-full transition-transform duration-300 ease-out safe-area-bottom">
- <div class="w-12 h-1.5 bg-gray-200 rounded-full mx-auto mb-6"></div>
- <h3 class="font-bold text-lg mb-5 text-gray-800">前往比赛场地</h3>
- <div class="space-y-6">
- <div>
- <button onclick="triggerJump('兴隆山校区')" class="w-full border-2 border-primary bg-blue-50 text-primary py-4 rounded-xl font-bold text-sm flex items-center justify-between px-6 shadow-sm active:scale-[0.98] transition-transform">
- <div class="flex items-center gap-3">
- <i class="fas fa-map-marked-alt text-2xl"></i>
- <div class="text-left">
- <div class="text-base font-bold">兴隆山校区</div>
- <div class="text-[10px] opacity-70 font-normal">当前比赛区域</div>
- </div>
- </div>
- <i class="fas fa-chevron-right text-lg"></i>
- </button>
- </div>
- <div>
- <label class="text-xs text-gray-400 font-bold uppercase mb-2 block pl-1">选择导航</label>
- <div class="bg-gray-50 rounded-2xl p-2 flex flex-col gap-2 border border-gray-100">
- <button onclick="triggerJump('高德地图')" class="flex items-center gap-4 w-full bg-white p-3 rounded-xl border border-gray-100 shadow-sm active:bg-gray-50 active:scale-[0.99] transition-transform">
- <img src="./gd.png" class="w-8 h-8 object-contain">
- <div class="text-left">
- <div class="font-bold text-gray-800 text-sm">高德地图</div>
- <div class="text-[10px] text-gray-400">推荐路线</div>
- </div>
- <i class="fas fa-location-arrow ml-auto text-primary"></i>
- </button>
- <button onclick="triggerJump('百度地图')" class="flex items-center gap-4 w-full bg-white p-3 rounded-xl border border-gray-100 shadow-sm active:bg-gray-50 active:scale-[0.99] transition-transform">
- <img src="./bd.png" class="w-8 h-8 object-contain">
- <div class="text-left">
- <div class="font-bold text-gray-800 text-sm">百度地图</div>
- <div class="text-[10px] text-gray-400">备选方案</div>
- </div>
- <i class="fas fa-location-arrow ml-auto text-primary"></i>
- </button>
- </div>
- </div>
- </div>
- </div>
- <script src="./bridge.js"></script>
- <script src="./api.js"></script>
- <script>
- // --- 核心状态 ---
- let currentTab = 'team';
- let currentMetric = 'score';
-
- // --- 全局数据存储 ---
- let API_DATA = {}; // 存储 API 返回的完整对象
- let CURRENT_RANK_LIST = []; // 当前显示的列表
- // --- 字段映射配置 (参考 rankList.vue) ---
- // 对应 dispArrStr: "teamCp,teamDistance,teamRightAnswerPer,teamTodayPace,regionCp,regionDistance,regionRightAnswerPer,regionTodayPace"
- const DATA_MAPPING = {
- team: {
- score: { key: 'teamCpRs', unit: '分', label: '积分' }, // 对应 rankList.vue tab1Current=0, index=0 (rankType=totalScore) -> teamCpRs
- mileage: { key: 'teamDistanceRs', unit: 'km', label: '里程' }, // index=2 (rankType=totalDistance) -> teamDistanceRs
- accuracy: { key: 'teamRightAnswerPerRs', unit: '%', label: '正确率' }, // index=3 -> teamRightAnswerPerRs
- count: { key: 'teamCpRs', unit: '个', label: '打点' }, // 暂复用 teamCpRs 或 teamTodayCpRs? 这里沿用 score 的源,但在 Vue 里是分开的 Tab
- lap: { key: 'teamTodayPaceRs', unit: '/km', label: '配速' } // index=4 -> teamTodayPaceRs
- },
- individual: {
- score: { key: 'regionCpRs', unit: '分', label: '积分' }, // tab1Current=1, index=0 -> regionCpRs
- mileage: { key: 'regionDistanceRs', unit: 'km', label: '里程' },
- accuracy: { key: 'regionRightAnswerPerRs', unit: '%', label: '正确率' },
- count: { key: 'regionCpRs', unit: '个', label: '打点' },
- lap: { key: 'regionTodayPaceRs', unit: '/km', label: '配速' }
- }
- };
- // --- 格式化工具 ---
- const Formatters = {
- distance: (val) => {
- if (!val) return '0';
- if (val < 10000) return (Math.round(val * 100 / 1000) / 100).toFixed(2);
- return Math.round(val / 1000).toString();
- },
- pace: (val) => {
- if (!val) return "--'--\"";
- const m = Math.floor(val / 60);
- const s = Math.floor(val % 60);
- return `${m}'${s < 10 ? '0' + s : s}"`;
- },
- default: (val) => val || '0'
- };
- // --- 渲染逻辑 ---
- function renderLeaderboard() {
- const container = document.getElementById('leaderboard-container');
- container.innerHTML = ''; // Clear existing
- // 1. 获取当前配置
- const config = DATA_MAPPING[currentTab][currentMetric];
- if (!config) return;
- // 2. 获取数据列表
- const rawList = API_DATA[config.key] || [];
-
- // 3. 转换数据结构
- // Vue 组件 item: { rankNum, isSelf, userName, inRankNum, headUrl, ... }
- const fullList = rawList.map(item => {
- let valDisplay = item.inRankNum;
-
- // 根据 Metric 类型进行格式化
- if (currentMetric === 'mileage') valDisplay = Formatters.distance(item.inRankNum);
- else if (currentMetric === 'lap') valDisplay = Formatters.pace(item.inRankNum);
-
- return {
- name: item.userName || item.teamName || '匿名', // 兼容不同字段
- sub: item.additionalName || '', // 副标题
- val: valDisplay,
- unit: config.unit,
- avatar: item.headUrl, // 个人头像
- rank: item.rankNum,
- isMe: item.isSelf === 1 || item.isSelf === true, // 兼容
- raw: item
- };
- });
- if (fullList.length === 0) {
- container.innerHTML = '<div class="text-center text-gray-400 py-10 text-sm">暂无排名数据</div>';
- return;
- }
-
- const renderItem = (item, visualIndex, isRealRank = false) => {
- const rank = (isRealRank && item.rank) ? item.rank : (item.rank || visualIndex + 1);
- const isTop3 = rank <= 3; // 使用真实排名判断样式
- // 图标
- let rankIconHtml = '';
- if (isTop3) {
- const colors = ['text-yellow-400', 'text-gray-400', 'text-orange-600'];
- const colorClass = colors[rank - 1] || 'text-gray-400'; // 安全回退
- const iconClass = currentTab === 'team' ? 'fa-trophy' : 'fa-medal';
- rankIconHtml = `<div class="w-8 flex justify-center shrink-0 mr-1"><i class="fas ${iconClass} ${colorClass} text-lg drop-shadow-sm"></i></div>`;
- } else {
- rankIconHtml = `<div class="w-8 text-center font-bold text-gray-400 text-sm mr-1">${rank}</div>`;
- }
-
- // “我”的特殊排位样式
- if (item.isMe) {
- rankIconHtml = `<div class="w-8 text-center font-black text-primary text-lg italic mr-1">${rank}</div>`;
- }
- // 头像
- let avatarHtml = '';
- if (currentTab === 'team') {
- avatarHtml = `<div class="w-9 h-9 bg-blue-50 rounded-full mr-3 flex items-center justify-center shrink-0 text-primary"><i class="fas fa-user-friends text-base"></i></div>`;
- } else {
- const avatarSrc = item.avatar || 'https://i.pravatar.cc/100?img=1'; // 默认头像
- avatarHtml = `<img src="${avatarSrc}" class="w-9 h-9 rounded-full mr-3 border-2 ${isTop3 ? 'border-yellow-400' : 'border-transparent'} shrink-0 object-cover">`;
- }
- // 容器样式
- let containerClass = "bg-white rounded-xl py-2 px-3 flex items-center shadow-sm border border-gray-100 relative fade-in-up";
- let nameClass = "font-bold text-gray-800 text-sm";
- let valClass = "font-bold text-gray-600 font-mono text-base";
- if (item.isMe) {
- containerClass = "bg-blue-50 rounded-xl py-2 px-3 flex items-center shadow-md border-2 border-primary/30 relative overflow-hidden transform scale-[1.02] fade-in-up z-10 my-2";
- nameClass = "font-bold text-primary text-sm";
- valClass = "font-bold text-primary font-mono text-lg";
- } else if (isTop3) {
- containerClass = "bg-white rounded-xl py-2 px-3 flex items-center shadow-sm border border-yellow-100 relative overflow-hidden fade-in-up";
- }
- const meBadge = item.isMe ? `<div class="absolute right-0 top-0 bg-primary text-white text-[8px] px-1.5 py-0.5 rounded-bl-lg">我</div>` : '';
- return
- `<div class="${containerClass}" style="animation-delay: ${visualIndex * 50}ms">
- ${meBadge}
- ${rankIconHtml}
- ${avatarHtml}
- <div class="flex-1 min-w-0">
- <h4 class="${nameClass} truncate">${item.name}</h4>
- <p class="text-[10px] text-gray-400 truncate">${item.sub}</p>
- </div>
- <div class="text-right">
- <div class="${valClass}">${item.val}</div>
- <div class="text-[10px] text-gray-400">${item.unit}</div>
- </div>
- </div>`;
- };
- let html = '';
-
- // 逻辑:前3名 + (如果我在后面则插队) + 剩余
- // 这里简化处理,直接渲染列表,如果 "我" 在列表中会自动高亮。
- // 如果 API 返回的数据没有包含 "我" (比如分页了),则需要单独处理 getUserCurrentRank 接口,这里暂且假设 rankRs 包含了 top N。
-
- fullList.forEach((item, index) => {
- html += renderItem(item, index);
- });
- container.innerHTML = html;
- }
- // --- 编辑模态框逻辑 ---
- const editModal = document.getElementById('editProfileModal');
- const editNameInput = document.getElementById('editNameInput');
- const selectedTeamText = document.getElementById('selectedTeamText');
- function openEditModal() {
- const currentName = document.getElementById('profileName').innerText;
- const currentTeam = document.getElementById('profileTeam').innerText;
- editNameInput.value = currentName;
- selectedTeamText.innerHTML = `<i class="fas fa-user-friends text-primary"></i> ${currentTeam}`;
- editModal.classList.remove('hidden');
- }
- function closeEditModal() {
- editModal.classList.add('hidden');
- closeDropdown();
- }
- function saveProfile() {
- const newName = editNameInput.value;
- // 这里的 teamName 逻辑仅仅是 UI 演示,实际修改需要调用 API (e.g., signUpOnline)
- // 目前仅更新 UI
- document.getElementById('profileName').innerText = newName;
- // TODO: Call API to update profile if needed
- closeEditModal();
- }
- // --- 下拉菜单 ---
- const dropdownMenu = document.getElementById('dropdownMenu');
- const dropdownArrow = document.getElementById('dropdownArrow');
- function toggleDropdown(event) {
- event.stopPropagation();
- if (dropdownMenu.classList.contains('hidden')) {
- dropdownMenu.classList.remove('hidden');
- setTimeout(() => dropdownMenu.classList.add('dropdown-enter-active'), 10);
- dropdownArrow.style.transform = 'rotate(180deg)';
- } else { closeDropdown(); }
- }
- function closeDropdown() {
- dropdownMenu.classList.remove('dropdown-enter-active');
- dropdownArrow.style.transform = 'rotate(0deg)';
- setTimeout(() => dropdownMenu.classList.add('hidden'), 200);
- }
- function selectOption(teamName) {
- selectedTeamText.innerHTML = `<i class="fas fa-user-friends text-primary"></i> ${teamName}`;
- closeDropdown();
- }
- function closeDropdownOnClickOutside(event) {
- if (!editModal.classList.contains('hidden')) {
- const btn = document.getElementById('dropdownBtn');
- if (!dropdownMenu.contains(event.target) && !btn.contains(event.target)) {
- closeDropdown();
- }
- }
- }
- // --- 切换 Tab ---
- function switchMainTab(type) {
- currentTab = type;
- const tTeam = document.getElementById('tab-team');
- const tInd = document.getElementById('tab-ind');
-
- const activeClass = "flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 bg-white text-primary shadow-sm";
- const inactiveClass = "flex-1 py-2 rounded-full text-sm font-bold text-center transition-all duration-300 text-gray-500 hover:text-gray-700";
- if(type === 'team') {
- tTeam.className = activeClass;
- tInd.className = inactiveClass;
- } else {
- tInd.className = activeClass;
- tTeam.className = inactiveClass;
- }
- renderLeaderboard();
- }
- function switchMetric(metric) {
- currentMetric = metric;
- document.querySelectorAll('.metric-btn').forEach(btn => {
- if (btn.id === `metric-${metric}`) {
- btn.className = 'metric-btn bg-primary text-white px-3 py-1 rounded-full text-xs shadow-md shadow-blue-100 font-bold shrink-0 relative overflow-visible transition-colors';
- } else {
- btn.className = 'metric-btn bg-white text-gray-500 border border-gray-200 px-3 py-1 rounded-full text-xs font-bold shrink-0 active:bg-gray-50 transition-colors';
- }
- });
-
- renderLeaderboard();
- }
- function openInfoModal() { document.getElementById('infoModal').classList.remove('hidden'); }
- function closeInfoModal() { document.getElementById('infoModal').classList.add('hidden'); }
- function openDrawer() { document.getElementById('drawer-backdrop').classList.remove('hidden'); document.getElementById('drawer').classList.remove('translate-y-full'); }
- function closeDrawer() { document.getElementById('drawer-backdrop').classList.add('hidden'); document.getElementById('drawer').classList.add('translate-y-full'); }
- function triggerJump(target) { alert("正在跳转至:" + target); closeDrawer(); }
-
- const slider = document.getElementById('modalSlider');
- const dots = document.querySelectorAll('.dot');
- function updateDots() {
- const index = Math.round(slider.scrollLeft / slider.offsetWidth);
- dots.forEach((dot, i) => {
- dot.className = (i === index) ? 'dot w-6 h-1.5 rounded-full bg-primary transition-all duration-300' : 'dot w-1.5 h-1.5 rounded-full bg-gray-300 transition-all duration-300';
- });
- }
- window.onload = function() {
- // Helper function to get URL query parameters (local to this script)
- function getQueryParam(name) {
- const params = new URLSearchParams(window.location.search);
- return params.get(name);
- }
- // Helper function to format remaining time (seconds timestamp)
- function formatRemainingTime(endSecond) {
- if (endSecond === undefined) return 'N/A';
- const now = Date.now() / 1000; // Current Unix timestamp in seconds
- const diffSeconds = endSecond - now;
- if (diffSeconds <= 0) {
- return '已结束';
- }
- const days = Math.floor(diffSeconds / (3600 * 24));
- const hours = Math.floor((diffSeconds % (3600 * 24)) / 3600);
-
- let timeStr = '';
- if (days > 0) {
- timeStr += `${days}天 `;
- }
- timeStr += `${hours}小时`;
-
- return timeStr.trim();
- }
- // Get external parameters
- const token = getQueryParam('token');
- let ecId = getQueryParam('id'); // Use 'id' from URL as ecId
- const env = getQueryParam('env');
- // Initialize Mock if needed
- if (env === 'mock' && window.API) {
- console.log('Initializing API in Mock mode...');
- window.API.init({ useMock: true });
-
- // Fallback ecId for mock mode if missing
- if (!ecId) {
- ecId = 'mock_default_id';
- console.warn('No "id" parameter found. Using default mock ID:', ecId);
- }
- }
- // State for Marquee Data
- let marqueeData = {
- totalCp: 'N/A',
- totalDistanceKm: 'N/A',
- totalAnswerNum: 'N/A',
- remainingTimeStr: 'N/A'
- };
- function updateMarquee() {
- const marqueeTextContainer = document.getElementById('marqueeTextContainer');
- if (marqueeTextContainer) {
- marqueeTextContainer.innerText =
- `总打点数: ${marqueeData.totalCp}个 | 总里程: ${marqueeData.totalDistanceKm}km | 答题数: ${marqueeData.totalAnswerNum}道 | 距离比赛结束还有 ${marqueeData.remainingTimeStr} | 加油!冲鸭!`;
- }
- }
- // Set token if available
- if (token && window.API && window.API.setToken) {
- window.API.setToken(token);
- console.log('API Token set:', token);
- } else {
- if (env !== 'mock') console.warn('Token not found in URL or API.setToken not available.');
- }
- // Call API with ecId
- if (window.API && ecId) {
- console.log('Starting Analysis-Based Sequence...');
- // 0. Global State for selections
- window.CURRENT_SELECTION = {
- mcId: 0,
- mcType: 0,
- ocaId: 0, // Current selected map ID (for individual)
- mapList: [] // Store map options
- };
-
- // 1. Match Details (Core)
- API.getMatchRsDetail(ecId).then(matchRes => {
- console.log('API Response (getMatchRsDetail):', matchRes);
- if (!matchRes) return;
- const mcId = matchRes.mcId;
- const mcType = matchRes.mcType;
- window.CURRENT_SELECTION.mcId = mcId;
- window.CURRENT_SELECTION.mcType = mcType;
- // Update UI Info
- if (matchRes.nickName) document.getElementById('profileName').innerText = matchRes.nickName;
- if (matchRes.totalSysPoint !== undefined) document.getElementById('currentScoreDisplay').innerText = matchRes.totalSysPoint;
- if (matchRes.endSecond !== undefined) {
- marqueeData.remainingTimeStr = formatRemainingTime(matchRes.endSecond);
- updateMarquee();
- }
- // 2. Parallel Calls: MapList & Statistics
- const p1 = API.getMapList(mcId).then(mapRes => {
- console.log('API Response (getMapList):', mapRes);
- if (mapRes && mapRes.length > 0) {
- window.CURRENT_SELECTION.mapList = mapRes;
- // Default ocaId to the first map
- window.CURRENT_SELECTION.ocaId = mapRes[0].ocaId;
-
- // Update Dropdown/Tab UI if needed (Simulated here)
- // In a real app, you'd populate the 'individual' tab dropdown here
- console.log('Default ocaId set to:', window.CURRENT_SELECTION.ocaId);
- }
- }).catch(e => console.error('MapList Error:', e));
- const p2 = API.getCompStatistic(mcId).then(compStatsRes => {
- if (compStatsRes) {
- if (compStatsRes.totalDistance !== undefined) marqueeData.totalDistanceKm = Math.round(compStatsRes.totalDistance / 1000);
- if (compStatsRes.totalAnswerNum !== undefined) marqueeData.totalAnswerNum = compStatsRes.totalAnswerNum;
- if (compStatsRes.totalCp !== undefined) marqueeData.totalCp = compStatsRes.totalCp;
- updateMarquee();
- }
- }).catch(e => console.warn('CompStat Error:', e));
- // 3. Initial Rank Load (Wait for MapList to ensure ocaId is ready for Individual tab if that's default,
- // but usually Team tab is default which might not need specific ocaId or uses global context)
- Promise.all([p1, p2]).then(() => {
- loadRankData();
- });
- }).catch(err => console.error('MatchRsDetail Error:', err));
- } else if (!ecId) {
- console.warn('URL parameter "id" (ecId) not found.');
- }
- // Internal function to load rank data based on current state
- window.loadRankData = function() {
- const { mcId, mcType, ocaId } = window.CURRENT_SELECTION;
- // Determine effective ocaId based on current tab
- // If Team tab, usually we query global or specific team-level data.
- // If Individual tab, we MUST use the selected ocaId (mapId).
- // Note: The Vue component sends 'ocaId' in apiCardRankDetailQuery.
- // When in Team mode (tab1Current=0), it might still pass the ocaId if the team rank is also segregated by map,
- // OR it might rely on the backend ignoring it for team ranks.
- // Based on analysis: "onSelectChange" updates ocaId and calls query.
-
- let effectiveOcaId = ocaId;
- // If needed: if (currentTab === 'team') effectiveOcaId = 0; // Uncomment if team rank is global
- const dispArrStr = "teamCp,teamTodayCp,teamDistance,teamRightAnswerPer,teamTodayPace,regionCp,regionTodayCp,regionDistance,regionRightAnswerPer,regionTodayPace";
-
- console.log(`Fetching Rank: mcId=${mcId}, type=${mcType}, ocaId=${effectiveOcaId}`);
-
- API.getRankDetail(mcId, mcType, effectiveOcaId, dispArrStr).then(rankRes => {
- console.log('API Response (getRankDetail):', rankRes);
- if (rankRes) {
- API_DATA = rankRes;
- renderLeaderboard();
- } else {
- document.getElementById('leaderboard-container').innerHTML = '<div class="text-center text-gray-400 py-10 text-sm">暂无排名数据</div>';
- }
- }).catch(e => console.error('RankDetail Error:', e));
- };
- // Hook into tab switching
- const originalSwitchMainTab = window.switchMainTab;
- window.switchMainTab = function(type) {
- originalSwitchMainTab(type); // Update UI state
- // Re-load data (ocaId stays same or logic inside loadRankData handles it)
- loadRankData();
- };
- };
- </script>
- </body>
- </html>
|