Browse Source

Merge remote-tracking branch 'gogs/master'

nahida 5 tháng trước cách đây
mục cha
commit
8c92296de0
1 tập tin đã thay đổi với 46 bổ sung6 xóa
  1. 46 6
      src/components/about/ContactUs.tsx

+ 46 - 6
src/components/about/ContactUs.tsx

@@ -3,19 +3,59 @@ import React, {useEffect} from 'react';
 import SubTitle from "@/components/subTitle";
 import {BDMapGL} from "@/utils/BDMap";
 import Image from "next/image";
+import {serverGet, serverPost} from "@/utils/request";
 
+export async function generateStaticParams() {
+  const basicInfoRes = await serverGet<BasicInfo[]>("/webSite/getLocationInforList", {
+    next: {
+      revalidate: 1800
+    },
+    cache: "force-cache"
+  })
+  return basicInfoRes.data
+}
 function ContactUs({basicInfo}: {basicInfo: BasicInfo}) {
   const BASE_URL:string = process.env.NEXT_PUBLIC_BASE_URL as string;
 
   const BDMapInit = () => {
     BDMapGL('94KOPB1NRjoXmLvlJN6HMi7eVC50z09K').then((BMapGL: any) => {
       const map = new BMapGL.Map('container')
-      const point = new BMapGL.Point(112.863450,28.178478)
-      map.centerAndZoom(point, 16)
-      map.enableScrollWheelZoom(true) //设置鼠标放大缩小
-      map.addControl(new BMapGL.ScaleControl()) //卡尺
-      const marker = new BMapGL.Marker(point) // 创建标注
-      map.addOverlay(marker)
+      let pointLists;
+
+      // { lng: 112.863450, lat: 28.178478, name: "长沙市", address: "北京市东城区东长安街" },
+      // { lng: 110.009930, lat: 27.582966, name: "怀化市", address: "北京市东城区景山前街4号" },
+      // { lng: 110.400296, lat: 28.459076, name: "沅陵县", address: "北京市海淀区新建宫门路19号" },
+      // { lng: 113.141009, lat: 27.837841, name: "株洲市", address: "北京市海淀区新建宫门路19号" }
+
+      generateStaticParams().then((resultArray) => {
+        pointLists = resultArray; // 获取数组第1个元素
+        console.log(1111,pointLists)
+        pointLists.forEach(point => {
+          const bmapPoint = new BMapGL.Point(point.longitude, point.latitude);
+          const marker = new BMapGL.Marker(bmapPoint);
+
+          // 创建信息窗口(内容可自定义 HTML)
+            const infoWindow = new BMapGL.InfoWindow(`
+            <div>
+              <h4>姓名:${point.name}</h4>
+              <p style="margin: 5px 0 0; color: #666;">区域:${point.marker}</p>
+              <p style="margin: 5px 0 10px; color: #666;">联系方式:${point.phone}</p>
+            </div>
+          `);
+
+          // 绑定点击事件:点击标记点显示信息窗口
+          marker.addEventListener("click", () => {
+            map.openInfoWindow(infoWindow, bmapPoint); // 在点位坐标处打开窗口
+          });
+
+          map.centerAndZoom(bmapPoint, 7)
+          map.enableScrollWheelZoom(true) //设置鼠标放大缩小
+          map.addControl(new BMapGL.ScaleControl()) //卡尺
+          map.addOverlay(marker)
+        });
+      }).catch((err) => {
+        console.error("Promise 执行失败:", err);
+      });
     })
   }
   const qrCodeUrl = BASE_URL + basicInfo.qrCodeUrl