瀏覽代碼

Merge branch 'dev' of http://192.168.0.115:3000/bill/traffic-laser into dev

xzw 1 年之前
父節點
當前提交
a942bc5ef7
共有 4 個文件被更改,包括 54 次插入8 次删除
  1. 5 1
      src/main.ts
  2. 33 4
      src/openSDK.ts
  3. 9 3
      src/views/scene/photo.vue
  4. 7 0
      src/views/scene/scene.vue

+ 5 - 1
src/main.ts

@@ -1,5 +1,9 @@
 import VConsole from "vconsole";
-import params, { useParams } from "@/hook/useParams";
+import { useParams } from "@/hook/useParams";
+
+if (import.meta.env.VITE_APP_SDK === "true") {
+  import("./openSDK");
+}
 
 if (useParams().console === "true") {
   new VConsole();

+ 33 - 4
src/openSDK.ts

@@ -1,7 +1,36 @@
-import { ref } from "vue";
+import { nextTick, reactive, ref, watchEffect } from "vue";
+import { FixPoint, fixPoints } from "./store/fixPoint";
+import { baseLines } from "./store/baseLine";
+import { MeasureAtom, MeasuresRaw, Pos, Pos3D } from "./sdk";
+import { list } from "./store/measure";
+import { PhotoRaw } from "./store/photos";
+import { useSDK } from "./hook";
+
+type SDKAPI = {
+  getFixPoints: () => FixPoint[];
+  getBaseLine: () => MeasureAtom;
+  getMeasures: () => MeasuresRaw;
+  photo: (callback: (data: PhotoRaw) => void) => void;
+  getScreenPosition: (pos3d: Pos3D) => null | Pos;
+};
 
 export const loaded = ref(false);
-export const sdkAPI: any = {
-  // getFixPoints
+export const sdkAPI = reactive({
+  getFixPoints: () => JSON.parse(JSON.stringify(fixPoints.value)),
+  getBaseLine: () => JSON.parse(JSON.stringify(baseLines.value[0])),
+  getMeasures: () => JSON.parse(JSON.stringify(list.value)),
+  getScreenPosition: (pos3d: Pos3D) => {
+    const sdk = useSDK();
+    const data = sdk.scene.getScreenByPoint(pos3d);
+    return data.trueSide ? JSON.parse(JSON.stringify(data.pos)) : null;
+  },
+}) as SDKAPI;
+
+(window as any).getSDK = (callback: (sdk: SDKAPI) => {}) => {
+  const stopWatch = watchEffect(() => {
+    if (loaded.value && sdkAPI.photo) {
+      callback({ ...sdkAPI });
+      nextTick(() => stopWatch());
+    }
+  });
 };
-(window as any).getSDK = (callback: () => {}) => {};

+ 9 - 3
src/views/scene/photo.vue

@@ -28,7 +28,7 @@ import { list } from "@/store/measure";
 import { FixType, GFixPoint, fixPoints } from "@/store/fixPoint";
 import { baseLines } from "@/store/baseLine";
 import { basePoints } from "@/store/basePoint";
-import { photos } from "@/store/photos";
+import { PhotoRaw, photos } from "@/store/photos";
 import { useSDK } from "@/hook/useLaser";
 
 import { disabledMap } from "@/hook/custom";
@@ -125,7 +125,7 @@ const photo = async () => {
   tempPhoto.value = await api.getFile(data.rawUrl);
   console.log("获取到临时文件");
   await nextTick();
-  return new Promise((resolve, reject) => {
+  return new Promise<PhotoRaw>((resolve, reject) => {
     const handler = async () => {
       if (!isSDK) {
         coverRef.value.removeEventListener("animationend", handler);
@@ -185,7 +185,13 @@ const photo = async () => {
 };
 
 if (import.meta.env.VITE_APP_SDK === "true") {
-  (window as any).photo = photo;
+  import("@/openSDK").then((data) => {
+    watchEffect(() => {
+      data.sdkAPI.photo = async (callback) => {
+        callback(JSON.parse(JSON.stringify(await photo())));
+      };
+    });
+  });
 }
 </script>
 

+ 7 - 0
src/views/scene/scene.vue

@@ -47,4 +47,11 @@ const stopReg = watchEffect(() => {
     disabledMap.measure = false;
   }
 });
+if (import.meta.env.VITE_APP_SDK === "true") {
+  import("@/openSDK").then((data) => {
+    watchEffect(() => {
+      data.loaded.value = loaded.value;
+    });
+  });
+}
 </script>