index.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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, user-scalable=no">
  6. <title>彩图奔跑 - 首页</title>
  7. <style>
  8. body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; background-color: #f7f8fa; }
  9. .header { background: #007aff; color: white; padding: 20px; padding-top: 40px; border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; }
  10. .user-info { display: flex; align-items: center; justify-content: space-between; }
  11. .score-box { text-align: center; background: rgba(255,255,255,0.2); padding: 10px 20px; border-radius: 12px; backdrop-filter: blur(5px); }
  12. .score-num { font-size: 24px; font-weight: bold; }
  13. .section-title { margin: 20px; font-size: 18px; font-weight: bold; color: #333; }
  14. .card-list { padding: 0 15px; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
  15. .card { background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.05); transition: transform 0.2s; }
  16. .card:active { transform: scale(0.98); }
  17. .card-img { width: 100%; height: 100px; background-color: #eee; object-fit: cover; }
  18. .card-body { padding: 10px; }
  19. .card-title { font-size: 14px; font-weight: bold; margin-bottom: 5px; }
  20. .card-desc { font-size: 12px; color: #888; }
  21. .loading { text-align: center; margin-top: 50px; color: #999; }
  22. </style>
  23. <!-- SDK 引入 -->
  24. <script src="./mock_flutter.js"></script> <!-- 调试用,打包请删除 -->
  25. <script src="./bridge.js"></script>
  26. <script src="./api.js"></script>
  27. </head>
  28. <body>
  29. <div class="header">
  30. <div class="user-info">
  31. <div>
  32. <div style="font-size: 14px; opacity: 0.8;">欢迎回来</div>
  33. <div style="font-size: 20px; font-weight: bold;">运动达人</div>
  34. </div>
  35. <div class="score-box">
  36. <div style="font-size: 12px;">我的积分</div>
  37. <div class="score-num" id="scoreVal">--</div>
  38. </div>
  39. </div>
  40. <div style="margin-top: 20px; display: flex; gap: 10px;">
  41. <button onclick="location.href='rank.html'" style="flex: 1; background: rgba(255,255,255,0.2); border: 1px solid white; color: white; border-radius: 20px; padding: 8px;">🏆 排行榜</button>
  42. <button onclick="location.href='signup.html'" style="flex: 1; background: white; color: #007aff; border: none; border-radius: 20px; padding: 8px;">📝 去报名</button>
  43. </div>
  44. </div>
  45. <div class="section-title">热门活动</div>
  46. <div class="card-list" id="listContainer">
  47. <!-- 动态生成 -->
  48. </div>
  49. <div class="loading" id="loading">加载数据中...</div>
  50. <script>
  51. // 模拟 Token,真实环境请从 URL 获取: getUrlParam('token')
  52. var TOKEN = '96ba3c924394934f7d30fa869a94ce0d';
  53. // 1. 初始化
  54. // 增强本地环境检测:包含 file:, localhost, 127.0.0.1
  55. var isLocal = window.location.protocol === 'file:' ||
  56. window.location.hostname === 'localhost' ||
  57. window.location.hostname === '127.0.0.1';
  58. API.init({
  59. token: TOKEN,
  60. useMock: isLocal
  61. });
  62. // 2. 获取积分
  63. API.getScore(0).then(function(data) {
  64. document.getElementById('scoreVal').innerText = data.score;
  65. }).catch(function(err) {
  66. console.error('积分获取失败', err);
  67. document.getElementById('scoreVal').innerText = 'Err';
  68. });
  69. // 3. 模拟获取活动列表 (API中没有直接的活动列表接口,这里用静态数据模拟业务逻辑)
  70. var mockActivities = [
  71. { id: 101, name: '奥体中心定向赛', desc: '探索城市地标', img: 'https://via.placeholder.com/150/007aff/ffffff?text=Aoti' },
  72. { id: 102, name: '千佛山登山节', desc: '登高望远', img: 'https://via.placeholder.com/150/ff9500/ffffff?text=Mountain' },
  73. { id: 103, name: '大明湖健步走', desc: '湖畔漫步', img: 'https://via.placeholder.com/150/34c759/ffffff?text=Lake' },
  74. { id: 104, name: '校园寻宝', desc: '重返校园时光', img: 'https://via.placeholder.com/150/af52de/ffffff?text=School' }
  75. ];
  76. setTimeout(function() {
  77. document.getElementById('loading').style.display = 'none';
  78. renderList(mockActivities);
  79. }, 500);
  80. function renderList(list) {
  81. var html = '';
  82. list.forEach(function(item) {
  83. html += `
  84. <div class="card" onclick="goDetail(${item.id}, '${item.name}')">
  85. <img src="${item.img}" class="card-img">
  86. <div class="card-body">
  87. <div class="card-title">${item.name}</div>
  88. <div class="card-desc">${item.desc}</div>
  89. </div>
  90. </div>`;
  91. });
  92. document.getElementById('listContainer').innerHTML = html;
  93. }
  94. function goDetail(id, name) {
  95. // 跳转到 H5 详情页 (演示页面间传参)
  96. window.location.href = `detail.html?id=${id}&name=${encodeURIComponent(name)}`;
  97. }
  98. </script>
  99. </body>
  100. </html>