import { computed, 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"; const global = window as any; type SDKAPI = { getFixPoints: () => FixPoint[]; getBaseLine: () => MeasureAtom; getMeasures: () => MeasuresRaw; photo: (callback: (data: PhotoRaw) => void) => void; getScreenPosition: (pos3d: Pos3D) => null | Pos; }; const mustAPI: (keyof SDKAPI)[] = ["photo"] as const; export const loaded = ref(false); 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; const sdkLoaded = computed( () => loaded.value && mustAPI.every((api) => api in sdkAPI) ); global.photo = () => { sdkAPI.photo((data) => { console.log("告诉anzhuo", JSON.stringify(data, null, 2)); global.android.photoCallback(JSON.stringify(data, null, 2)); }); }; global.getSDK = (callback: (sdk: SDKAPI) => {}) => { const stopWatch = watchEffect(() => { if (sdkLoaded.value) { callback({ ...sdkAPI }); nextTick(() => stopWatch()); } }); };