index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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">
  6. <title>充电桩查询系统</title>
  7. <script type="text/javascript"
  8. src="https://webapi.amap.com/maps?v=2.0&key=f0eabeffc4e5f3d9f9836d21a3c4de1f"></script>
  9. <style>
  10. * {
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. body {
  16. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  17. background-color: #f6f6f6;
  18. color: #333;
  19. }
  20. .container {
  21. max-width: 100%;
  22. margin: 0 auto;
  23. }
  24. .map-container {
  25. width: 100%;
  26. height: 50vh;
  27. background-color: #e5e5e5;
  28. position: relative;
  29. }
  30. .search-bar {
  31. position: absolute;
  32. top: 20px;
  33. left: 50%;
  34. transform: translateX(-50%);
  35. width: 90%;
  36. padding: 12px;
  37. background: white;
  38. border-radius: 8px;
  39. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  40. display: flex;
  41. align-items: center;
  42. }
  43. .search-bar input {
  44. flex: 1;
  45. border: none;
  46. padding: 8px;
  47. font-size: 14px;
  48. outline: none;
  49. }
  50. .search-bar button {
  51. border: none;
  52. background: #4CAF50;
  53. color: white;
  54. padding: 8px 16px;
  55. border-radius: 4px;
  56. margin-left: 10px;
  57. cursor: pointer;
  58. }
  59. .station-list {
  60. padding: 16px;
  61. }
  62. .station-card {
  63. background: white;
  64. border-radius: 12px;
  65. padding: 16px;
  66. margin-bottom: 16px;
  67. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  68. }
  69. .station-name {
  70. font-size: 16px;
  71. font-weight: bold;
  72. margin-bottom: 8px;
  73. color: #333;
  74. }
  75. .station-info {
  76. font-size: 14px;
  77. color: #666;
  78. margin-bottom: 4px;
  79. }
  80. .station-status {
  81. display: flex;
  82. justify-content: space-between;
  83. align-items: center;
  84. margin-top: 12px;
  85. }
  86. .status-tag {
  87. background: #e8f5e9;
  88. color: #4CAF50;
  89. padding: 4px 8px;
  90. border-radius: 4px;
  91. font-size: 12px;
  92. }
  93. .distance {
  94. color: #999;
  95. font-size: 12px;
  96. }
  97. .tab-bar {
  98. position: fixed;
  99. bottom: 0;
  100. width: 100%;
  101. background: white;
  102. display: flex;
  103. padding: 8px 0;
  104. border-top: 1px solid #eee;
  105. z-index: 1000;
  106. }
  107. .tab-item {
  108. flex: 1;
  109. text-align: center;
  110. color: #999;
  111. font-size: 12px;
  112. padding: 4px 0;
  113. display: flex;
  114. flex-direction: column;
  115. align-items: center;
  116. transition: all 0.3s ease;
  117. cursor: pointer;
  118. }
  119. .tab-item svg {
  120. width: 24px;
  121. height: 24px;
  122. margin-bottom: 4px;
  123. fill: currentColor;
  124. transition: all 0.3s ease;
  125. }
  126. .tab-item.active {
  127. color: #4CAF50;
  128. transform: scale(1.1);
  129. }
  130. .custom-marker {
  131. background-color: white;
  132. padding: 8px 12px;
  133. border-radius: 4px;
  134. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  135. min-width: 130px;
  136. }
  137. .marker-title {
  138. font-size: 14px;
  139. font-weight: bold;
  140. color: #333;
  141. margin-bottom: 4px;
  142. }
  143. .marker-info {
  144. font-size: 12px;
  145. color: #666;
  146. margin-bottom: 4px;
  147. }
  148. .marker-status {
  149. font-size: 12px;
  150. color: #4CAF50;
  151. background: #e8f5e9;
  152. padding: 2px 6px;
  153. border-radius: 3px;
  154. display: inline-block;
  155. }
  156. </style>
  157. </head>
  158. <body>
  159. <div class="container">
  160. <div class="map-container">
  161. <div class="search-bar">
  162. <input type="text" placeholder="搜索附近充电桩">
  163. <button>搜索</button>
  164. </div>
  165. <div id="container" style="width: 100%; height: 100%;"></div>
  166. </div>
  167. <div class="station-list">
  168. <div class="station-card">
  169. <div class="station-name">星星充电站 - 望京SOHO</div>
  170. <div class="station-info">北京市朝阳区望京SOHO T1</div>
  171. <div class="station-info">营业时间:24小时</div>
  172. <div class="station-status">
  173. <span class="status-tag">可用 10/12</span>
  174. <span class="distance">距离500m</span>
  175. </div>
  176. </div>
  177. <div class="station-card">
  178. <div class="station-name">特来电充电站 - 三里屯</div>
  179. <div class="station-info">北京市朝阳区三里屯太古里</div>
  180. <div class="station-info">营业时间:24小时</div>
  181. <div class="station-status">
  182. <span class="status-tag">可用 5/8</span>
  183. <span class="distance">距离1.2km</span>
  184. </div>
  185. </div>
  186. </div>
  187. <div class="tab-bar">
  188. <div class="tab-item active">
  189. <svg>
  190. <use xlink:href="./images/icons.svg#icon-home" />
  191. </svg>
  192. <span>首页</span>
  193. </div>
  194. <div class="tab-item">
  195. <svg>
  196. <use xlink:href="./images/icons.svg#icon-list" />
  197. </svg>
  198. <span>列表</span>
  199. </div>
  200. <div class="tab-item">
  201. <svg>
  202. <use xlink:href="./images/icons.svg#icon-favorite" />
  203. </svg>
  204. <span>收藏</span>
  205. </div>
  206. <div class="tab-item">
  207. <svg>
  208. <use xlink:href="./images/icons.svg#icon-person" />
  209. </svg>
  210. <span>我的</span>
  211. </div>
  212. </div>
  213. </div>
  214. <script>
  215. // 底部导航栏交互
  216. document.querySelectorAll('.tab-item').forEach(item => {
  217. item.addEventListener('click', function () {
  218. // 移除其他项的active类
  219. document.querySelectorAll('.tab-item').forEach(tab => {
  220. tab.classList.remove('active');
  221. });
  222. // 为当前点击项添加active类
  223. this.classList.add('active');
  224. });
  225. });
  226. // 初始化地图
  227. var map = new AMap.Map('container', {
  228. zoom: 13,
  229. center: [116.48621, 39.99875] // 望京SOHO坐标
  230. });
  231. // 添加定位控件
  232. AMap.plugin(['AMap.Geolocation'], function () {
  233. var geolocation = new AMap.Geolocation({
  234. enableHighAccuracy: true,
  235. timeout: 10000,
  236. buttonPosition: 'RB',
  237. buttonOffset: new AMap.Pixel(10, 20),
  238. zoomToAccuracy: true
  239. });
  240. map.addControl(geolocation);
  241. geolocation.getCurrentPosition();
  242. });
  243. // 定义充电桩图标样式
  244. var chargerIcon = new AMap.Icon({
  245. size: new AMap.Size(32, 32),
  246. image: './images/charging-station.svg',
  247. imageSize: new AMap.Size(32, 32)
  248. });
  249. // 添加充电站标记点
  250. var markers = [
  251. {
  252. position: [116.48621, 39.99875], // 望京SOHO坐标
  253. title: '星星充电站 - 望京SOHO',
  254. address: '北京市朝阳区望京SOHO T1',
  255. available: '10/12'
  256. },
  257. {
  258. position: [116.45398, 39.93428], // 三里屯坐标
  259. title: '特来电充电站 - 三里屯',
  260. address: '北京市朝阳区三里屯太古里',
  261. available: '5/8'
  262. }
  263. ];
  264. markers.forEach(function (marker) {
  265. var markerInstance = new AMap.Marker({
  266. map: map,
  267. position: marker.position,
  268. icon: chargerIcon,
  269. offset: new AMap.Pixel(-16, -32)
  270. });
  271. // 创建信息窗体
  272. var infoWindow = new AMap.InfoWindow({
  273. isCustom: true,
  274. content: `<div class="custom-marker">
  275. <div class="marker-title">${marker.title}</div>
  276. <div class="marker-info">${marker.address}</div>
  277. <div class="marker-status">可用: ${marker.available}</div>
  278. </div>`,
  279. offset: new AMap.Pixel(0, -30)
  280. });
  281. // 绑定点击事件
  282. markerInstance.on('click', function () {
  283. infoWindow.open(map, marker.position);
  284. });
  285. });
  286. // 搜索功能
  287. document.querySelector('.search-bar button').addEventListener('click', function () {
  288. var keyword = document.querySelector('.search-bar input').value;
  289. if (keyword) {
  290. AMap.plugin(['AMap.PlaceSearch'], function () {
  291. var placeSearch = new AMap.PlaceSearch({
  292. city: '北京',
  293. type: '充电站'
  294. });
  295. placeSearch.search(keyword, function (status, result) {
  296. if (status === 'complete' && result.info === 'OK') {
  297. var pois = result.poiList.pois;
  298. map.setCenter(pois[0].location);
  299. }
  300. });
  301. });
  302. }
  303. });
  304. </script>
  305. </body>
  306. </html>