bill 1 year ago
parent
commit
b3c96d7113
3 changed files with 36 additions and 35 deletions
  1. 3 0
      src/request/URL.ts
  2. 32 35
      src/util/pc4xlsl.ts
  3. 1 0
      src/view/map/hot.ts

+ 3 - 0
src/request/URL.ts

@@ -17,6 +17,9 @@ export const delRelicsScene = `/relics/relics-scene/del`;
 export const updateRelicsScenePosName = `/relics/relics-scene/editPosName`;
 export const getRelicsScenePosInfo = `/relics/relics-scene-pos/get/:posId`;
 
+export const exportCoordinateData = `/relics/excel/coordinateData`;
+export const exportVectorData = `/relics/excel/vectorData`;
+
 export const getDevicePage = `/relics/camera/page`;
 export const delDevice = `/relics/camera/del/:deviceId`;
 export const addDevice = `/relics/camera/add`;

+ 32 - 35
src/util/pc4xlsl.ts

@@ -1,6 +1,9 @@
 import * as XLSX from "xlsx";
 import { round, toDegrees } from "./";
 import { saveAs } from "./file-serve";
+import { sendFetch } from "@/request";
+import * as URL from "@/request/URL";
+import { basePath, gHeaders } from "@/request/state";
 
 const genXLSLByTemp = (data: ArrayBuffer, tabs: any[][], name: string) => {
   const workbook = XLSX.read(data, {
@@ -22,28 +25,9 @@ const genXLSLByTemp = (data: ArrayBuffer, tabs: any[][], name: string) => {
   const sheetName = workbook.SheetNames[0];
   const worksheet = workbook.Sheets[sheetName];
 
-  console.log(worksheet);
   XLSX.utils.sheet_add_aoa(worksheet, tabs, { origin: "A2" });
   const wbout = XLSX.writeFile(workbook, `${name}.xlsx`);
-  // const wbout = URL.createObjectURL(new Blob([data]));
-  // const wbout = XLSX.write(workbook, {
-  //   // 要生成的文件类型
-  //   bookType: "xlsx",
-  //   type: "binary",
-  // });
-  // 将字符串转ArrayBuffer
-
-  // console.log(wbout);
-  // function s2ab(s: string) {
-  //   const buf = new ArrayBuffer(s.length);
-  //   const view = new Uint8Array(buf);
-  //   for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff;
-  //   return buf;
-  // }
-  // const blob = new Blob([s2ab(wbout)], {
-  //   type: "application/octet-stream",
-  // });
-  return saveAs(wbout, `${name}.xls`);
+  return saveAs(wbout, `${name}.xlsx`);
 };
 
 export const downloadPointsXLSL1 = async (
@@ -51,15 +35,23 @@ export const downloadPointsXLSL1 = async (
   desc: { title: string; desc: string }[] = [],
   name: string
 ) => {
-  const temp = await fetch("/templaten.xls").then((r) => r.arrayBuffer());
   const tabs = points.map((point, i) => {
     const des = desc[i] || { title: "无", desc: "无" };
-    return [i, des.title, toDegrees(point[1], 4), toDegrees(point[0], 4)].map(
-      (i) => i.toString()
-    );
+    return {
+      fid: i.toString(),
+      name: des.title,
+      latitude: toDegrees(point[1], 4),
+      longitude: toDegrees(point[0], 4),
+    };
   });
 
-  await genXLSLByTemp(temp, tabs, name);
+  const data = await fetch(basePath + URL.exportVectorData, {
+    headers: gHeaders,
+    method: "post",
+    body: JSON.stringify(tabs),
+  }).then((res) => res.blob());
+
+  return saveAs(data, `${name}.xlsx`);
 };
 
 export const downloadPointsXLSL2 = async (
@@ -67,19 +59,24 @@ export const downloadPointsXLSL2 = async (
   desc: { title: string; desc: string }[] = [],
   name: string
 ) => {
-  const temp = await fetch("/本体边界坐标.xls").then((r) => r.arrayBuffer());
   const tabs = points.map((point, i) => {
     const des = desc[i] || { title: "无", desc: "无" };
-    return [
-      { v: toDegrees(point[1], 4), t: "s", z: "@" },
-      { v: toDegrees(point[0], 4), t: "s", z: "@" },
-      { v: round(point[2], 4), t: "s", z: "@" },
-      des.title,
-      des.desc,
-    ];
+    return {
+      latitude: toDegrees(point[1], 4),
+      longitude: toDegrees(point[0], 4),
+      altitude: round(point[2], 4),
+      description: des.title,
+      remark: des.desc,
+    };
   });
-  console.log("data", tabs);
-  await genXLSLByTemp(temp, tabs, name);
+
+  const data = await fetch(basePath + URL.exportCoordinateData, {
+    headers: gHeaders,
+    method: "post",
+    body: JSON.stringify(tabs),
+  }).then((res) => res.blob());
+
+  return saveAs(data, `${name}.xlsx`);
 };
 
 export const downloadPointsXLSL = async (

+ 1 - 0
src/view/map/hot.ts

@@ -51,6 +51,7 @@ export const dynamicHots = (map: Map) => {
   const container = map.getTargetElement();
   const getMouseFeature = (ev: MouseEvent) => {
     const pixel = getRealativeMosePosition(container, [ev.offsetX, ev.offsetY]);
+    console.log(pixel);
     return map.forEachFeatureAtPixel(pixel, (feature) => {
       return hotSource.getFeatures().find((f) => f === feature);
     });