|
@@ -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 (
|